Project

Profile

Help

Bug #4430

closed

Unpredictable output when streaming accumulators call other accumulators

Added by Martin Honnen over 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Streaming
Sprint/Milestone:
-
Start date:
2020-01-16
Due date:
% Done:

100%

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

Description

I have run into an odd problem, I have written an XSLT 3 stylesheet using accumulators and streaming that gives the wanted result when running with 9.9.1.6 EE Java from the command line as long as I don't use the -t option to display timing information (well, I rather use it to see whether the input is really processed with streaming).

The XSLT sample 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:mf="http://example.com/mf"
    exclude-result-prefixes="#all" version="3.0">

    <xsl:output method="text" item-separator="&#10;"/>

    <xsl:mode on-no-match="shallow-skip" use-accumulators="#all" streamable="yes"/>

    <xsl:accumulator name="A" as="xs:integer?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="fields/data/id1" phase="end"
            select="accumulator-after('values') => subsequence(1, 3) => sum()"/>
    </xsl:accumulator>

    <xsl:accumulator name="B" as="xs:integer?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="fields/data/id1" phase="end"
            select="accumulator-after('values') => subsequence(4, 3) => sum()"/>
    </xsl:accumulator>

    <xsl:accumulator name="C" as="xs:integer?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="fields/data/id2" phase="end"
            select="accumulator-after('values') => subsequence(1, 3) => sum()"/>
    </xsl:accumulator>

    <xsl:accumulator name="D" as="xs:integer?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="fields/data/id2" phase="end"
            select="accumulator-after('values') => subsequence(4, 3) => sum()"/>
    </xsl:accumulator>

    <xsl:accumulator name="values" as="xs:integer*" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="data" select="()"/>
        <xsl:accumulator-rule match="data/id1/text() | data/id2/text()"
            select="
                analyze-string(., '.')//*:match ! (
                if (. = '.')
                then
                    15
                else
                    if (. = ' ')
                    then
                        20
                    else
                        xs:integer(.))"
        />
    </xsl:accumulator>

    <xsl:accumulator name="remainder" as="xs:integer?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="fields/data" select="()"/>
        <xsl:accumulator-rule match="fields/data" phase="end"
            select="
                abs((accumulator-after('B') + accumulator-after('D')) -
                (accumulator-after('A') + accumulator-after('C'))) mod 13"
        />
    </xsl:accumulator>

    <xsl:accumulator name="remainder-sum" as="xs:integer?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="fields" select="0"/>
        <xsl:accumulator-rule match="fields/data" phase="end" select="$value + accumulator-after('remainder')"/>
    </xsl:accumulator>

    <xsl:output method="text" item-separator="&#10;"/>

    <xsl:template match="fields">
        <xsl:apply-templates/>
        <xsl:sequence select="accumulator-after('remainder-sum')"/>
    </xsl:template>

</xsl:stylesheet>

An input sample is

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <fields>
        <data>
            <id1>111   </id1>
            <id2>123.50</id2>
        </data>        
    </fields>
    <fields>
        <data>
            <id1>111   </id1>
            <id2>123.50</id2>
        </data>
        <data>
            <id1>321.50</id1>
            <id2>   222</id2>
        </data>
    </fields>
</root>

When I run it from the command line solely with options -xsl:sheet.xsl -s:input.xml then the result is fine:

6
7

or when I use the -o:result.txt I get that result in the named result file.

However, when using the -t option, I get the timing and streaming infos output to the console but the two numbers are not output to the console or, with the -o option, an empty file is created.

The code tries to solve https://stackoverflow.com/q/59756080/252228 with streaming.

Please register to edit this issue

Also available in: Atom PDF