XQuery FLWORExpressions
XML Example Document
We will continue to use this "books.xml" document in the examples below (same as the XML file in the previous section).
View the "books.xml" file in your browser。
If you use FLWOR to select nodes from "books.xml"
Please look at the following path expression:
The above expression selects all title elements under the book element under the bookstore element, where the value of the price element must be greater than 30.
The following FLWOR expression selects the same data as the path expression above:
where $x/price>30
return $x/title
Output result:
<title lang="en">Learning XML</title>
With FLWOR, you can sort the results:
where $x/price>30
order by $x/title
return $x/title
FLWOR is an acronym for "For, Let, Where, Order by, Return".
forThe statement extracts all book elements under the bookstore element into a variable named $x.
whereThe statement selects book elements whose price element value is greater than 30.
order byThe statement defines the sort order. It will sort according to the title element.
returnThe statement specifies what content to return. Here, it returns the title element.
The result of the XQuery expression above:
<title lang="en">XQuery Kick Start</title>