XQuery order ascending and descending

In XQuery, how do you order ascending and descending?

I have the following from a tutorial:

for $x in doc("books.xml")/bookstore/book where $x/price>30 order by $x/title return $x/title 

would

 for $x in doc("books.xml")/bookstore/book where $x/price>30 order by $x/title ascending return $x/title 
+8
xml xquery
source share
2 answers

Yes, you can use ascending (the default) or descending at the end of the order by.. expression.

Here is a link to the relevant part of the W3C XQuery specification:

http://www.w3.org/TR/xquery/#doc-xquery-OrderSpec

+12
source share

See my answer to this question . The code shows the order in descending order.

For ascending order, the ascending keyword may be omitted.

+1
source share

All Articles