* @return null - this implementation of the method never returns a TailCall
*/
public TailCall processLeavingTail(XPathContext context) throws XPathException {
SequenceReceiver out = context.getReceiver();
boolean copyBaseURI = (out.getSystemId() == null);
// if the copy is being attached to an existing parent, it inherits the base URI of the parent
int copyOptions = CopyOptions.TYPE_ANNOTATIONS;
if (copyNamespaces) {
copyOptions |= CopyOptions.ALL_NAMESPACES;
}
//int whichNamespaces = (copyNamespaces ? NodeInfo.ALL_NAMESPACES : NodeInfo.NO_NAMESPACES);
SequenceIterator iter = select.iterate(context);
while (true) {
Item item = iter.next();
if (item == null) {
break;
}
if (item instanceof NodeInfo) {
NodeInfo source = (NodeInfo) item;
int kind = source.getNodeKind();
switch (kind) {
case Type.ELEMENT: {
if (copyBaseURI) {
out.setSystemId(computeNewBaseUri(source));
}
source.copy(out, copyOptions);
break;
}
case Type.ATTRIBUTE:
try {
context.getReceiver().attribute(source.getNameCode(), source.getStringValueCS());
} catch (NoOpenStartTagException err) {
dynamicError(err.getMessage(), err.getErrorCodeLocalPart(), context);
}
break;
case Type.TEXT:
out.characters(source.getStringValueCS());
break;
case Type.PROCESSING_INSTRUCTION:
if (copyBaseURI) {
out.setSystemId(source.getBaseURI());
}
out.processingInstruction(source.getDisplayName(), source.getStringValueCS());
break;
case Type.COMMENT:
out.comment(source.getStringValueCS());
break;
case Type.NAMESPACE:
try {
source.copy(out, 0);
} catch (NoOpenStartTagException err) {
dynamicError(err.getMessage(), err.getErrorCodeLocalPart(), context);
}
break;
case Type.DOCUMENT: {
out.setPipelineConfiguration(out.getPipelineConfiguration());
if (copyBaseURI) {
out.setSystemId(source.getBaseURI());
}
source.copy(out, copyOptions);
break;
}
default:
throw new IllegalArgumentException("Unknown node kind " + source.getNodeKind());
}
} else {
out.append(item, NodeInfo.ALL_NAMESPACES);
}
}
return null;
}