child.addContextNode(contextId, parent);
child.deepCopyContext(parent, contextId);
    public static NodeSet selectParentChild(NodeSet dl, NodeSet al, int mode,            int contextId) {        ExtArrayNodeSet result = new ExtArrayNodeSet();        DocumentImpl lastDoc = null;        switch (mode) {        case NodeSet.DESCENDANT:            for (Iterator i = dl.iterator(); i.hasNext();) {                int sizeHint = Constants.NO_SIZE_HINT;                NodeProxy child = (NodeProxy) i.next();                if (lastDoc == null || child.getDocument() != lastDoc) {                    lastDoc = child.getDocument();                    sizeHint = dl.getSizeHint(lastDoc);                }                NodeProxy parent = al.parentWithChild(child, true, false,                        NodeProxy.UNKNOWN_NODE_LEVEL);                if (parent != null) {                    if (Expression.NO_CONTEXT_ID != contextId)                        child.addContextNode(contextId, parent);                    else                        child.copyContext(parent);                    result.add(child, sizeHint);                }            }            break;        case NodeSet.ANCESTOR:            for (Iterator i = dl.iterator(); i.hasNext();) {                int sizeHint = Constants.NO_SIZE_HINT;                NodeProxy child = (NodeProxy) i.next();                if (lastDoc == null || child.getDocument() != lastDoc) {                    lastDoc = child.getDocument();                    sizeHint = al.getSizeHint(lastDoc);                }                NodeProxy parent = al.parentWithChild(child, true, false,                        NodeProxy.UNKNOWN_NODE_LEVEL);                if (parent != null) {                    if (Expression.NO_CONTEXT_ID != contextId)                        parent.addContextNode(contextId, child);                    else                        parent.copyContext(child);                    result.add(parent, sizeHint);                }            }            break;        default:            throw new IllegalArgumentException("Bad 'mode' argument");        }        result.sort();        return result;    }