Actions
Bug #3122
closedlast() not computed correctly when processing sequence constructed from variable
Start date:
2017-02-02
Due date:
% Done:
100%
Estimated time:
Legacy ID:
Applies to branch:
9.7
Fix Committed on Branch:
9.7
Fixed in Maintenance Release:
Platforms:
Description
I have run into a problem with Saxon 9.7 (occurs with both Saxon-EE 9.7.0.14J and Saxon-HE 9.7.0.14J) where the value of last()
when processing a sequence constructed in a variable as element()*
with <xsl:apply-templates select="$var"/>
is wrong. Here is a diagnostic test case:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:variable name="duplicates" as="element()*">
<xsl:for-each-group select="/root/items/item" group-by="@key">
<xsl:sequence select="current-group()[current-group()[2]]"/>
</xsl:for-each-group>
</xsl:variable>
<xsl:apply-templates select="$duplicates"/>
</xsl:template>
<xsl:template match="item">
<xsl:message select="'position(): ', position(), '; last(): ', last()"/>
{
"value" : "<xsl:value-of select="@value"/>"
}<xsl:if test="position() < last()">,</xsl:if>
</xsl:template>
</xsl:stylesheet>
When I run that against the input
<?xml version="1.0" encoding="UTF-8"?>
<root>
<items>
<item key="a" value="a1"/>
<item key="b" value="b1"/>
<item key="a" value="a2"/>
<item key="c" value="c1"/>
<item key="a" value="a3"/>
<item key="c" value="c2"/>
</items>
</root>
the output is
position(): 1 ; last(): 9
position(): 2 ; last(): 9
position(): 3 ; last(): 9
position(): 4 ; last(): 9
position(): 5 ; last(): 9
{
"value" : "a1"
},
{
"value" : "a2"
},
{
"value" : "a3"
},
{
"value" : "c1"
},
{
"value" : "c2"
},
So although only (and correctly) 5 item
elements are processed, last()
is computed as 9@. And that way the @5th item
in the output has a unwanted comma appended.
The problem does not occur with Saxon 9.6 (tested with Saxon-EE 9.6.0.9J).
Please register to edit this issue
Actions