YouTip LogoYouTip

Xquery Flwor

# XQuery FLWOR Expressions * * * ## XML Example Document We will continue to use this "books.xml" document in the examples below (the same XML file as in the previous section). [View the "books.xml" file in your browser](#). * * * ## How to Select Nodes from "books.xml" Using FLWOR Look at the following path expression: doc("books.xml")/bookstore/book[price>30]/title The above expression selects all title elements under book elements under bookstore elements, 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: for $x in doc("books.xml")/bookstore/book where $x/price>30 return $x/title Output result: XQuery Kick Start Learning XML With FLWOR, you can sort the results: for $x in doc("books.xml")/bookstore/book where $x/price>30 order by $x/title return $x/title **FLWOR is an 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. Sorting will be based on the title element. The **return** statement specifies what to return. Here, it returns the title element. Result of the XQuery expression above: Learning XML XQuery Kick Start
← Xquery Flwor HtmlXquery Example β†’