MemTreeBuilder builder = context.getDocumentBuilder();
try {
// for (Item item : contextSequence) {
for (SequenceIterator iterInner = contextSequence.iterate(); iterInner.hasNext();) {
Item i = iterInner.nextItem();
org.w3c.dom.Node item;
if (i instanceof NodeValue) {
item = ((NodeValue) i).getNode();
} else
item = (org.w3c.dom.Node) i;
//UNDERSTAND: strange place to workaround
if (item instanceof org.w3c.dom.Document) {
org.w3c.dom.Document document = (org.w3c.dom.Document) item;
item = document.getDocumentElement();
}
if (item instanceof org.w3c.dom.Element) {
QName qn;
if (item instanceof QNameValue) {
qn = ((QNameValue)item).getQName();
} else {
qn = ((QNameable)item).getQName();
if (qn.getPrefix() == null && context.getInScopeNamespace("") != null) {
qn.setNamespaceURI(context.getInScopeNamespace(""));
}
}
int nodeNr = builder.startElement(qn, null);
if (use_attribute_sets != null)
getXSLContext().getXSLStylesheet().attributeSet(use_attribute_sets, contextSequence, i);
super.eval(contextSequence, i);
builder.endElement();
NodeImpl node = builder.getDocument().getNode(nodeNr);
result.add(node);
} else if (item instanceof org.w3c.dom.Text) {
int nodeNr = builder.characters(i.getStringValue());
NodeImpl node = builder.getDocument().getNode(nodeNr);
result.add(node);
} else {
throw new XPathException("not supported node type "+i.getType());
}
}
} finally {
context.popInScopeNamespaces();
}