Re: [xsl] Filtering, xslt 2.0

Subject: Re: [xsl] Filtering, xslt 2.0
From: "Dave Pawson dave.pawson@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 2 Nov 2022 12:13:49 -0000
For the archive: My solution

Called from command line (Linux, bash)
>  sax2 seq.xml seq.xsl op.xml types=dog,cat


output
*** Match on A

*** Match on dog

*** Match on B

*** Match on cat
mouse No match found

(My) learning points
(Old MK cry)
<xsl:param name="types" as="xs:string*"/>
The appropriate type helps.
then (with simpler command line params) param=a,b,c
and processing with tokenize ($params, ',')
I can test for equality.

Thanks for your help folks.

regards


stylesheet
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:d="http://www.dpawson.co.uk/ns#";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
 version="2.0">

  <xsl:param name="types" as="xs:string*"/>

  <xsl:strip-space elements="*"/>

<xsl:output method="xml"/>

  <xsl:template match="set">

    <xsl:for-each select="data">
      <xsl:sort select="name"/>
      <xsl:apply-templates select="."/>
    </xsl:for-each>
  </xsl:template>


  <xsl:template match="data">
      <xsl:choose>
      <xsl:when test="type = tokenize($types, ',')">
<xsl:apply-templates mode="pass"/>
      </xsl:when>
      <xsl:otherwise>
<xsl:message>
   <xsl:value-of select='type'/> No match found
 </xsl:message>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>


 <xsl:template match="name|type" />

 <xsl:template match="name|type" mode="pass">
  <xsl:message>
*** Match on <xsl:value-of select="."/>
 </xsl:message>
    <xsl:copy>
<xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>


   <xsl:template match="*">
  <xsl:message>
    *****<xsl:value-of select="name(..)"/>/{<xsl:value-of
select="namespace-uri()"/>}<xsl:value-of select="name()"/>******
    </xsl:message>
</xsl:template>



</xsl:stylesheet>

On Tue, 1 Nov 2022 at 13:00, Dave Pawson dave.pawson@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, 1 Nov 2022 at 09:01, Martin Honnen martin.honnen@xxxxxx
> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> >
> > It sounds as if you tried
> >
> >   ?types=A,B
> >
> > where the XPath evaluation kicks in.
>
> Quite right Martin. Now working and I can apply to my problem.
>
> Many thanks all for your help!
>
> As 80 approaches this becomes a little harder.
>
> regards
>
>
> --
> Dave Pawson
> XSLT XSL-FO FAQ.
> Docbook FAQ.
> 
>


-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.

Current Thread