tags:

views:

32

answers:

2

What happens when I apply following-sibling::*[1] to the last child?

A: 

It will get you the first sibling to the current node.

Here is an example:

<Root>
   <Div id="Hey">
      Test1
   </Div>
   <Div>
      Test2
   </Div>
   <Div>
      Test3
   </Div>
</Root>

XPath:

/Root/Div[@id = 'Hey']/following-sibling::*[1]

/Root/Div[@id = 'Hey'] will get you the Div with id=Hey and /following-sibling::*[1] will then get you the first sibling so in total you would get the Div with the text "Test2".

Update: I apologize (see comment), but this: /Root/Div[3]/following-sibling::*[1] will just return a empty list. (Div[3] is the last child)

lasseespeholt
**-1** The question asked what it did when applied to the _last_ child
Eric
See my update :-)
lasseespeholt
+1  A: 

What happens when I apply following-sibling::*[1] to the last child?

Answer: it gets evaluate to an empty node-set, because there is no more following siblings.

If you want to get the following sibling of the context node or following sibling of context node parent otherwise, the rigth axis is following, as in:

following::*[1]
Alejandro