For each book with an author, return a
book
with its title and authors. For
each book with an editor, return a
reference
with the book title and the
editor's affiliation.
<bib>
{
for $b in doc("bib.xml")//book[author]
return
<book>
{ $b/title }
{ $b/author }
</book>,
for $b in doc("bib.xml")//book[editor]
return
<reference>
{ $b/title }
<org> { $b/editor/affiliation/text() } </org>
</reference>
}
</bib>
Adapted from XML Query Use Cases