exslt:node-set differs between Xalan-J and XSLTC

Julian Reschke <[email protected]> Mon, 18 Oct 2010 16:58:56 +0200
Newsgroups gmane.text.xml.xalan.java.user
Message-ID <[email protected]>
Hi,

I see some strange behavior with Xalan-J (as opposed to other engines, 
such as XSLTC or Saxon). It happens when an RTF is passed as a template 
parameter, and is converted to a node-set (using exslt:node-set).

-- test case --
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:exslt="http://exslt.org/common"
 >

<xsl:output method="text"/>

<xsl:template match="/">

   <xsl:variable name="t">
     <root>
       <x>1</x>
       <x>2</x>
       <x>3</x>
     </root>
   </xsl:variable>

   <xsl:variable name="tns" select="exslt:node-set($t)/root/x"/>

   <xsl:message>Type of t: <xsl:value-of 
select="exslt:object-type($t)"/></xsl:message>
   <xsl:message>Type of tns: <xsl:value-of 
select="exslt:object-type($tns)"/></xsl:message>
   <xsl:message>Name of tns: <xsl:value-of 
select="local-name($tns)"/></xsl:message>
   <xsl:message>Nodes in tns: <xsl:value-of 
select="count($tns)"/></xsl:message>
   <xsl:message>$tns[2]: <xsl:value-of select="$tns[2]"/></xsl:message>

   <xsl:call-template name="foo">
     <xsl:with-param name="t" select="$tns"/>
     <xsl:with-param name="i" select="'1'"/>
   </xsl:call-template>

</xsl:template>

<xsl:template name="foo">
   <xsl:param name="t"/>
   <xsl:param name="i"/>
   <xsl:variable name="tns" select="exslt:node-set($t)"/>

   <xsl:message>In template - i: <xsl:value-of select="$i"/></xsl:message>
   <xsl:message>In template - Type of t: <xsl:value-of 
select="exslt:object-type($t)"/></xsl:message>
   <xsl:message>In template - Type of tns: <xsl:value-of 
select="exslt:object-type($tns)"/></xsl:message>
   <xsl:message>In template - Name of tns: <xsl:value-of 
select="local-name($tns)"/></xsl:message>
   <xsl:message>In template - Nodes in tns: <xsl:value-of 
select="count($tns)"/></xsl:message>
   <xsl:message>In template - $tns[2]: <xsl:value-of 
select="$tns[2]"/></xsl:message>

   <xsl:if test="$i &lt; count($tns)">
     <xsl:call-template name="foo">
       <xsl:with-param name="t" select="$tns"/>
       <xsl:with-param name="i" select="$i + 1"/>
     </xsl:call-template>
   </xsl:if>

</xsl:template>

</xsl:stylesheet>
-- test case --

The expected result is that the template "foo" is called three times 
(the number of "x" elements in "root"); once from the root template, 
twice recursively.

With Xalan-J (2.7.0), this happens only two times; in the first recursion,

   count($tns)

evaluates to 1 instead of 3.

Any ideas? Known issue?

Best regards, Julian