xml - 计算 XPath 1.0 中的不同内容

标签 xml xslt xpath xpath-1.0

给定以下 XML

<Address>
 <CountryName>France</CountryName>
</Address>
...
<Address>
 <CountryName>Germany</CountryName>
</Address>
...
<Address>
 <CountryName>Spain</CountryName>
</Address>

如何计算使用 XPath 1.0 的不同国家/地区的数量?

地址列表很长,包含许多不同的国家/地区,因此我不想一一列举。

最佳答案

选择所有 CountryName 元素的值与作为当前 CountryName 子元素的 CountryName 元素值不同的计数元素的父元素的以下兄弟元素是 Address 元素:

count(//Address/CountryName[not(.=../following-sibling::Address/CountryName)])

关于xml - 计算 XPath 1.0 中的不同内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24026461/

相关文章:

xml - 在内存中的 XQuery 中多次编辑同一个文档节点

XML 错误 - 格式不正确

xslt - 如何在xslt子字符串函数中转义单引号

c# - FPML 计算

xml - 检查节点集是否包含 XSLT 中的任何值

java - 无法使用 XPath 获取 XML 的节点值

xml - 寻找 "CC130"的 XPath 函数

c# - 通过 TCP 发送长 XML

android - xmlns :android ="http://schemas.android.com/apk/res/android" this line is marked as error in Linear Layout

xml - Xpath 通配符只返回第一个元素