Friday, July 31, 2009

Unique Attribute Values Across Multiple Documents using XQuery

It's a little slow, but here's one way to get a list of all the unique attribute values across multiple XML documents using XQuery.

let $raw-values :=
for $book in collection("abc")/(gbook|set)[@type='oeb']
element { "book" }
for $value in distinct-values($book//node()/@class)
return element { "class" } { $value }
for $item in distinct-values($raw-values//class)
order by $item
return element { "uniques" } { $item }

No comments: