<div dir="ltr">for $x at $i in blah<div>  group by $x/@a</div><div>   return </div><div>     if ($i mod 10000 eq 0) then ..... else .....</div><div><br></div><div><br></div><div>Now the problem is that XQuery (of the eXist variety) denies knowledge of the existence of the $i variable in the return clause. Presumably this is because the group construct interferes with the lexical scoping. </div>

<div><br></div><div>I do not have to do this with XQuery as I can solve it downstream but I would be interested in learning more about this scenario.<br></div><div><br></div><div><br></div><div><br></div><div>  </div></div>