File: Data.xml
0001
name 1
navy black
0002
name 2
0003
name 3
0004
name 4
File: Query.xquery
let $sortedProds := for $prod in doc("Data.xml")//car
order by $prod/id
return $prod
for $prodName in $sortedProds/name
return {string($prodName)}
Output:
name 1
name 2
name 3
name 4