25.12.2013 Views

Tamino XQuery User Guide - Software AG Documentation

Tamino XQuery User Guide - Software AG Documentation

Tamino XQuery User Guide - Software AG Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

FLWOR Expressions<br />

13<br />

14<br />

23<br />

24<br />

If there are for and let clauses in the FLWOR expression then the variable bindings created by<br />

the let clause are added to the tuples created by the for clause.<br />

The where Clause<br />

By using the where clause you can define conditions that previously generated tuples must satisfy.<br />

If the condition is met, the tuple is retained, if not, the tuple is discarded. It depends on the effective<br />

boolean value of the expression in the where clause, whether tuples will be retained or not. For<br />

the remaining tuples all variable bindings are still valid so that they can be used in the return<br />

clause.<br />

A where clause can simply act as a filter and then represents a more verbose form of a path expression<br />

using a predicate. The query expressions<br />

input()/bib/book[@year < 2000]/title<br />

and<br />

for $a in input()/bib/book<br />

where $a/@year < 2000<br />

return $a/title<br />

are equivalent: Both return the titles of books that have been published before 2000. They differ<br />

in that the path expression additionally performs sorting in document order and elimination of<br />

duplicates according to node identity. Therefore it is not necessary to use the FLWOR expression<br />

here.<br />

But you can use where clauses for more than defining predicates in path expressions. For example,<br />

they are necessary in defining a join criterion:<br />

for $b in input()/bib/book,<br />

$a in input()/reviews/entry<br />

where $b/title = $a/title<br />

return<br />

<br />

{ $b/author }<br />

{ $b/title }<br />

{ $a/review }<br />

<br />

See also the section Joining for a short explanation of this example.<br />

<strong>XQuery</strong> <strong>User</strong> <strong>Guide</strong><br />

35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!