if (newDoc != null) {
NodeId rootId = newDoc.getBrokerPool().getNodeFactory().createInstance();
for (int j = i; j <= size; j++) {
v = (NodeValue) values[j];
if(v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
NodeImpl node = (NodeImpl) v;
if (node.getDocument() == doc) {
if (node.getNodeType() == Node.ATTRIBUTE_NODE)
{node = expandedDoc.getAttribute(node.getNodeNumber());}
else
{node = expandedDoc.getNode(node.getNodeNumber());}
NodeId nodeId = node.getNodeId();
if (nodeId == null)
{throw new XPathException("Internal error: nodeId == null");}
if (node.getNodeType() == Node.DOCUMENT_NODE)
{nodeId = rootId;}
else
{nodeId = rootId.append(nodeId);}
NodeProxy p = new NodeProxy(newDoc, nodeId, node.getNodeType());
if (p != null) {
// replace the node by the NodeProxy
values[j] = p;
}
}