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 />
Building upon the FLWOR expression from the last example, we modified the return clause:<br />
return<br />
<br />
{ string($y) } <br />
{ $b/title }<br />
<br />
The year of publication is now the contents of the new element year. As the expression $b/@year<br />
represents an attribute node, we need to turn its value into a string by applying the function<br />
string().<br />
sort by (title)<br />
All book elements are sorted by their child element title in ascending order. The FLWOR expression<br />
evaluates to a sequence of items and determines the context node for sort by (<strong>XQuery</strong> calls<br />
this evaluation context inner focus). These input items are then reordered according to the sort<br />
criterion and returned as a sequence of output items. As book is the context node for each input<br />
item, the result is a sequence of book elements sorted alphabetically by title in the default order,<br />
which is ascending.<br />
An alternative version of this query is:<br />
for $b in input()/bib/book<br />
let $y := $b/@year<br />
where $y > 1991<br />
return<br />
<br />
{ string($y) } <br />
{ $b/title }<br />
<br />
sort by (title)<br />
Putting the sort at the end of the for clause has the advantage that the data type of title is retained<br />
and the query can be optimized, while newly constructed nodes have no type information.<br />
See SortExpr and fn:string in the language reference for details.<br />
<strong>XQuery</strong> <strong>User</strong> <strong>Guide</strong><br />
13