[xquery-talk] attribute names and their distinct values

Michael Kay mhk at mhk.me.uk
Thu May 25 14:24:08 PDT 2006


> can i get the name of all attributes in each path $p and get 
> the count of their distint values to produce it as the 
> summary produced on leaf nodes

I assume by attributes "in a path", you mean the attributes of the elements
on the ancestor-or-self axis of a node, that is

$node/ancestor-or-self::*/@*

You can get the names of these attributes as

$node/ancestor-or-self::*/@*/node-name()

and you can eliminate duplicates using

distinct-values($node/ancestor-or-self::*/@*/node-name())

You can get the distinct values for each attribute name using

for $a in
distinct-values($node/ancestor-or-self::*/@*/node-name())
return distinct-values($node/ancestor-or-self::*/@*[node-name() eq $a])

but at this stage I suspect I'm guessing wildly at what you actually want to
achieve.

Michael Kay
http://www.saxonica.com/



More information about the talk mailing list