比较一个元素的属性和另一个元素的属性 [英] Compare attribute of one element to attribute of another element
本文介绍了比较一个元素的属性和另一个元素的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这看起来应该很容易,但我永远弄不明白.
This seems like it should be easy, but I can never figure it out.
假设我有以下文件:
<data>
<a>
<b val="1"/>
</a>
<c val="1">
</data>
并假设我正在从 的上下文中执行 XPath.我需要检查是否存在与
b
具有相同值的元素 c
.
And assume that I am executing an XPath from the context of <b>
. I need to check if there is an element c
that has the same value as b
.
显然,这是行不通的:
../a/c[@val=@val]
如何让 XPath 在遍历树时记住它的当前"上下文?
How to I get an XPath to remember its "current" context when traversing the tree?
推荐答案
试试下面的表达式.您会注意到当前节点并没有丢失,因为谓词用于查找 c
节点.
Try the expression below. You'll notice that the current node is not lost since a predicate is used for finding the c
node.
.[../../c/@val=@val]
这篇关于比较一个元素的属性和另一个元素的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文