File: Data.xml
0001
name 1
0002
name 2
0003
name 3
0004
name 4
File: Query.xquery
let $modelNames :=
let $cat := doc("Data.xml")/order
for $model in distinct-values($cat/car/@model)
return Department: {data($modelNames/model[@code = $model]/@name)
} ({$model})
Output:
Department: Womens (A)
Department: Accessories (B)
Department: Menswear (C)