Item item = contextItem; if (getSignature().getArgumentCount() > 0) { Sequence seq = getArgument(0).eval(contextSequence, contextItem); if (seq.getLength() == 0) item = null; else item = seq.itemAt(0); }
	public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {        if (context.getProfiler().isEnabled()) {            context.getProfiler().start(this);                   context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));            if (contextSequence != null)                context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);            if (contextItem != null)                context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());        }                Sequence result;		Item item = contextItem;		if (getSignature().getArgumentCount() > 0) {			Sequence seq = getArgument(0).eval(contextSequence, contextItem);			if (seq.getLength() == 0)                item = null;            else                item = seq.itemAt(0);		}                if (item == null)            result = Sequence.EMPTY_SEQUENCE;        else {    		if (!Type.subTypeOf(item.getType(), Type.NODE))    			throw new XPathException("Context item is not a node; got " + Type.getTypeName(item.getType()));    		if (item instanceof NodeProxy) {                NodeProxy p = ((NodeProxy) item);                org.exist.dom.DocumentImpl doc = p.getDocument();    		    //Filter out the temporary nodes wrapper element                 if (doc.getCollection().isTempCollection()) {                    //TODO check that we only have one child                    StoredNode trueRoot = (StoredNode)doc.getDocumentElement().getFirstChild();                    result = new NodeProxy(doc, trueRoot.getGID(), trueRoot.getInternalAddress());                } else                                    result = new NodeProxy(((NodeProxy) item).getDocument());    		} else    		    result = (DocumentImpl) ((NodeImpl) item).getOwnerDocument();        }                if (context.getProfiler().isEnabled())             context.getProfiler().end(this, "", result);                 return result;         	}