May 28, 2021 XQuery
FLWOR expressions are one of XQuery's most important expressions, and this section takes you through the use of FLWOR expressions.
We'll continue to use this "books.xml" document in the following example (the same as the XML file in the previous section).
View the "books" file .xml your browser.
Look at this path expression:
The above expression picks all the title elements under the book element under the bookstore element, and the value of the price element there must be greater than 30.
The following FLWOR expression picks the same data as the path expression above:
Output:
With FLWOR, you can sort the results:
FLWOR is an acronym for "For, Let, Where, Order by, Return".
The for statement extracts all the book elements under the bookstore element into a $x called the file.
The where statement selects a book element with a price element value greater than 30.
The order by statement defines the sort order. Sorts are based on the title element.
The return statement specifies what is returned. The title element is returned here.
The result of the XQuery expression above:
Next, in the next section, you'll see how FLWOR and HTML work together in XQuery.