<grand id="grand">
<parent>
<child age="18" id="#not-grand"/>
<child age="20" id="#grand"/> <!-- This is what I want to locate -->
</parent>
</grand>
谁能告诉我如何表达找到第二个 child 吗?
这不起作用...
"/grand/parent/child[@id=concat('#',/grand/@id)]/@age"
谢谢。
<小时/>对不起。表情没问题。我发现我在其他区域遇到了一些问题,而不是表达式本身。
最佳答案
此 XPath 特定于您提供的代码片段。选择<child>
id 为 #grand
你可以写//child[@id='#grand']
.
获取年龄//child[@id='#grand']/@age
.
关于XPath 选择某个属性值等于其他节点属性值的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6055432/