The answer is to another thread (see https://stackoverflow.com/a/1674747 ). I ran into a problem below where different xsl engines seem to need different approaches when converting fragments of the result tree to node-sets.
To simplify the problem (but see the link above for the full story), I want to have a built-in tree containing a list of color values. Since this should be used in Xpath expressions, I had to create a node-set from it specifically for the MSXML xx xsl engine (the built-in XML spy had less trouble interpreting Xpath expressions associated with variables built as rtf).
Another thread https://stackoverflow.com/a/236329/2123 helped me there. The resulting node -set is used to create a new rtf variable from the input XML.
Again, MSXML complains when a new variable is used in Xpath expressions, so I used the node-set function to create a node-set from it.
So far, so good, and MSXML xx no longer causes errors.
But when I run the same in Spy or Saxon 9he inline XML, I get another error: the node-set function seems to be unknown:
Cannot find a matching 1-argument function named {urn:schemas-microsoft-com:xslt}node-set() in variable colorList
Note that this two-step approach is not needed in this particular example, but as I said, I have simplified things; I just want to know how to write an XSLT 1.0 transform that will work on all xsl machines.
Used XSLT:
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:std="http://whatever" xmlns:exslt="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="std exslt"> <xsl:output method="xml" indent="yes"/> <std:colors> <color>#0000FF</color> <color>#FF0000</color> </std:colors> <xsl:variable name="colors" select="document('')/*/std:colors"/> <xsl:variable name="std:colorList"> <xsl:for-each select="//testid"> <xsl:variable name="pos" select="position() mod 2"/> <xsl:element name="color"> <xsl:attribute name="testid"><xsl:value-of select="."/></xsl:attribute> <xsl:value-of select="$colors/color[$pos + 1]"/> </xsl:element> </xsl:for-each> </xsl:variable> <xsl:variable name="colorList" select="exslt:node-set($std:colorList)"/> <xsl:template match="/"> <output> <xsl:copy-of select="$colorList/color"/> </output> </xsl:template> </xsl:stylesheet>
Input file:
<?xml version="1.0" standalone="yes"?> <NewDataSet> <defects> <testid>111</testid> </defects> <defects> <testid>999</testid> </defects> </NewDataSet>
Result in MSXML 3.0 / 4.0 / 6.0:
<?xml version="1.0" encoding="UTF-16"?> <output> <color testid="111">#FF0000</color> <color testid="999">#0000FF</color> </output>
Result in Saxon9he:
Cannot find a matching 1-argument function named {urn:schemas-microsoft-com:xslt}node-set() in variable colorList
leads to the built-in xsl engine in XML Spy:
Error in XPath expression Unknown function - Name and number of arguments do not match any function signature in the static context - 'urn:schemas-microsoft-com:xslt:node-set'
Maestro13
source share