}
}
public TailCall processLeavingTail(XPathContext context) throws XPathException {
Controller controller = context.getController();
XPathContext c2 = context;
// XPathContext c2 = context.newMinorContext();
// c2.setOrigin(this);
SequenceReceiver out = c2.getReceiver();
Item item = context.getContextItem();
if (!(item instanceof NodeInfo)) {
out.append(item, locationId, NodeInfo.ALL_NAMESPACES);
return null;
}
NodeInfo source = (NodeInfo)item;
//out.getPipelineConfiguration().setBaseURI(source.getBaseURI());
// Processing depends on the node kind.
switch(source.getNodeKind()) {
case Type.ELEMENT:
// use the generic code for creating new elements
return super.processLeavingTail(c2);
case Type.ATTRIBUTE:
try {
CopyOf.copyAttribute(source, getSchemaType(), validation, this, c2, false);
} catch (NoOpenStartTagException err) {
err.setXPathContext(context);
throw dynamicError(this, err, c2);
}
break;
case Type.TEXT:
out.characters(source.getStringValueCS(), locationId, 0);
break;
case Type.PROCESSING_INSTRUCTION:
out.processingInstruction(source.getDisplayName(), source.getStringValueCS(), locationId, 0);
break;
case Type.COMMENT:
out.comment(source.getStringValueCS(), locationId, 0);
break;
case Type.NAMESPACE:
try {
source.copy(out, NodeInfo.NO_NAMESPACES, false, locationId);
} catch (NoOpenStartTagException err) {
XPathException e = new XPathException(err.getMessage());
e.setXPathContext(context);
e.setErrorCode(err.getErrorCodeLocalPart());
throw dynamicError(this, e, context);
}
break;
case Type.DOCUMENT:
if (!preservingTypes) {
Receiver val = controller.getConfiguration().
getDocumentValidator(out, source.getBaseURI(),
validation, Whitespace.NONE, getSchemaType(), -1);
if (val != out) {
SequenceReceiver sr = new TreeReceiver(val);
sr.setPipelineConfiguration(out.getPipelineConfiguration());
c2.setReceiver(sr);
out = sr;
}
}
out.startDocument(0);
content.process(c2);