How to write an XSL 1.0 style sheet with a node-set () function that will work on both MSXML and libxml

I have an XSLT 1.0 stylesheet using the XSL processor included in PHP (libxml). I want to get the same stylesheet that will work on the Microsoft XSL processor MSXML 6.0 (msxml6.dll), ideally so that the same stylesheet can work on any of the processors.

Unfortunately, at the moment I need to have two stylesheets - one for each processor.

This snippet calls the node-set () function on a PHP processor;

<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exsl="http://exslt.org/common"
  extension-element-prefixes="exsl">
    <xsl:template match="root">
        <xsl:variable name="rtf">
            <a>hello</a><b>world</b>
        </xsl:variable>
        <xsl:variable name="ns" select="exsl:node-set($rtf)"/>
        <xsl:copy-of select="$ns/b"/>
    </xsl:template>
</xsl:transform>

This snippet calls the node-set () function on a Microsoft processor;

<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  extension-element-prefixes="msxsl">
    <xsl:template match="root">
        <xsl:variable name="rtf">
            <a>hello</a><b>world</b>
        </xsl:variable>
        <xsl:variable name="ns" select="msxsl:node-set($rtf)"/>
        <xsl:copy-of select="$ns/b"/>
    </xsl:template>
</xsl:transform>

If the input was:

<root/>

The result of both stylesheets will be:

<b>world</b>

I want one stylesheet that can work unchanged on the PHP processor and Microsoft processor.

400 , node -set() , , .

+3
1

libxml msxsl, .

.

<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exsl="http://exslt.org/common"
  xmlns:func="http://exslt.org/functions"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  extension-element-prefixes="exsl func msxsl"
  >

    <func:function name="msxsl:node-set">
      <xsl:param name="node"/>
      <func:result select="exsl:node-set($node)"/>
    </func:function>

    <xsl:template match="root">
        <xsl:variable name="rtf">
            <a>hello</a><b>world</b>
        </xsl:variable>
        <xsl:variable name="ns" select="msxsl:node-set($rtf)"/>
        <xsl:copy-of select="$ns/b"/>
    </xsl:template>
</xsl:transform>
+1

All Articles