使用 xpath 获取节点的第 N 个子节点 [英] Get Nth child of a node using xpath
本文介绍了使用 xpath 获取节点的第 N 个子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的示例输入 XML 是:
My sample input XML is:
<root>
<a>
<b>item</b>
<b>item1</b>
<b>item2</b>
<b>item3</b>
<b>item4</b>
</a>
</root>
我假设选择一个节点b
,其位置是一个变量的值.
I am suppose to select a node b
whose position is the value of a variable.
如何使用变量的值来测试节点的位置?
How can I use the value of a variable to test the position of a node?
推荐答案
你可以使用这个:
/root/a/b[position()=$variable]
position() 基于 1
position() is 1 based
http://saxon.sourceforge.net/saxon6.5.3/expressions.html
这篇关于使用 xpath 获取节点的第 N 个子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文