Description
Consider the following XML file:
---------------------------------------------------
<xmldata>
<value/>
<value/>
</xmldata>
---------------------------------------------------
Consider the following XSL file:
---------------------------------------------------
<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:variable name="doc" select="xmldata"/>
<xsl:template match="xmldata">
<html>
<head/>
<body>
Number of elements: <xsl:value-of select="count($doc/value)"/>
<br/>
Number of elements: <xsl:value-of select="count($doc/value)"/>
<br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------------
As you can see, the output should be an html page showing the total number of elements twice. However, this is the output:
---------------------------------------------------
Number of elements: 2
Number of elements: 4
---------------------------------------------------
Now consider the following XSL file:
---------------------------------------------------
<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="xmldata">
<xsl:variable name="doc" select="."/>
<html>
<head/>
<body>
Number of elements: <xsl:value-of select="count($doc/value)"/>
<br/>
Number of elements: <xsl:value-of select="count($doc/value)"/>
<br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------------
Now the output is correct:
---------------------------------------------------
Number of elements: 2
Number of elements: 2
---------------------------------------------------
Comparing the two XSL files, the only diference is that the "doc" variable is declared outside or inside the template.
Thank you!
Attachments
Issue Links
- duplicates
-
XALANJ-2204 Function Count on variable modifies number of nodes in variable.
- Closed
- relates to
-
XALANJ-2204 Function Count on variable modifies number of nodes in variable.
- Closed