[xquery-talk] XQuery Style Conventions

Michael Kay mhk at mhk.me.uk
Sat Oct 29 10:30:20 PDT 2005

> > As all for and let clauses simply add another variable and 
> are equal is that respect [...]

I think it depends on whether one thinks of multiple "for" clauses as
representing nested loops, or as a join construct. People coming from a SQL
background may find it natural to think of it as a join, but in many cases I
think the mental model of nested loops is easier, especially when the inner
"for" clause has a dependency on the outer one.

To be honest, I rarely use multiple "for" clauses in a single FLOWR
expression. Usually I find that each level of iteration is producing some

for $b in //books
     for $a in $b/author

or if it really is a join, I tend from years of XPath practice to express it
within a predicate:

let $p := //publisher[country=$param]
for $b in //books[publisher = $p/name]
return ...

Michael Kay

More information about the talk mailing list