XQuery FLWOR expression
XML Example Document
We will continue to use this "books.xml" document (the same XML file from the previous section) in the following examples.
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 can select all title elements under the book element under the bookstore element, and the value of the price element must be greater than 30.
The data selected by the FLWOR expression below is the same 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 the acronym 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 whose price element value is greater than 30. The
order by statement defines the sort order. Will be sorted based on the title element.
return statement specifies what to return. What is returned here is the title element.
The result of the above XQuery expression:
<title lang="en" >XQuery Kick Start</title>