xpath - 如何比较xpath中的元素位置
问题描述
我正在尝试比较客户帐户值以仅显示不同的值并忽略 XPath 中的重复项:
XML 代码:
<info>
<Customer CustAccount="1"/>
<Customer CustAccount="2"/>
<Customer CustAccount="2"/>
<Customer CustAccount="3"/>
</info>
结果应比较客户 1/2/3 并显示:
customer 1
customer 2
customer 3
解决方案
您可以使用 XPath-2.0 表达式来实现这一点
for $c in distinct-values(/info/Customer/@CustAccount) return concat('customer ',$c,'
')
输出是:
customer 1
customer 2
customer 3
如果您不喜欢换行符,请

从表达式中删除。
没有纯粹的 XPath-1.0 表达式可以实现这一点;如果 XPath-2.0 不可用,您只能使用 XSLT-1.0 执行此操作。
推荐阅读
- c# - 按下回车键时转到下一个文本框
- python - 检查用户之前是否使用 Django 填写过问卷
- html - Angular中的ngx-color颜色选择器,无法设置宽度
- php - 覆盖 Codeigniter 4 中的默认 Myth\Auth 路由库
- python - 如何在 python 的特定场景中忽略 csv 分隔符?
- c - 使用命令行界面减少程序的代码?
- visual-studio-code - 如何在 vscode 的 Multi-root Workspaces 中获取活动工作区
- javascript - 当我保存方法的返回时,它保存未定义
- laravel-8 - Doctrine\DBAL\Driver\PDO\Exception SQLSTATE[28000] [1045] Access denied for user 我得到一个错误
- html - 如何为 tbody 中的所有表数据设置一个表头?