Bug #2562
closedMissing end tag in result after using xsl:break
100%
Description
See https://saxonica.plan.io/boards/3/topics/6262
Saxon - Help: Getting incomplete result document when using xsl:break in xsl:iterate in xsl:copy with streaming mode
Martin Honnen
I am getting an incomplete result document with a missing closing end tag of the root element when using the following stylesheet with Saxon 9.7 EE:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:param name="elements-to-copy" as="xs:integer" select="5"/>
<xsl:mode streamable="yes"/>
<xsl:output indent="yes"/>
<xsl:template match="/*">
<xsl:iterate select="*">
<xsl:copy-of select="."/>
<xsl:if test="position() eq $elements-to-copy">
<xsl:break/>
</xsl:if>
</xsl:iterate>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The input document is
......
...
...
...
...
...
...
The output is lacking the closing end tag of the root element:
......
...
...
...
As the xsl:copy is outside of the xsl:iterate I would expect the root element to be closed properly.
Updated by Michael Kay almost 9 years ago
- Status changed from New to In Progress
Trying to reproduce this, I hit a secondary problem: running a transformation from the command line, if there is no global context item declaration, we build the source document as a tree regardless whether the initial mode is streamable. See Transform line 1193.
Updated by Michael Kay almost 9 years ago
The problem is that xsl:break, under the conditions of this test, causes parsing of the input file to be aborted because no more input is required; but the writing of end tags in the output file is only triggered by the processing of end tags in the input file.
Updated by Michael Kay almost 9 years ago
I have a solution that works for this test case, which involves WatchManager.endElement() catching the QuitParsingException and calling endElement() for all open elements on the stack, before re-throwing the exception. Need to do further testing to establish that this has no adverse side-effects. Also, we are catching the QuitParsingException where it occurs in this test case (during endElement processing) and it's not obvious that this will catch all cases where the same problem might occur.
Updated by Michael Kay almost 9 years ago
- Status changed from In Progress to Resolved
- Fix Committed on Branch 9.7 added
This fix is now tested. Raising a separate bug for the "secondary issue" that streaming doesn't work from the command line.
Updated by O'Neil Delpratt almost 9 years ago
- % Done changed from 0 to 100
- Fixed in Maintenance Release 9.7.0.2 added
Bug fix applied in the Saxon 9.7.0.2 maintenance release
Updated by O'Neil Delpratt almost 9 years ago
- Status changed from Resolved to Closed
Please register to edit this issue