How to use node-set function in a platform-independent way? How to use node-set function in a platform-independent way? xml xml

How to use node-set function in a platform-independent way?


You can use the function function-available() to determine which function you should use:

<xsl:choose>  <xsl:when test="function-available('exslt:node-set')">    <xsl:apply-templates select="exslt:node-set($nodelist)" />  </xsl:when>  <xsl:when test="function-available('msxsl:node-set')">    <xsl:apply-templates select="msxsl:node-set($nodelist)" />  </xsl:when>  <!-- etc --></xsl:choose>

You can even wrap this logic in a named template and call it with the nodeset as a parameter.


Yes, there is a good and universal solution.

EXSLT's function common:node-set() can be implemented as an inline Javascript function and is thus available with any browser that supports Javascript (practically all major browsers without exception).

This technique was first discovered by Julian Reschke and after he published it on the xsl-list, was publicized by David Carlisle. On the blog of David Carlisle there is also a link to a test page that shows if the common:node-set() function thus implemented works with the browser of your choice.

To summarize:

  1. First go here and read the explanation.
  2. Then try the test page. In particular, verify that it works with IE (that means with MSXML)
  3. Finally, use the code.

Do enjoy!


Exslt is "supposed to be" a platform-independent set of xslt extensions, but only so far as various xslt processors choose to implement them.

There's some evidence that MSXML actually does support exsl:node-set(), but I don't know for sure.

There is an old article discussing an implementation of exslt on top of MSXML.

Otherwise, I think function-available() is your friend :)