It walks through a fairly simple, but common, type of document, where it's selecting a film based on references to actors. It starts off with an XPath example, culminating with this:
//video[actorRef=//actors/actor[ends-with(., 'Lisa')]/@id]/titleIt ends up with a far more suitable (and powerful) XQuery statement:
declare variable $firstName external;Finally, the article closes with a discussion of using XQuery with databases.
let $doc := .
for $v in $doc//video,
$a in $doc//actors/actor
where ends-with($a, 'Lisa')
and $v/actorRef = $a/@id
order by $v/year
If you've got a real database, however, the form of the queries won't need to change all that much from these examples. Instead of using the doc() function (or simply ".") to select a document, you're likely to call the collection() function to open a database, or a specific collection of documents within a database. The actual way collections are named is likely to vary from one database system to another. The result of the XQuery collection() function is a set of documents (more strictly, a sequence of documents, but the order is unlikely to matter), and you can process this using path expressions or FLWOR expressions in just the same way as you address a single document.XQuery is seen as a core part of the XML toolbox because of its much clearer syntax as compared to XPath, even though it uses XPath as a basis. (For example, the article shows exact equivalency between an XPath query and an XQuery query, with XPath as the expression and XQuery as a language construct, with some XPath-isms embedded.)
What do you think?