Simple XQuery FLWOR Expressions

The simplest XQuery FLWOR expression might be something like this:

This returns all of the video elements in $doc.

We can add a bit of substance by adding XQuery where and return clauses:

This returns all of the titles of videos released in 1999.

If you know SQL, that XQuery probably looks reassuringly similar to the equivalent SQL statement:

And if you know XPath, you might be wondering why our XQuery cannot be written as this:

Well, you can. This XPath expression is completely equivalent to the FLWOR expression above, and furthermore, it is a legal XQuery query. In fact, every legal XPath expression is also legal in XQuery. Thus the first query in this section can be written as:

 
Free Stylus Studio XML Training: