XQuery while using distinct-values()
xml, xpath, xquery
Solution
pls try this -
for $x in distinct-values(doc("sample")/Cities/Place/City/@n)
order by $x
return $x
I have checked the same with baseX 7.1 and working smoothly as expected by you :)
Problem
XML File ``` <Cities> <Place> <City n="New Delhi"></City> <City n="Chandigarh"></City> <City n="Mumbai"></City> </Place> <Place> <City n="New Delhi"></City> <City n="Chandigarh"></City> </Place> <Place> <City n="New Delhi"></City> <City n="Mumbai"></City> </Place> </Cities> ``` I am using following XQuery - ``` for $x in doc("sample")/Cities/Place/City order by $x/@n return distinct-values($x/@n) ``` The result I am expecting is - `Chandigarh Mumbai New Delhi` but getting - `Chandigarh Chandigarh Mumbai Mumbai New Delhi New Delhi New Delhi` Please tell me where am I going wrong?