@@ -144,32 +144,20 @@ public static Sequence normalize(final Expression callingExpr, final XQueryConte
144
144
if (input .isEmpty ())
145
145
// "If the sequence that is input to serialization is empty, create a sequence S1 that consists of a zero-length string."
146
146
{return StringValue .EMPTY_STRING ;}
147
+ final String _separator = itemSeparator == null ? DEFAULT_ITEM_SEPARATOR : itemSeparator ;
147
148
final ValueSequence temp = new ValueSequence (input .getItemCount ());
148
149
for (final SequenceIterator i = input .iterate (); i .hasNext (); ) {
149
150
final Item next = i .nextItem ();
150
151
if (Type .subTypeOf (next .getType (), Type .NODE )) {
151
152
if (next .getType () == Type .ATTRIBUTE || next .getType () == Type .NAMESPACE || next .getType () == Type .FUNCTION_REFERENCE )
152
153
{throw new XPathException (callingExpr , FnModule .SENR0001 ,
153
154
"It is an error if an item in the sequence to serialize is an attribute node or a namespace node." );}
154
- if (itemSeparator != null && itemSeparator .length () > 0 && !temp .isEmpty ()) {
155
- temp .add (new StringValue (itemSeparator + next .getStringValue ()));
156
- } else {
157
- temp .add (next );
158
- }
155
+ temp .add (next );
159
156
} else {
160
157
// atomic value
161
- Item last = null ;
162
- if (!temp .isEmpty ())
163
- {last = temp .itemAt (temp .getItemCount () - 1 );}
164
- if (last != null && last .getType () == Type .STRING )
165
- // "For each subsequence of adjacent strings in S2, copy a single string to the new sequence
166
- // equal to the values of the strings in the subsequence concatenated in order, each separated
167
- // by a single space."
168
- {((StringValue )last ).append ((itemSeparator == null ? " " : itemSeparator ) + next .getStringValue ());}
169
- else
170
- // "For each item in S1, if the item is atomic, obtain the lexical representation of the item by
171
- // casting it to an xs:string and copy the string representation to the new sequence;"
172
- {temp .add (new StringValue (callingExpr , next .getStringValue ()));}
158
+ // "For each item in S1, if the item is atomic, obtain the lexical representation of the item by
159
+ // casting it to an xs:string and copy the string representation to the new sequence;"
160
+ temp .add (new StringValue (callingExpr , next .getStringValue ()));
173
161
}
174
162
}
175
163
@@ -184,6 +172,9 @@ public static Sequence normalize(final Expression callingExpr, final XQueryConte
184
172
} else {
185
173
receiver .characters (next .getStringValue ());
186
174
}
175
+ if (i .hasNext ()) {
176
+ receiver .characters (_separator );
177
+ }
187
178
}
188
179
return (DocumentImpl )receiver .getDocument ();
189
180
} catch (final SAXException e ) {
0 commit comments