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 document("http://www.bn.com/bib.xml")//book[author]
RETURN
<book>
$b/title,
$b/author
</book>,
FOR $b IN document("http://www.bn.com/bib.xml")//book[editor]
RETURN
<reference>
$b/title,
<org> $b/editor/affiliation/text() </org>
</reference>
</bib>
Adapted from XML Query Use Cases