Bug #6472
closedSort order not recognised for xsl:for-each-group in named template (Saxon HE 12.xJ)
0%
Description
I have an issue setting the sort order for xsl:for-each-group via a xsl:param inside a named template. When I call the same template more than once it seems to remember the sort order from the first call.
The first call to the template sets the param to 'descending' and the output is in the expected order.
The second call to the template sets the param to 'ascending' and the output is in descending order.
This happens in 12.x (I tried 12.0, 12.4 and 12.5) but is fine in 11.6.
My stylesheet is:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="data">
<root>
<item name="bbb" />
<item name="ddd" />
<item name="bbb" />
<item name="aaa" />
<item name="ccc" />
</root>
</xsl:variable>
<xsl:template name="xsl:initial-template">
<root>
<xsl:call-template name="fegTemplate">
<xsl:with-param name="ordering">descending</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="fegTemplate">
<xsl:with-param name="ordering">ascending</xsl:with-param>
</xsl:call-template>
</root>
</xsl:template>
<xsl:template name="fegTemplate">
<xsl:param name="ordering" select="string('ascending')" />
<h>for-each-group <xsl:value-of select="$ordering" /></h>
<xsl:for-each-group select="$data/root/item" group-by="@name">
<xsl:sort order="{$ordering}" select="current-grouping-key()" />
<t><xsl:value-of select="current-grouping-key()" /></t>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
The first call sets the 'ordering' param to 'descending' and the second call sets it to 'ascending'. With 12.xJ the output from the second call is in descending order:
<root>
<h>for-each-group descending</h>
<t>ddd</t>
<t>ccc</t>
<t>bbb</t>
<t>aaa</t>
<h>for-each-group ascending</h>
<t>ddd</t>
<t>ccc</t>
<t>bbb</t>
<t>aaa</t>
</root>
With 11.6 the output is as expected:
<root>
<h>for-each-group descending</h>
<t>ddd</t>
<t>ccc</t>
<t>bbb</t>
<t>aaa</t>
<h>for-each-group ascending</h>
<t>aaa</t>
<t>bbb</t>
<t>ccc</t>
<t>ddd</t>
</root>
Adrian
Files
Please register to edit this issue