Project

Profile

Help

Bug #2830

position() inside of xsl:for-each-group select="copy-of(root/items/item)" group-adjacent="foo" in streamed mode is wrong

Added by Martin Honnen almost 3 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Streaming
Sprint/Milestone:
-
Start date:
2016-07-10
Due date:
% Done:

100%

Legacy ID:
Applies to branch:
9.7, trunk
Fix Committed on Branch:
9.7, trunk
Fixed in Maintenance Release:

Description

I have run into a problem with Saxon Saxon-EE 9.7.0.6J using the position() function inside of a <xsl:for-each-group select="copy-of(root/items/item)" group-adjacent="foo"> with a streamable mode, it does not output consecutive numbers 1, 2, 3, 4, ... as it does with a non-streamable mode but rather the position of the first item of the group in the original group population (e.g. @1, 3, 4, 6, 7@).

The reduced XSLT is

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs math"
    version="3.0">

    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:mode streamable="yes"/>

    <xsl:template match="/">
        <root>
            <xsl:for-each-group select="copy-of(root/items/item)" group-adjacent="foo">
                <group key="{current-grouping-key()}" group-nr="{position()}">
                    <xsl:copy-of select="current-group()"/>
                </group>
            </xsl:for-each-group>
        </root>
    </xsl:template>

</xsl:stylesheet>

And input sample is

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <items>
        <item id="i1">
            <foo>a</foo>
        </item>
        <item id="i2">
            <foo>a</foo>
        </item>
        <item id="i3">
            <foo>b</foo>
        </item>
        <item id="i4">
            <foo>c</foo>
        </item>
        <item id="i5">
            <foo>c</foo>
        </item>
        <item id="i6">
            <foo>d</foo>
        </item>
        <item id="i7">
            <foo>e</foo>
        </item>
    </items>
</root>

the result I get when running Saxon 9.7 EE from the command line is:

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <group key="a" group-nr="1">
      <item id="i1">
         <foo>a</foo>
      </item>
      <item id="i2">
         <foo>a</foo>
      </item>
   </group>
   <group key="b" group-nr="3">
      <item id="i3">
         <foo>b</foo>
      </item>
   </group>
   <group key="c" group-nr="4">
      <item id="i4">
         <foo>c</foo>
      </item>
      <item id="i5">
         <foo>c</foo>
      </item>
   </group>
   <group key="d" group-nr="6">
      <item id="i6">
         <foo>d</foo>
      </item>
   </group>
   <group key="e" group-nr="7">
      <item id="i7">
         <foo>e</foo>
      </item>
   </group>

so the group-nr values are wrong. Additionally the closing </root> tag is missing. When I change the mode to @streamable="no"@, I get the wanted, correct result:

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <group key="a" group-nr="1">
      <item id="i1">
         <foo>a</foo>
      </item>
      <item id="i2">
         <foo>a</foo>
      </item>
   </group>
   <group key="b" group-nr="2">
      <item id="i3">
         <foo>b</foo>
      </item>
   </group>
   <group key="c" group-nr="3">
      <item id="i4">
         <foo>c</foo>
      </item>
      <item id="i5">
         <foo>c</foo>
      </item>
   </group>
   <group key="d" group-nr="4">
      <item id="i6">
         <foo>d</foo>
      </item>
   </group>
   <group key="e" group-nr="5">
      <item id="i7">
         <foo>e</foo>
      </item>
   </group>
</root>

Exselt also gives the the right position() numbers for the streamable mode version so the problem appears to be a bug in Saxon.

History

#1 Updated by Michael Kay almost 3 years ago

  • Status changed from New to In Progress
  • Assignee set to Michael Kay
  • Priority changed from Low to Normal

Created test case si-group-034.

#2 Updated by Michael Kay almost 3 years ago

  • Status changed from In Progress to Resolved
  • Applies to branch 9.8 added
  • Fix Committed on Branch 9.7, 9.8 added

Patched in ForEachGroupAdjunct.GroupedGroundedFeed on the 9.7 and 9.8 branches.

The problem is specific to a streaming xsl:for-each-group where the select expression is consuming and grounded.

#3 Updated by O'Neil Delpratt almost 3 years ago

  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 9.7.0.7 added

Bug fix applied in the Saxon 9.7.0.7 maintenance release.

#4 Updated by O'Neil Delpratt almost 3 years ago

  • Status changed from Resolved to Closed

#5 Updated by O'Neil Delpratt about 2 years ago

  • Applies to branch trunk added
  • Applies to branch deleted (9.8)

#6 Updated by O'Neil Delpratt about 2 years ago

  • Fix Committed on Branch trunk added
  • Fix Committed on Branch deleted (9.8)

Please register to edit this issue

Also available in: Atom PDF