<order>
<key><landId>0012</landId>....here are other key elements......</key>
.....here are other elements.........
<item>
<name>name1</name>
</item>
<item>
<name>name2</name>
</item>
.....here are other elements.........
</order>
I want to get the sorted Item List of the order with its landId.
question:
how can i sort the items by name?
I used the following xquery and have got an error message:sequernce occurrend where atomic value required.
for $q in input()/order
where $q/key/landId='0012'
sort by ($q/item/name)
return <myOrder><land>{$q/key/landId}</land>{$q/item} </myOrder>
you see that there are two item/name nodes. The “sort” applies to the document and does not know which item/name node the documents should be sorted by.
To sort on the inner nodes the following xquery might work for you:
let $order := <order><key><landid>0012</landid></key><item><name>name3</name></item><item><name>name2</name></item><item><name>name1</name></item></order>
for $q in $order
where $q/key/landid = "0012"
return
<myorder>
<land>{$q/key/landid}</land>
{
for $i in $q/item sort by (name) return $i
}
</myorder>