[xquery-talk] Adding content for with distinct-values

Jeni Tennison jeni at jenitennison.com
Thu Dec 9 21:57:30 PST 2004

Hi Bruno,

> I suspect using distinct-values and sum but do not succeed.

Indeed. Use distinct-values() to get the distinct values of the IDs,
then iterate over them with a for. Within the loop, locate the
elements with that ID, and then sum them together with the sum()
function. So something like:

let $counts := doc('test.xml')/*/dy:iu-count
for $value in distinct-values($counts/@ID)
  return <dy:iu-count ID="{$value}">
           { sum($counts[@ID = $value]) }



Jeni Tennison

More information about the talk mailing list