#558 Creative Let expressions

Michael Kay

An XQuery expression that constructs new nodes is
classified by Saxon as a "creative" expression.
Creative expressions cannot be moved out of a loop,
because executing the same expression repeatedly will
produce different results (nodes with different identity).

The expression (let $x in E return R) is not being
classified as creative. If E is creative, then it
should be, at least in certain cases, for example where
R is the expression "$x".

The result is that whereas the expression

for $i in 1 to 3 return <e/>

returns three distinct element nodes, the expression

for $i in 1 to 3 return
let $e := <e/> return $e

returns the same element node three times, so an
operation that eliminates duplicates will treat the
nodes as identical.

The patch to classify the let expression correctly is
to change the method computeSpecialProperties() in
net.sf.saxon.expr.LetExpression (line 232) to read:

public int computeSpecialProperties() {
    int props = action.getSpecialProperties();
    int seqProps = sequence.getSpecialProperties();
    if ((seqProps & StaticProperty.NON_CREATIVE) ==

0) {
props &= ~StaticProperty.NON_CREATIVE;
return props;


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks