Project

Profile

Help

Bug #6472

closed

Sort order not recognised for xsl:for-each-group in named template (Saxon HE 12.xJ)

Added by Adrian Bird 5 months ago. Updated 4 months ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
Internals
Sprint/Milestone:
-
Start date:
2024-07-07
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
11, 12, trunk
Fix Committed on Branch:
12, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

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

ForEachGroupSortOrderIssue.xslt (1.12 KB) ForEachGroupSortOrderIssue.xslt Adrian Bird, 2024-07-07 10:25

Please register to edit this issue

Also available in: Atom PDF