Example of grouping and counting in XQuery
✓ Published0🌍 Public
CCliffordAnderson
Last edited Jul 28, 2017
Created on Jul 28, 2017
This example demonstrates how to group XML elements by an attribute value and count the grouped items using XQuery 3.1’s `group by` clause. It defines a small in-memory `<books>` dataset with five book titles categorized by `class` attributes (fiction or nonfiction). The query iterates over each `<book>`, extracts the text content as titles, and groups them by class, then returns a new element named after each class containing an ordered, numbered list of titles. The implementation relies on XQuery’s `element` constructor and `count` clause to generate the output, with titles sorted alphabetically using `order by`.
AI-generated description