Would an accumulator prevent early exit with xsl:iterate/break?
Added by Martin Honnen about 2 years ago
While trying to use accumulators with xsl:iterate
/xsl:break
, expecting to benefit from partial input file reading/early exit Saxon EE supports, I surprisingly found that as soon as I introduce an accumulator Saxon no longer emits the SXQP0001 The input file has not been read to completion
and seems to read a file to completion.
So the example from the test suite has the input https://github.com/qt4cg/xslt40-test/blob/master/tests/strm/si-iterate/si-iterate-094.xml and the XSLT https://github.com/qt4cg/xslt40-test/blob/master/tests/strm/si-iterate/si-iterate-094.xsl and on running this with EE and streaming emits the above cited info message but when I use a similar test case using an accumulator e.g.
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:accumulator name="chapter-p-count" streamable="yes" initial-value="0" as="xs:integer">
<xsl:accumulator-rule match="doc/chapter/p" select="$value + 1"/>
</xsl:accumulator>
<xsl:mode streamable="yes" use-accumulators="#all"/>
<xsl:template match="/">
<out>
<xsl:iterate select="doc/chapter/p">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="node()"/>
</xsl:copy>
<xsl:if test="accumulator-before('chapter-p-count') ge 2">
<xsl:break/>
</xsl:if>
</xsl:iterate>
</out>
</xsl:template>
</xsl:stylesheet>
I find that I don't get the info message any longer, suggesting that the declaration of the accumulator lets Saxon no longer implement the early exit.
And for instance example input that contained malformed markup long after the xsl:break
point and are processed due to the early exit/parsing abandoning without problems with the original sample are failing with a parse error if the accumulator is present.
Is that a known/expected interference of the the use of accumulators with the xsl:iterate/xsl:break
early exit strategy? Is there some way to use accumulators but nevertheless benefit from xsl:iterate/xsl:break
early exit?
Replies (2)
RE: Would an accumulator prevent early exit with xsl:iterate/break? - Added by Michael Kay about 2 years ago
Yes, it's a known issue - explored in https://saxonica.plan.io/issues/5484
I made changes in that investigation to ensure that if the accumulator was accessed, it gave the correct result, which in some cases prevented early exit. What I didn't do was to try and identify whether there were case where we could safely quit parsing despite the presence of the accumulator.
RE: Would an accumulator prevent early exit with xsl:iterate/break? - Added by Martin Honnen about 2 years ago
Ah, I see.
Interestingly enough my attempts to count some nodes with accumulators and streaming but use xsl:iterate/xsl:break
for "early exit" before some malformed tail of the input documents do what I wanted them to do with 11.3, the failure is with 11.4 which I understand has that fix to ensure accumulators are run with priority over an early exit.
Maybe some additional setting/extension attribute to be able to let the XSLT author decide whether early exit or processing to the end for all accumulators has priority could help. But I can't assess the general impact this might have, in particular not on the implementation side.
Please register to reply