Question: I have this XML file, from which I'd like to count the number of users referenced in it. But they can appear in more than one category, and I'd like these duplicates not to be taken into account.  

In the example below, the query should return 3 and not 4. Is there a way in XPath to do so? Users are not sorted at all.

```
<list>
  <group name='QA'>
    <user name='name1'>name1@email</user>
    <user name='name2'>name2@email</user>
  </group>
  <group name='DEV'>
    <user name='name3'>name3@email</user>
    <user name='name2'>name2@email</user>
  </group>
</list>

```

Answer: 
Not sure if you could do it in XPath, but it could be done easily using System.Linq:

```
string xml = "<list><group name='QA'><user name='name1'>name1@email</user><user name='name2'>name2@email</user></group><group name='DEV'><user name='name3'>name3@email</user><user name='name2'>name2@email</user></group></list>";
        XElement xe = XElement.Parse(xml);
        int distinctCount = xe.Elements().Elements().Select(n => n.Value).Distinct().Count();

```

In this example, distinctCount will equal 3.
```
count(//user[not(./@name = preceding::user/@name)])

```

I think the best way is to try to draw your xml data on paper to see how you can solve it easily