O'Reilly logo

XQuery from the Experts: A Guide to the W3C XML Query Language by Philip Wadler, Jim Tivy, Jérôme Siméon, Michael Rys, Jonathan Robie, Michael Kay, Mary Fernández, Denise Draper, Don Chamberlin, Howard Katz - Editor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required