File: Data.xml
File: Query.xquery
for $d in distinct-values(doc("Data.xml")//car/@model)
let $cars := doc("Data.xml")//car[@model = $d]
order by $d
return {
for $i in $cars
order by $i/@id
return $i
}
Output: