XML File
<map>
<links>
<link id="10" ordernum="0"></link>
<link id="20" ordernum="1"></link>
<link id="30" ordernum="2"></link>
</links>
<products>
<product id="10" group="2">...</product>
<product id="20" group="1">...</product>
<product id="30" group="2">...</product>
</products>
</map>
I'm using the following Xquery to get the products/@id, ordered by the corresponding link/@ordernum but only once for the same group.
for $linkid in //links/link
order by $linkid/@ordernum
return distinct-values(data(//products/product[@id=data($linkid/@id)]/@id))
Expected output: 10, 20
Received output: 10, 20, 30