(: Build a portfolio of paper titles per author. Report the list of authors who have more than one paper. Over bibliography.xml. parke godfrey 2013-11-05, revised 2013-11-06 This demonstrates that we can store the XML-reults of one query and use that as the source for another query. So the first query is like a sub-query in the overall. This offers compositionality like in SQL, and makes XQuery quite powerful. The main query, bigwig, uses an aggregation, "count". LET assigns the node, node-list, or value of the RHS to the variable. If it is a node-list, then the variable references the whole list. We can still ask about properties about the list, like count. If the value is printed, the list is joined with "space" as the join character into a string. Notice we still have our duplicate problem... :) { let $portfolios := { for $author in doc("bibliography.xml")//author order by $author return { for $paper at $i in doc("bibliography.xml") //paper[.//author = $author] let $title := $paper/title/text() let $session := $paper/..[name() = 'session']/@name return if (empty($session)) then ( {$title} ) else ( {$title} ) } } for $author in $portfolios/portfolio let $number := $author/title where count($number) > 1 return {$author/@author/data()} }