A Final Example: Grouping

We conclude the chapter with an example that ties together most of the concepts that we've covered. Suppose we wish to display all articles for sale, grouped by seller. Listing 4.15 provides a query to do so.

Listing 4.15. Query to Display Articles for Sale, Grouped by Seller
 default element namespace = "http://www.example.com/auction" declare namespace x = "http://www.w3.org/1999/xhtml" let $auction := $input/auction return <x:html> <x:head><x:title>Items by Seller</x:title></x:head> <x:body> <x:h1>Items by seller</x:h1> { for $id in distinct-values ($auction/articles/article/seller/@idref) let $name := exactly-one($auction/users/user[@id = $id]/name) order by $name return <x:p>{ $name }</x:p> <x:table>{ for $article ...

Get XQuery from the Experts: A Guide to the W3C XML Query Language now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.