Xpath 用于获取节点名称的唯一值 [英] Xpath for getting unique values of node names

查看:30
本文介绍了Xpath 用于获取节点名称的唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 XML:

<MyFruits>
   <Apple>A</Apple>
   <Apple>19</Apple>
   <Mango>12</Mango>
   <Apple>19</Apple>
   <Orange>A</Orange>
   <Orange>A</Orange>
   <Orange>A</Orange>
   <Apple>B</Apple>
   <Apple>19</Apple>
   <Mango>12</Mango>
   <Apple>19</Apple>
   <Orange>10</Orange>
   <Apple>19</Apple>
   <Orange>10</Orange>
   <Apple>C</Apple>
   <Apple>19</Apple>
   <Mango>12</Mango>
   <Apple>19</Apple>
   <Orange>10</Orange>
   <Apple>19</Apple>
   <Orange>10</Orange>
</MyFruits>

我只想得到其中唯一的水果(苹果、芒果和橙子)

I want to get only unique fruits among them (Apple,Mango and Orange)

有人可以建议使用 XPath 1.0 检索 XPath 吗?

Can anyone suggest an XPath to retrieve using XPath 1.0?

谢谢

推荐答案

我不认为这可以在单个 XPath 1.0 表达式中完成,因为它需要两个嵌套的谓词级别,内部级别取决于外层,即

I don't think this can be done in a single XPath 1.0 expression because it would require two nested levels of predicates with the inner one depending on the value of the outer one, i.e.

/MyFruits/*[not(preceding-sibling::*[name() = name(node-from-outer-predicate)])]

这在 XPath 1.0 中是不可能的.

and this isn't possible in XPath 1.0.

这在 XPath 2.0 中是微不足道的

It would be trivial in XPath 2.0

distinct-values(/MyFruits/*/name())

这篇关于Xpath 用于获取节点名称的唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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