Skip to main content
100%

Order by & Group by in XQuery

✓ Published0🌍 Public
CCliffordAnderson
Last edited Feb 18, 2015
Created on Feb 18, 2015

This example demonstrates how XQuery’s `order by` and `group by` clauses transform an XML book list into grouped output. It shows the difference between sorting titles alphabetically and then grouping them by their `class` attribute, so fiction and nonfiction categories each contain their titles in order. The code defines a `books` element with five `book` children, then iterates with a `for` loop, assigns the text and class via `let`, sorts by title, and groups by class. The result returns the class followed by its titles, revealing how grouping interacts with pre-sorting. No external libraries are used, only the XQuery language’s core expressions.

AI-generated description

Similar vizzes