Latest web development tutorials

XQuery FLWOR expression

XML instance documents

We will continue to use the "books.xml" document in the following example (in an XML file in the same).

See "books.xml" file in your browser .


If you use the FLWOR select nodes from "books.xml"

Look at the following path expression:

doc("books.xml")/bookstore/book[price>30]/title

This expression can be selected above all the title elements under the book elements under the bookstore element, and the value of the price element which must be greater than 30.

FLWOR expression below the selected data and the above path is the same as this expression:

for $x in doc("books.xml")/bookstore/book
where $x/price>30
return $x/title

Output:

<title lang="en">XQuery Kick Start</title>
<title lang="en">Learning XML</title>

By 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 "For, Let, Where, Order by, Return" only take acronym.

statements for all book elements under the bookstore element into a variable named $ x extraction in.

where statements element selected book price element values greater than 30.

order by statement defines the sort order. Will be sorted according to the title element.

return statement specifies what they return. In this returns the title elements.

The above XQuery expression results:

<title lang="en">Learning XML</title>
<title lang="en">XQuery Kick Start</title>