XQuery FLWOR Expressions

XML fayilin kaiyadanci

kaiko dake da baya ana baya "books.xml" fayilin (ka dake da baya "section" fayilin) dake.

kaiko "books.xml" fayilin "browser" dake.

idan ana baya FLWOR ka "books.xml" ka yin

kaiko dake da baya bana:

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

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

The data selected by the following FLWOR expression is the same as the above path expression:

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

The result is:

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

Through 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 the abbreviation for 'For, Let, Where, Order by, Return'.

for The statement extracts all book elements under the bookstore element to the variable named $x.

where The statement selects book elements with a price element value greater than 30.

order by The statement defines the sorting order. The sorting will be based on the title element.

return The statement specifies what content is returned. In this case, it is the title element that is returned.

The result of the above XQuery expression is:

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