<div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Which must be a bug. saxon returns a different result.<br><div class="im">
</div></blockquote><div><br>Perhaps, or I&#39;ve lost something in translation from my simplified example.<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">
</div>
Using distinct-values to group by id could be another option, though maybe not the fastest:<br>
<br>
for $id in distinct-values(/items//id)<br>
let $itemsById := /items/item[id = $id]<br>
return<br>
    $itemsById[version = max($itemsById/version)]<br>
<br>
You should have an index on id and version in any case.<br><font color="#888888">
</font></blockquote></div><br>This worked!  It&#39;s twice as fast as my original convoluted solution.<br><br>Many thanks to all who responded!!<br><br>-- <br>A. Steven Anderson<br>Independent Consultant<br><a href="mailto:steve@asanderson.com">steve@asanderson.com</a><br>