Skip to main content


What is FLWOR?

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:

  • For: selects a sequence of nodes
  • Let: binds a sequence to a variable
  • Where: filters the nodes
  • Order by: sorts the nodes
  • Return: what to return (gets evaluated once for every node)


Consider the following example that contains information about a bookstore.

We will use a FLOWR expression to retrieve the authors of these books with a price lower than 20.

<?xml version="1.0" encoding="UTF-8"?>

<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<book category="web">
<title lang="en">XQuery Tips</title>
<author>Tom Nolan</author>
<book category="web">
<title lang="en">Learn XML</title>
<author>Tutorial Reference</author>

And the following XQuery document contains the query expression to be executed on the above XML document:

let $books := (doc("books.xml")/bookstore/book)
return <results>
for $x in $books
where $x/price<20
order by $x/author
return $x/author

More in details:

  • The for clause selects all book elements under the bookstore element into a variable called $x.
  • The where clause selects only book elements with a price element with a value lower than 20.
  • The order by clause defines the sort-order. Will be sort by the author element.
  • The return clause specifies what should be returned. Here it returns the title elements.

The result of the XQuery expression above is:

<author>Tutorial Reference</author>

Table of Contents