Description
Testcase XSL
---------------------------------------------------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="x" select="/doc/ch"/>
<xsl:template match="/">
<xsl:text>
</xsl:text>
<out>
<xsl:text>
</xsl:text>
<presort-foreach>
<xsl:for-each select="$x">
<xsl:copy-of select="."/>
</xsl:for-each>
</presort-foreach>
<xsl:text>
</xsl:text>
<sort-foreach>
<xsl:for-each select="$x">
<xsl:sort data-type="number" order="ascending"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</sort-foreach>
<xsl:text>
</xsl:text>
<postsort-foreach>
<xsl:for-each select="$x">
<xsl:copy-of select="."/>
</xsl:for-each>
</postsort-foreach>
<xsl:text>
</xsl:text>
</out>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------------------
Testcase XML:
---------------------------------------------------------
<doc><ch>1</ch><ch>4</ch><ch>3</ch><ch>2</ch></doc>
---------------------------------------------------------
The presort comes out in order 1 4 3 2.
The sort comes out in order 1 2 3 4
... but then the postsort comes out in order 1 2 3 4, but should be in the order 1 4 3 2, so the sort on $x has mutated
the variable $x, and this is WRONG.
Thanks to Henry Zongaro for thinking up this bug while reviewing my fix for XALANJ-2204.
<implementation-details>
It looks like the cache, a NodeVector, held by a NodeSequence is being shared and updated by the iterators.
The fix might be to create your own copy of the cache when an attempt is made to mutate it after it is complete.
</implementation-details>
Attachments
Issue Links
- is related to
-
XALANJ-2204 Function Count on variable modifies number of nodes in variable.
- Closed