Bug #3932
closedaccumulator-before not working correctly with streaming and xsl:result-document in Saxon 9.9. EE
100%
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
Please register to edit this issue