Sequence r = whereExpr.eval(context, docs, contextSequence); if (r.effectiveBooleanValue()) return r; else return Sequence.EMPTY_SEQUENCE;
NodeSet result = new ExtArrayNodeSet(); int p = 0; context.setContextPosition(0); for (SequenceIterator i = contextSequence.iterate(); i.hasNext(); p++) { Item item = i.nextItem(); context.setContextPosition(p); Sequence innerSeq = whereExpr.eval(docs, contextSequence, item); if (innerSeq.effectiveBooleanValue()) result.add(item); } return result;
	protected Sequence applyWhereExpression(		StaticContext context,		DocumentSet docs,		Sequence contextSequence)		throws XPathException {		whereExpr.setInPredicate(true);		if (Type.subTypeOf(whereExpr.returnsType(), Type.NODE)) {			// if the where expression returns a node set, check the context			// node of each node in the set			NodeSet temp =				whereExpr.eval(context, docs, contextSequence).toNodeSet();			LOG.debug("found " + temp.getLength());			NodeProxy current;			ContextItem contextNode;			NodeProxy next;			DocumentImpl lastDoc = null;			int count = 0, sizeHint = -1;			NodeSet result = new ExtArrayNodeSet();			for (Iterator i = temp.iterator(); i.hasNext(); count++) {				current = (NodeProxy) i.next();				if (lastDoc == null || current.doc != lastDoc) {					lastDoc = current.doc;					sizeHint = temp.getSizeHint(lastDoc);				}				contextNode = current.getContext();				if (contextNode == null) {					throw new XPathException("Internal evaluation error: context node is missing!");				}				while (contextNode != null) {					next = contextNode.getNode();					next.addMatches(current.match);					if (!result.contains(next))						result.add(next, sizeHint);					contextNode = contextNode.getNextItem();				}			}			return result;		} else {			// general where clause: just check the effective boolean value			Sequence r = whereExpr.eval(context, docs, contextSequence);			if (r.effectiveBooleanValue())				return r;			else				return Sequence.EMPTY_SEQUENCE;		}	}