if (Expression.NO_CONTEXT_ID != contextId) ancestor.addContextNode(contextId, current); else ancestor.copyContext(current); result.add(ancestor);
NodeProxy t = result.get(ancestor); if (t == null) { if (Expression.NO_CONTEXT_ID != contextId) ancestor.addContextNode(contextId, current); else ancestor.copyContext(current); result.add(ancestor); } else t.addContextNode(contextId, current);
	protected NodeSet getAncestors(XQueryContext context, NodeSet contextSet) {				if (test.isWildcardTest()) {            NodeSet result = new ExtArrayNodeSet();                        for (Iterator i = contextSet.iterator(); i.hasNext();) {                NodeProxy current = (NodeProxy) i.next();                NodeProxy ancestor;                if (axis == Constants.ANCESTOR_SELF_AXIS && test.matches(current)) {                    ancestor = new NodeProxy(current.getDocument(), current.getGID(), current.getInternalAddress());                    if (Expression.NO_CONTEXT_ID != contextId)                        ancestor.addContextNode(contextId, current);                    else                        ancestor.copyContext(current);                    result.add(ancestor);                }                long parentID = NodeSetHelper.getParentId(current.getDocument(), current.getGID());                               while (parentID > 0) {                    ancestor = new NodeProxy(current.getDocument(), parentID, Node.ELEMENT_NODE);                    //Filter out the temporary nodes wrapper element                     if (parentID != NodeProxy.DOCUMENT_NODE_GID &&                             !(parentID == NodeProxy.DOCUMENT_ELEMENT_GID && current.getDocument().getCollection().isTempCollection())) {                        if (test.matches(ancestor)) {                            if (Expression.NO_CONTEXT_ID != contextId)                                ancestor.addContextNode(contextId, current);                            else                                ancestor.copyContext(current);                            result.add(ancestor);                                                }                    }                    parentID = NodeSetHelper.getParentId(ancestor);                }            }            return result;        } else if (preloadNodeSets()) {                        DocumentSet docs = getDocumentSet(contextSet);            if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) {                ElementIndex index = context.getBroker().getElementIndex();                 if (context.getProfiler().isEnabled())                    context.getProfiler().message(this, Profiler.OPTIMIZATIONS,                             "OPTIMIZATION", "using index '" + index.toString() + "'");                  currentSet = index.findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);                currentDocs = docs;                registerUpdateListener();            }                       switch (axis) {                case Constants.ANCESTOR_SELF_AXIS :                    return currentSet.selectAncestors(contextSet, true, contextId);                                   case Constants.ANCESTOR_AXIS :                                 return currentSet.selectAncestors(contextSet, false, contextId);                                    default :                    throw new IllegalArgumentException("Unsupported axis specified");                               }        		} else {            NodeSelector selector;                        DocumentSet docs = getDocumentSet(contextSet);            switch (axis) {                case Constants.ANCESTOR_SELF_AXIS :                    selector = new AncestorSelector(contextSet, contextId, true);                     break;                case Constants.ANCESTOR_AXIS :                                 selector = new AncestorSelector(contextSet, contextId, false);                    break;                default :                    throw new IllegalArgumentException("Unsupported axis specified");                               }            ElementIndex index = context.getBroker().getElementIndex();            if (context.getProfiler().isEnabled())                context.getProfiler().message(this, Profiler.OPTIMIZATIONS,                         "OPTIMIZATION", "using index '" + index.toString() + "'");                          return index.findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), selector);		}			}