if(orderSpecs != null) result = new OrderedValueSequence(orderSpecs, in.getLength()); else result = new ValueSequence();
if(resultSequence == null) { if(orderSpecs != null) resultSequence = new OrderedValueSequence(orderSpecs, in.getLength()); else resultSequence = new ValueSequence(); }
	public Sequence eval(		Sequence contextSequence,		Item contextItem)		throws XPathException {		Sequence result = null;		context.pushLocalContext(false);		// declare the variable		Variable var = new Variable(QName.parse(context, varName));		context.declareVariable(var);				// declare positional variable		Variable at = null;		if(positionalVariable != null) {			at = new Variable(QName.parse(context, positionalVariable));			context.declareVariable(at);		}				// evaluate the "in" expression		Sequence in = inputSequence.eval(null, null);		var.setValue(in);		if(whereExpr != null) {			whereExpr.setInPredicate(true);			setContext(in);		}		boolean fastExec = whereExpr != null &&			( whereExpr.getDependencies() & Dependency.CONTEXT_ITEM ) == 0 &&			at == null &&			in.getItemType() == Type.NODE;					if(fastExec) {			LOG.debug("fast evaluation mode");			in = applyWhereExpression(in);			LOG.debug("where found " + in.getLength());		}				if(orderSpecs != null)			result = 				new OrderedValueSequence(orderSpecs, in.getLength());		else			result = new ValueSequence();					Sequence val = null;		int p = 1;		IntegerValue atVal = new IntegerValue(1);		if(positionalVariable != null)			at.setValue(atVal);		// loop through each variable binding		for (SequenceIterator i = in.iterate(); i.hasNext(); p++) {			contextItem = i.nextItem();			context.setContextPosition(p);			atVal.setValue(p);			contextSequence = contextItem.toSequence();			if(sequenceType != null)				// check sequence type				sequenceType.checkType(contextItem.getType());			// set variable value to current item			var.setValue(contextSequence);			val = contextSequence;			// check optional where clause			if (whereExpr != null && (!fastExec)) {				if(contextItem instanceof NodeProxy)					((NodeProxy)contextItem).addContextNode((NodeProxy)contextItem);				Sequence bool = applyWhereExpression(contextSequence);				if(!bool.effectiveBooleanValue())					continue;			} else				val = contextItem.toSequence();						// if there is no "order by" clause, immediately call			// the return clause			if(orderSpecs == null)				val = returnExpr.eval(val);			result.addAll(val);		}		if(orderSpecs != null) {			// sort the result and call return for every item			((OrderedValueSequence)result).sort();			Sequence orderedResult = new ValueSequence();			p = 1;			for(SequenceIterator i = result.iterate(); i.hasNext(); p++) {				contextItem = i.nextItem();				contextSequence = contextItem.toSequence();				// set variable value to current item				var.setValue(contextSequence);				context.setContextPosition(p);				val = returnExpr.eval(contextSequence);				orderedResult.addAll(val);			}			result = orderedResult;		}		context.popLocalContext();		return result;	}