在Xpath中与众不同? [英] distinct in Xpath?

查看:61
本文介绍了在Xpath中与众不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个XML文件,我想从中计算引用的用户数。但是它们可以出现在多个类别中,并且我希望不要考虑这些重复项。

在下面的示例中,查询应返回3而不是4。 XPath这样做吗?

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>


推荐答案

纯XPath 1.0-班轮

使用

count(/ * / group / user [not(。= ../ following-sibling :: group / user)])

这篇关于在Xpath中与众不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆