Skip to content

Commit d267aca

Browse files
[bugfix] Fix serialization item separators for nodes.
1 parent be04720 commit d267aca

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/FunSerialize.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ public static Sequence normalize(final Expression callingExpr, final XQueryConte
148148
if (next.getType() == Type.ATTRIBUTE || next.getType() == Type.NAMESPACE || next.getType() == Type.FUNCTION_REFERENCE)
149149
{throw new XPathException(callingExpr, FnModule.SENR0001,
150150
"It is an error if an item in the sequence to serialize is an attribute node or a namespace node.");}
151-
temp.add(next);
151+
if (itemSeparator != null && itemSeparator.length() > 0 && !temp.isEmpty()) {
152+
temp.add(new StringValue(itemSeparator + next.getStringValue()));
153+
} else {
154+
temp.add(next);
155+
}
152156
} else {
153157
// atomic value
154158
Item last = null;

exist-core/src/test/xquery/xquery3/serialize.xql

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,3 +802,47 @@ function ser:item-separator-adaptive-method() {
802802
let $data := (1, 2)
803803
return ser:serialize-with-item-separator($data, "adaptive")
804804
};
805+
806+
declare
807+
%test:assertEquals("1|2|3|4|5|6|7|8|9|10")
808+
function ser:serialize-xml-033() {
809+
let $params :=
810+
<output:serialization-parameters xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization">
811+
<output:method value="xml"/>
812+
<output:item-separator value="|"/>
813+
</output:serialization-parameters>
814+
return serialize(1 to 10, $params)
815+
};
816+
817+
declare
818+
%test:assertEquals("1==2==3==4")
819+
function ser:serialize-xml-034() {
820+
let $params :=
821+
<output:serialization-parameters xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization">
822+
<output:method value="xml"/>
823+
<output:omit-xml-declaration value="yes"/>
824+
<output:item-separator value="=="/>
825+
</output:serialization-parameters>
826+
return serialize(1 to 4, $params)
827+
};
828+
829+
declare
830+
%test:assertEquals("1|2|3|4|5|6|7|8|9|10")
831+
function ser:serialize-xml-133() {
832+
let $params := map {
833+
"method" : "xml",
834+
"item-separator" : "|"
835+
}
836+
return serialize(1 to 10, $params)
837+
};
838+
839+
declare
840+
%test:assertEquals("1==2==3==4")
841+
function ser:serialize-xml-134() {
842+
let $params := map {
843+
"method" : "xml",
844+
"omit-xml-declaration" : true(),
845+
"item-separator" : "=="
846+
}
847+
return serialize((1 to 4)!text{.}, $params)
848+
};

0 commit comments

Comments
 (0)