Project

Profile

Help

Bug #2830

closed

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 8 years ago. Updated almost 7 years ago.

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

100%

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

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.

Please register to edit this issue

Also available in: Atom PDF