In the document "prices.xml", find the minimum price for each book, in the
form of a minprice
element with the book title as its
title
attribute.
<results>
LET $doc := document("prices.xml")
FOR $t IN distinct($doc/book/title)
LET $p := $doc/book[title = $t]/price
RETURN
<minprice title = $t/text()>
min($p)
</minprice>
</results>
Adapted from XML Query Use Cases