Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#179 saxon:evaluate params must be singletons

v7.8
closed
Michael Kay
5
2012-10-08
2003-12-14
Michael Kay
No

The saxon:evaluate function does not work correctly if
the values of parameters to the dynamic expression ($p1
to $pN) are sequences, as opposed to singletons. The
effect may be a crash, or incorrect results (e.g.
selecting only the first item in the sequence).

The following fix appears to work: change the method
iterate() in net.sf.saxon.functions.Evaluate to read:

public SequenceIterator iterate(XPathContext c)

throws XPathException {
PreparedExpression pexpr = prepareExpression(c);

    if (operation == EXPRESSION) {
        return SingletonIterator.makeIterator(new

ObjectValue(pexpr));
} else {
for (int i=1; i<getNumberOfArguments(); i++) {

pexpr.variables[i-1].setValue(ExpressionTool.eagerEvaluate(argument[i],c));
}
return pexpr.expression.iterate(c);
}
}

and make the corresponding change to the evaluateItem
method:

public Item evaluateItem(XPathContext c) throws

XPathException {
PreparedExpression pexpr = prepareExpression(c);

    if (operation == EXPRESSION) {
        return new ObjectValue(pexpr);
    } else {
        for (int i=1; i&lt;getNumberOfArguments(); i++) {

pexpr.variables[i-1].setValue(ExpressionTool.eagerEvaluate(argument[i],c));
}
return pexpr.expression.evaluateItem(c);
}
}

Test case added: saxon07

Discussion