[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Suggestions for filtering algorithm

Subject: Re: Suggestions for filtering algorithm
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 18 Dec 2019 16:11:23 -0000
Re:  Suggestions for filtering algorithm
Am 18.12.2019 um 04:08 schrieb Rick Quatro rick@xxxxxxxxxxxxxx:
>
> 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>
>

If you add an empty template

   <xsl:template match="part[some $exclude in $exclude/exclude/exclude
satisifes matches(@desc, $exclude) ]"/>

then any matched "part"s will not be processed, for the rest you can set
up the identity transformation. Or you can of course use any such
predicate in an apply-templates e.g.

   <xsl:apply-templates select="part[not(some $exclude in
$exclude/exclude/exclude satisifes matches(@desc, $exclude))]"/>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.