Project

Profile

Help

Support #6369

closed

Serialization problem of XQuery result using Saxon 12.3

Added by Radu Coravu 2 months ago. Updated 15 days ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2024-03-06
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

We run this XQuery as a transformation scenario in Oxygen:

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method 'text';
declare option output:item-separator ', ';
let $xml:=<xml><element>text1</element><element>text2</element></xml> return $xml/element/string()

and we get as result:

text1,  , text2

Notice the two commas ", " between the two items.

To serialize we create a tree receiver something like:

    SerializerFactory sf = this.queryTransformer.getConfiguration().getSerializerFactory();
    PipelineConfiguration pipe = this.queryTransformer.getConfiguration().makePipelineConfiguration();
    SerializationProperties props = new SerializationProperties(queryTransformer.getOutputProperties());
    Receiver receiver = sf.getReceiver(new StreamResult(sw), props, pipe);
    tr = new TreeReceiver(receiver)..

The "net.sf.saxon.event.SequenceReceiver#decompose" is called for each item "text1" and "text2". The stack trace is something like:

	at net.sf.saxon.str.UnicodeWriterToWriter.write(UnicodeWriterToWriter.java:36)
	at net.sf.saxon.serialize.TEXTEmitter.characters(TEXTEmitter.java:104)
	at net.sf.saxon.event.ProxyReceiver.characters(ProxyReceiver.java:158)
	at net.sf.saxon.event.SequenceNormalizer.characters(SequenceNormalizer.java:99)
	at net.sf.saxon.event.SequenceNormalizerWithItemSeparator.sep(SequenceNormalizerWithItemSeparator.java:135)
	at net.sf.saxon.event.SequenceNormalizerWithItemSeparator.characters(SequenceNormalizerWithItemSeparator.java:75)
	at net.sf.saxon.event.TreeReceiver.characters(TreeReceiver.java:176)
	at net.sf.saxon.event.SequenceReceiver.decompose(SequenceReceiver.java:178)

For "text2" which is ATOMIC the code in "net.sf.saxon.event.SequenceReceiver.decompose(Item, Location, int)" does this:

                       protected void decompose(Item item, Location locationId, int copyNamespaces) throws XPathException {
        if (item != null) {
            switch (item.getGenre()) {
                case ATOMIC:
                case EXTERNAL:
                    if (previousAtomic) {
                        characters(StringConstants.SINGLE_SPACE, locationId, ReceiverOption.NONE);
                    }
                    characters(item.getUnicodeStringValue(), locationId, ReceiverOption.NONE);

It calls "characters(StringConstants.SINGLE_SPACE, locationId, ReceiverOption.NONE);" which adds a space and a comma before the space as the method "net.sf.saxon.event.SequenceNormalizerWithItemSeparator.characters(UnicodeString, Location, int)" always calls sep(). And then it calls:

characters(item.getUnicodeStringValue(), locationId, ReceiverOption.NONE);

which again adds a comma before the value. So we get two commas before the actual value is printed.

Please register to edit this issue

Also available in: Atom PDF