The following XQuery produces a distinct list of <Inv> elements by performing a deep-equal() comparison of the sequence of <Inv> elements:
let $invSequence := /Root/Inv
(:
For each position(),
return the <inv> element who's position is equal to the current number,
and who's previous siblings are not deep-equal()
:)
for $pos in (1 to count($invSequence))
return $invSequence[$pos]
[not(some $inv in $invSequence[position() < $pos]
satisfies deep-equal(., $inv))]
The result:
<Inv>
<Id>1</Id>
<Name>John</Name>
</Inv>
<Inv>
<Id>2</Id>
<Name>Tom</Name>
</Inv>
<Inv>
<Id>4</Id>
<Name>Harry</Name>
</Inv>
<Inv>elements? Can you describe your criteria and show an example of the output that you are trying to generate from the sample input? - Mads Hansen