Groups | Blog | Home
all groups > dotnet xml > august 2004 >

dotnet xml : XPath: counting unique values


Jo Goos
8/26/2004 2:39:06 AM
Hello,

I would like to count the unique values of a specific element in an XPath
statement.
Let's say I have the next XML document ...

<CLUB>
<MEMBER>
<NAME>Fred</NAME>
<LOCATION>Canada</LOCATION>
</MEMBER>
<MEMBER>
<NAME>Louis</NAME>
<LOCATION>Belgium</LOCATION>
</MEMBER>
<MEMBER>
<NAME>Gwendy</NAME>
<LOCATION>Belgium</LOCATION>
</MEMBER>
<MEMBER>
<NAME>Steve</NAME>
<LOCATION>Portugal</LOCATION>
</MEMBER>
</CLUB>

.... and I want to count the unique <LOCATION> elements.
In this case, it should be 3

Can this be done in a XPath statement?

Kind regards,
Oleg Tkachenko [MVP]
8/26/2004 1:23:23 PM
[quoted text, click to view]

count(/CLUB/MEMBER/LOCATION[not(. = ../preceding-sibling::MEMBER/LOCATION)])

or

count(set:distinct(/CLUB/MEMBER/LOCATION))
when using EXSLT.NET.

--
Oleg Tkachenko [XML MVP]
AddThis Social Bookmark Button