1

If I have this xml structure:

<tr>
    <td class="name">
        <b>Brand</b>
    </td>
    <td class="desc">Intel</td>
</tr>
<tr>
    <td class="name">
        <b>Series</b>
    </td>
    <td class="desc">Core i5</td>
</tr>
<tr>
    <td class="name">
        <b>Cores</b>
    </td>
    <td class="desc">4</td>
</tr>

How can I get the "desc" value when name == Series?

I've followed another example here How to select following sibling/xml tag using xpath

However, that example did not have the tags around the "name" value so following-sibling doesn't work at the level. How do I go back a level to the level?

Community
  • 1
  • 1
Dss
  • 1,687
  • 1
  • 20
  • 25

1 Answers1

2

You don't need the sibling axis for this.

This XPath,

string(//tr[normalize-space(td[@class='name'])='Series']/td[@class='desc'])

will select

Core i5

for your XML, as requested.

kjhughes
  • 89,675
  • 16
  • 141
  • 199
  • Thank you! I was not aware it could be done this way. Does this also handle the tag? I don't see reference to it. – Dss Nov 29 '16 at 18:35
  • Yes, it will handle any `b`, `i`, etc automatically because it tests the string value of the element rather than testing text nodes. See [**Testing text() nodes vs string values in XPath**](http://stackoverflow.com/questions/34593753/testing-text-nodes-vs-string-values-in-xpath) for details. – kjhughes Nov 29 '16 at 19:47