File: Data.xml
0001
name 1
0002
name 2
0003
name 3
File: Query.xquery
let $prods := doc("Data.xml")//car
for $prod in $prods
where $prod << $prods[@model = $prod/@model][last()]
return $prod
Output:
0002
name 2