For each author in the bibliography, list the author's name and the titles of
all books by that author, grouped inside a result
element.
<results>
{
FOR $a IN distinct(document("bib.xml")//author)
RETURN
<result>
{ $a }
{ FOR $b IN document("bib.xml")/bib/book[author=$a]
RETURN $b/title
}
</result>
}
</results>
Adapted from XML Query Use Cases