Thank you very much, Leo, and thanks for your interest, Marc.
An observation I made, and which turned out to be crucial to my concrete problem:
return ...
So the final step
/document{.}
turns the for loop into caching. Interestingly, the problem can be worked around very simply:
not caching:
for $node at $pos in doc('otds-fti')/foo/bar
let $node := document{.}
return ...
I am very glad that the problem could be solved. Your pointing out the importance of the expression details
"and the XPath expression you used only contains child steps, which can be evaluated in document order without duplicates."
helped me to make the revealing experiment.
Thanks again -
Hans-Jürgen
PS: Interestingly, the following variant is also not caching:
f:evaluate($expr, $context) {
let $ctx := map{'': $context}
return xquery:eval($expr $ctx)
};
let $context := doc('otds-fti')
for $node at $pos in f:evaluate('/foo/bar', $context)
let $node := document{.}
return ...