File: Data.xml
0001
name 1
0002
name 2
0003
name 3
File: Query.xquery
for $car in doc("Data.xml")//car
return
{$car/id}
{for $price in doc("Data.xml")//prod
where $car/id = $price/@id
return $price/price}
Output:
0001
0002
0003