Re: [xsl] Filtering, xslt 2.0

Subject: Re: [xsl] Filtering, xslt 2.0
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 1 Nov 2022 08:50:24 -0000
Am 11/1/2022 um 9:44 AM schrieb Dave Pawson dave.pawson@xxxxxxxxx:
I suspect it is a shell issue (Using Bash on Linux)
Test case
<?xml version="1.0" encoding="utf-8"?>
<set>

   <data>
     <name>A</name>
     <type>dog</type>
   </data>
   <data>
     <name>B</name>
     <type>cat</type>
   </data>
   <data>
     <name>C</name>
     <type>mouse</type>
   </data>
</set>

<?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"/>

If you declare the type as a single string item, then it doesn't make sense to attempt to use the "?param-name" syntax further below to pass in an XPath expression evaluating to a sequence of strings.


So either


B as="xs:string*"

and then

B ?types="('A','B')"

or

B as="xs:string"

and

B types=A,B

and

B test="type = tokenize($types, ',')"


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


<xsl:template match="set">

<xsl:message>
    <xsl:value-of select='$types'/>
  </xsl:message>


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


<xsl:template match="data"> <xsl:if test="type = $types"> <xsl:apply-templates mode="pass"/> </xsl:if> <xsl:if test="contains(concat(',', $types, ','), concat(',', type,
','))">
       <xsl:message>
    <xsl:value-of select="'Dimitre'"/>
       </xsl:message>
     </xsl:if>
   </xsl:template>


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


   <xsl:template match="name|type" mode="pass">
     <xsl:apply-templates/>
   </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>

1. sax2 seq.xml seq.xsl op.xml ?types='("A", "B")'
Errors with Unrecognized option: "B")

2. sax2 seq.xml seq.xsl op.xml ?types="('A','B')"
XPTY0004: A sequence of more than one item is not allowed as the value
of variable $types
   ("A", "B")

Saxon version PE 9.6.0.1


Suggestions to get the data into the stylesheet please? An external xml
file?


TiA

regards

Current Thread