}
    public Sequence eval(Sequence contextSequence, Item contextItem)            throws XPathException {        if (steps.size() == 0) return Sequence.EMPTY_SEQUENCE;        Sequence r;        if (contextSequence != null) {            r = contextSequence;        } else {            r = Sequence.EMPTY_SEQUENCE;        }        DocumentSet contextDocs = null;        Expression expr = (Expression) steps.getFirst();        if (expr instanceof VariableReference) {            Variable var = ((VariableReference) expr).getVariable();            if (var != null) {                contextDocs = var.getContextDocs();            }        }        NodeSet set;        Item current;        Sequence values;        for (Iterator iter = steps.iterator(); iter.hasNext();) {            expr = (Expression) iter.next();            if (contextDocs != null) expr.setContextDocSet(contextDocs);            if ((expr.getDependencies() & Dependency.CONTEXT_ITEM) != 0) {                if (r.getLength() == 0) {                    r = expr.eval(null, null);                } else {                    values = null;                    if (r.getLength() > 1) values = new ValueSequence();                    int pos = 0;                    context.setContextPosition(0);                    for (SequenceIterator iterInner = r.iterate(); iterInner                            .hasNext(); pos++) {                        context.setContextPosition(pos);                        current = iterInner.nextItem();                        if (values == null)                            values = expr.eval(r, current);                        else                            values.addAll(expr.eval(r, current));                    }                    r = values;                }            } else                r = expr.eval(r);        }        return r;    }