Unit3
Unit3
FLWOR is an acronym that stands for "For, Let, Where, Order by, Return".
The following list shows what they account for in a FLWOR expression:
F - For - Selects a collection of all nodes.
L - Let - Puts the result in an XQuery variable.
W - Where - Selects the nodes specified by the condition.
O - Order by - Orders the nodes specified as per criteria.
R - Return - Returns the final result.
Example : We will use a FLWOR expression to retrieve the titles of those books with a price greater than 30.
Books.xml Books.xqy
<?xml version="1.0" encoding="UTF-8"?> let $books := (doc("books.xml")/books/book)
<books> return
<book category="JAVA"> {
<title lang="en">Learn Java in 24 Hours</title> for $x in $books
<author>Robert</author> where $x/price>30
<year>2005</year> order by $x/price
<price>30.00</price> return $x/title
</book> }
<book category="DOTNET">
<title lang="en">Learn .Net in 24 hours</title>
<author>Peter</author>
<year>2011</year>
<price>70.50</price>
</book>
Advance Expressions
• Except FLOWR others expression also there :
1) XQuery Conditional Expression :
"If-Then-Else" expressions are allowed in XQuery.
Example :
<adult>Dot Not
</adult>
for $x in doc("books.xml")/books/book <child>peter</
child>
return if ($x/@category=“java") <adult>Java</a
dult>
then <child>{data($x/title)}</child> <child>Robert<
/child>
else <adult>{data($x/title)}</adult>
XQuery Regular Expression