// create the output
MemTreeBuilder builder = context.getDocumentBuilder();
DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder);
try {
SequenceIterator i = result.iterate();
Item next = i.nextItem();
StringBuilder buf = null;
boolean allowAttribs = true;
while (next != null) {
context.proceed(this, builder);
// if item is an atomic value, collect the string values of all
// following atomic values and seperate them by a space.
if (Type.subTypeOf(next.getType(), Type.ATOMIC)) {
if(buf == null)
buf = new StringBuilder();
else if (buf.length() > 0)
buf.append(' ');
buf.append(next.getStringValue());
allowAttribs = false;
next = i.nextItem(); // if item is a node, flush any collected character data and
// copy the node to the target doc.
} else if (Type.subTypeOf(next.getType(), Type.NODE)) {
if (buf != null && buf.length() > 0) {
receiver.characters(buf);
buf.setLength(0);
}
if (next.getType() == Type.ATTRIBUTE && !allowAttribs)
throw new XPathException(this, "XQTY0024: An attribute may not appear after " +
"another child node.");
next.copyTo(context.getBroker(), receiver);
allowAttribs = next.getType() == Type.ATTRIBUTE;
next = i.nextItem();
}
}
// flush remaining character data
if (buf != null && buf.length() > 0)