#537 Corrupt values of sequence variables

Michael Kay

This problem was observed with XSLT but it could
probably happen with XQuery as well.

Under certain circumstances the values of variables
containing sequences of constructed parentless elements
can become corrupt. Specifically, one such sequence may
contain elements belonging to another such sequence.
the problem arises because Saxon attempts to reuse the
SequenceOutputter used to build the values of
successive variables, and sometimes the state of the
SequenceOutputter is not reset correctly.

The particular circumstances in which the problem
occurs are with a construct like the following:

<xsl:variable name="x" as="element()*">
<xsl:variable name="y" as="element()*">

(although the body of the outer variable could be
contained inside a called template). That is, the
system starts writing an inner sequence of parentless
elements before the first item in an outer sequence of
parentless elements has been written.

Source fix: in net.sf.saxon.instruct.ElementCreator,
method constructElement at line 210, change this code:

SequenceReceiver old = c2.getReceiver();
SequenceOutputter seq;
if (old instanceof SequenceWriter &&
!((SequenceWriter)old).hasOpenNodes()) {
// Reuse the current SequenceOutputter
if possible. This enables the construction of
// a single TinyTree to hold a sequence
of parentless elements (a forest).
seq = (SequenceOutputter)old;
} else {
seq =

to the single line:

SequenceOutputter seq =


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks