XQuery FLWOR Expressions
- Previous Page XQuery Examples
- Next Page XQuery HTML
Mga halimbawa ng XML na dokumento
Magpatuloy kami sa mga halimbawa sa ibabaw ng dokumentong "books.xml" (kasama ang XML file sa nakaraang section).
Kung gamitin ang FLWOR para sa pagpili ng mga node mula sa "books.xml"
Mangyaring tingnan ang kasunod na ekspresyong daan:
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 following FLWOR expression selects the same data 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>
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 the acronym for "For, Let, Where, Order by, Return".
for The statement extracts all book elements under the bookstore element into a 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 is based on the title element.
return The statement specifies what content is returned. In this case, it returns the title element.
The result of the above XQuery expression is:
<title lang="en">Learning XML</title> <title lang="en">XQuery Kick Start</title>
- Previous Page XQuery Examples
- Next Page XQuery HTML