When the sequence constructor generating the children
of a new document node itself contains a document node,
and there are elements following that document node,
then the tree that is constructed is malformed, and the
elements appear not to be there (they are not selected
when following the child axis from the containing
document node). For example, with
the variable $x will appear to contain a copy of the
document abc.xml, but no xyz element.
The problem could also appear in XQuery, though it's
less likely. This bug first appeared in Saxon 8.5.
Circumvention: copy the children of the document node,
not the document node itself, thus: