QueryResult.serialize() returning unexpected results
Added by lin am about 7 years ago
Hi, if a stylesheet has the following variable :
<xsl:variable name ="stuff" as="element()*" >
Apple
Berry
Cantalope
</xsl:variable>
and we use it as a Sequence argument for an extension function: func($stuff). Then serialize via QueryResult.serialize(NodeInfo node, StreamResult out, Properties outputProperties)
The output (if we check in out.toString()) ends up containing multiple iterations of the elements like this:
Apple Apple Berry Apple Berry Cantalope
Is this a bug or should we be using the serialize() method differently? Or use something else altogether? Thanks.
Replies (5)
Please register to reply
RE: QueryResult.serialize() returning unexpected results - Added by Michael Kay about 7 years ago
I can't quite see how you would pass that sequence of nodes to QueryResult.serialize(NodeInfo node, StreamResult out, Properties outputProperties), because that method requires a single node rather than a sequence.
So there's something happening here which I haven't fully understood from your explanation. Could you flesh out the detail of what exactly you are doing?
RE: QueryResult.serialize() returning unexpected results - Added by lin am about 7 years ago
Sorry I skipped that part. Basically it loops through the items in the sequence via SequenceIterator iterator,
for each of the item, check if it's NodeInfo, if so serialize it via QueryResult.serialize(NodeInfo node, StreamResult out, Properties outputProperties).
It generates a correct final output if we use QueryResult.serialize(NodeInfo node) instead to return a string, but we lose the option to set the output properties with that method.
RE: QueryResult.serialize() returning unexpected results - Added by lin am about 7 years ago
Actually it's calling QueryResult.serialize(nodeinfo, new StreamResult(out), props); I wonder if "out" is the problem here. Let me check that.
RE: QueryResult.serialize() returning unexpected results - Added by lin am about 7 years ago
So that was indeed the culprit. Case closed and happy Friday!
RE: QueryResult.serialize() returning unexpected results - Added by Michael Kay about 7 years ago
Still rather curious (presumably a case of stream buffering working unpredictably) but I'm glad you got to the bottom of it!
Please register to reply