xsl-list
[Top] [All Lists]

[xsl] Suggestions for filtering algorithm

2019-12-17 21:08:11
Hi All,

 

I have an XML file with parts similar to this:

 

<?xml version="1.0" encoding="UTF-8"?>

<parts>

    <part no="123456" desc="HOSE KIT"/>

    <part no="234567" desc="HOSE FITTINGS"/>

    <part no="345678" desc="HOSE SEGMENT"/>

</parts>

 

When processing the parts with XSLT 2, I want to filter out some of the
parts based on words or phrases that the user supplies. I was thinking of a
lookup XML file that they could maintain:

 

<?xml version="1.0" encoding="UTF-8"?>

<exclude>

    <exclude>FITTINGS</exclude>

    <exclude>SEGMENT</exclude>

</exclude>

 

This is a roughed out stylesheet, but I am not sure the best way to use the
look up. I could convert the <exclude> elements to a regular expression and
apply it to the @desc attribute, but I am not sure if there is a better
approach that I am missing.

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

    xmlns:xs="http://www.w3.org/2001/XMLSchema";

    exclude-result-prefixes="xs"

    version="2.0">

    

    <xsl:variable name="exclude" select="doc('excludes.xml')"/>

    

    <xsl:template match="/parts">

        <xsl:apply-templates/>

    </xsl:template>

    

    <xsl:template match="part">

        <!-- Only process parts where the @desc doesn't contain an exclude
string. -->

        

    </xsl:template>

    

</xsl:stylesheet>

 

Thanks for any pointers.

 

Rick

 

Rick Quatro

Carmen Publishing Inc.

rick(_at_)frameexpert(_dot_)com

585-729-6746

www.frameexpert.com/store/

 

 
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>