Tamino XQuery User Guide - Software AG Documentation
Tamino XQuery User Guide - Software AG Documentation
Tamino XQuery User Guide - Software AG Documentation
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Query Examples<br />
Explanation<br />
Again, a FLWOR expression is used in the query, but this time there is an additional where clause:<br />
where $b/@year > 1994<br />
It restricts the bindings to the variable $b to those that meet the condition in the expression following<br />
the keyword where: Only those book elements are retained that have an attribute year whose numerical<br />
value is greater than 1994. So it has the same effect as the WHERE clause in SQL.<br />
return<br />
<br />
{ $b/@year }<br />
{ $b/title }<br />
<br />
An element constructor is used that creates a new element book which is then filled by two enclosed<br />
expressions: the first one evaluates to an attribute that is attached to the element book, the second<br />
expression is used as before.<br />
You could also introduce an additional variable that is bound to the attribute year by using the<br />
let clause. The query then reads:<br />
for $b in input()/bib/book<br />
let $y := $b/@year<br />
where $y > 1994<br />
return<br />
<br />
{ $y }<br />
{ $b/title }<br />
<br />
The let clause adds an additional binding so that you can refer to $y instead of referring to<br />
$b/@year.<br />
See FLWORExpr in the language reference for details.<br />
Note: Although a sequence of book elements is not a well-formed XML element by itself,<br />
the resulting node sequence is serialized by <strong>Tamino</strong> into an xq:result node, which is in<br />
itself a new well-formed XML document.<br />
<strong>XQuery</strong> <strong>User</strong> <strong>Guide</strong><br />
11