Project

Profile

Help

Bug #3932

closed

accumulator-before not working correctly with streaming and xsl:result-document in Saxon 9.9. EE

Added by Martin Honnen about 6 years ago. Updated about 6 years ago.

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

100%

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

Description

When trying to use streaming and xsl:result-document with an accumulator to capture the attribute value of a preceding sibling element I get wrong results for the accumulator value returned by accumulator-before() where that call is used inside of an xsl:result-document. This happens with Saxon 9.9.0.1 EE, it seems Saxon 9.8 EE gets it right.

Example 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" exclude-result-prefixes="#all" expand-text="yes"
	version="3.0">
	
	<xsl:param name="STREAMABLE" static="yes" as="xs:boolean" select="true()"/>
	
	<xsl:mode _streamable="{$STREAMABLE}" use-accumulators="#all"/>
	
	<xsl:accumulator name="last-id" as="xs:string?" initial-value="()" _streamable="{$STREAMABLE}">
		<xsl:accumulator-rule match="item" phase="end" select="string(@id)"/>
	</xsl:accumulator>
	
	<xsl:output method="html" indent="yes" version="5.0"/>
	
	<xsl:template match="/">
		<html>
			<head>
				<title>Testing accumulator with streaming and result-document threading</title>
			</head>
			<body>
				<h1>Testing accumulator with streaming and result-document threading</h1>
				<section>
					<h2>Results</h2>
					<xsl:apply-templates/>
				</section>
			</body>
		</html>
	</xsl:template>
	
	<xsl:template match="items">
		<xsl:result-document href="item-result.html">
			<html>
				<head>
					<title>Items</title>
				</head>
				<body>
					<ul>
						<xsl:apply-templates select="item"/>
					</ul>
				</body>
			</html>
		</xsl:result-document>
	</xsl:template>
	
	<xsl:template match="item">
		<li>Item {@id}, position: {position()}, attribute pos: {@pos},
			accumulator-before('last-id'): {accumulator-before('last-id')}</li>
		
		<xsl:result-document href="item_{@id}.txt" method="text">Item {@id}, accumulator-before('last-id'): {accumulator-before('last-id')}</xsl:result-document>
	</xsl:template>
	
</xsl:stylesheet>

Sample XML is

<?xml version="1.0" encoding="UTF-8"?>
<items>
   <item id="i1" pos="1">
      <data>data 1</data>
   </item>
   <item id="i2" pos="2">
      <data>data 2</data>
   </item>
   <item id="i3" pos="3">
      <data>data 3</data>
   </item>
   <item id="i4" pos="4">
      <data>data 4</data>
   </item>
   <item id="i5" pos="5">
      <data>data 5</data>
   </item>
</items>

Now the item-results.html has the right accumulator values with

     <ul>
        <li>Item i1, position: 1, attribute pos: 1,
                               accumulator-before('last-id'): </li>
        <li>Item i2, position: 2, attribute pos: 2,
                               accumulator-before('last-id'): i1</li>
        <li>Item i3, position: 3, attribute pos: 3,
                               accumulator-before('last-id'): i2</li>
        <li>Item i4, position: 4, attribute pos: 4,
                               accumulator-before('last-id'): i3</li>
        <li>Item i5, position: 5, attribute pos: 5,
                               accumulator-before('last-id'): i4</li>
     </ul>

However those test files created with xsl:result-document href="item_{@id}.txt" method="text" look like this (for instance when outputting them with type item_i*.txt in a PowerShell console):

Item i1, accumulator-before('last-id'):
Item i2, accumulator-before('last-id'): i2
Item i3, accumulator-before('last-id'): i3
Item i4, accumulator-before('last-id'): i4
Item i5, accumulator-before('last-id'): i5

while with Saxon 9.8 EE I get the intented result:

Item i1, accumulator-before('last-id'):
Item i2, accumulator-before('last-id'): i1
Item i3, accumulator-before('last-id'): i2
Item i4, accumulator-before('last-id'): i3
Item i5, accumulator-before('last-id'): i4

Using --allow-multithreading:off for 9.9 also gives the intented results.


Files

input5.xml (370 Bytes) input5.xml Martin Honnen, 2018-10-02 07:41
acc-test-result-doc-text3.xsl (1.56 KB) acc-test-result-doc-text3.xsl Martin Honnen, 2018-10-02 07:41

Please register to edit this issue

Also available in: Atom PDF