tags:

views:

322

answers:

2

Hi,
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 to use the value of variable to test the position of a node?

Best Reagards,
Iordan

+6  A: 

you can use this:

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

position() is 1 based

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

remi bourgarel
+2  A: 

The following should work:

/root/a/b[2]

And if it doesn't, try:

/root/a/b[position()=2]
Ronald Wildenberg