tags:

views:

135

answers:

2

Consider the following html fragment:

<table>
  <tr>
    <td>One</td><td>1</td>
    <td>Two</td><td>2</td>
  </tr>
</table>

I want to use xpath to find the second td ("1" or "2") based on the value of the first td ("One" or "Two). Something like:

/table/tr/td[text() = 'One']/../td

or

/table/tr/td[text(), 'One']/../td

Any ideas?

+1  A: 

following-sibling::td?

brian
How do I specify limiting the path to the <td> who's value is "One"? It's not the sibling that's the issue; it's finding the td with a value of "One". Any chance you could give me an example of the entire xpath expression?
Todd R
see AakashM's response. Although I don't think you need to specify the position in this case. And if you decide to, I'd use position() and not [].
brian
+2  A: 

/table/tr/td[text()='One']/following-sibling::td[1]

"The first td following-sibling of a td node with text One"

AakashM