XQuery FLWOR
Expression
XML Example Document
We will continue to use the "books.xml" document in the following examples (same as the XML file in the previous section).
View the "books.xml" file in your browser.
Selecting Nodes from "books.xml" Using FLWOR
Consider the following path expression:
This expression selects all title elements under the book elements under the bookstore element, where the value of the price element is greater than 30.
The following FLWOR expression selects the same data as the path expression above:
Output result:
With FLWOR, you can sort the results:
FLWOR stands for "For, Let, Where, Order by, Return."
The for statement extracts all book elements under the bookstore element into a variable named $x.
The where statement selects book elements where the price element value is greater than 30.
The order by statement defines the sort order, which is based on the title element.
The return statement specifies what content to return, in this case, the title element.
The result of the above XQuery expression: