Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Nth child of a node using xpath

Tags:

xml

xpath

My sample input XML is:

<root>  <a>    <b>item</b>    <b>item1</b>    <b>item2</b>    <b>item3</b>    <b>item4</b>  </a> </root> 

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?

like image 897
IordanTanev Avatar asked Mar 09 '10 09:03

IordanTanev


People also ask

How do I select the first child in XPath?

The key part of this XPath is *[1] , which will select the node value of the first child of Department .


1 Answers

you can use this:

/root/a/b[position()=$variable] 

position() is 1 based

http://saxon.sourceforge.net/saxon6.5.3/expressions.html

like image 76
remi bourgarel Avatar answered Oct 01 '22 22:10

remi bourgarel