> Now the problem is that XQuery (of the eXist variety) denies knowledge of the existence of the $i variable in the return clause. Yes, the original implementor left a todo comment in the code ;-) The $i variable should be in scope. I’ve just submitted a pull request for this. Wolfgang