Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
2.7
-
None
Description
Here is the testcase, the input XML is this:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<author>
<firstname>Bugs</firstname>
<initial>B</initial>
<lastname>Gone</lastname>
</author>
</project>
The stylesheet is this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="author">
<xsl:for-each select='(child::*)[not(self::initial)]'>
Child element <xsl:value-of select="position()"/>
of <xsl:value-of select="last()"/>
Element name: <xsl:value-of select="name()"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The current, and incorrect output is this:
Child element 1
of 3
Element name: firstname
Child element 2
of 3
Element name: lastname
The selected elements are correct, but the last() function is returning 3 rather than 2.
If the for-each is changed to this:
<xsl:for-each select='(child::*)[not(self::junk)]'>
it iterates over the 3 children correctly (there is no child named 'junk' so the predicate does not reduce the sequence selected by (child::*), but in this case last() returns 4. In both cases one greater than it should.
With no predicate things work fine.
Attachments
Issue Links
- duplicates
-
XALANJ-2286 count function applied to union as test of node identity is broken
- Closed
- relates to
-
XALANJ-2204 Function Count on variable modifies number of nodes in variable.
- Closed