boolean nodeSetCompare = true; for(int i = 0; i < getLength(); i++) { if(!Type.subTypeOf(getExpression(i).returnsType(), Type.NODE)) nodeSetCompare = false; }  if(nodeSetCompare) { NodeSet rr, rl = (NodeSet) getExpression(0).eval(docs, contextSequence, contextItem); rl = rl.getContextNodes((NodeSet)contextSequence, inPredicate); for (int i = 1; i < getLength(); i++) { LOG.debug("processing " + getExpression(i).pprint()); rr = (NodeSet) getExpression(i).eval(docs, contextSequence, contextItem); rl = rl.intersection(rr.getContextNodes((NodeSet)contextSequence, inPredicate)); }
if (contextItem != null) contextSequence = contextItem.toSequence(); Expression left = getLeft(); Expression right = getRight(); if (Type.subTypeOf(left.returnsType(), Type.NODE) && Type.subTypeOf(right.returnsType(), Type.NODE)) { NodeSet rl = left.eval(docs, contextSequence, null).toNodeSet(); rl = rl.getContextNodes((NodeSet) contextSequence, inPredicate); NodeSet rr = right.eval(docs, contextSequence, null).toNodeSet(); rl = rl.intersection( rr.getContextNodes((NodeSet) contextSequence, inPredicate));
	public Sequence eval(DocumentSet docs, Sequence contextSequence, Item contextItem) throws XPathException {		if (getLength() == 0)			return Sequence.EMPTY_SEQUENCE;				boolean nodeSetCompare = true;		for(int i = 0; i < getLength(); i++) {			if(!Type.subTypeOf(getExpression(i).returnsType(), Type.NODE))				nodeSetCompare = false;		}				if(nodeSetCompare) {			NodeSet rr, rl = (NodeSet) getExpression(0).eval(docs, contextSequence, contextItem);			rl = rl.getContextNodes((NodeSet)contextSequence, inPredicate);			for (int i = 1; i < getLength(); i++) {				LOG.debug("processing " + getExpression(i).pprint());				rr = (NodeSet) getExpression(i).eval(docs, contextSequence, contextItem);				rl = rl.intersection(rr.getContextNodes((NodeSet)contextSequence, inPredicate));			}			return rl;		} else {			Sequence result = new ValueSequence();			Item item;			boolean r;			for(SequenceIterator i = contextSequence.iterate(); i.hasNext(); ) {				item = i.nextItem();				r = true;				for(int j = 0; j < getLength(); j++) {					r = getExpression(j).						eval(docs, contextSequence, item).effectiveBooleanValue();					if(!r)						break;				}				if(r)					result.add(item);			}			return result;		}	}