I have a table with multiple rows, and I’m trying to use an xpath to find the one row that contains specific values in each column. For example, I expect “foo” in column 1, “bar” in column 2, and “baz” in column 3.
What xpath could I use to get a row that contains those three specific values in those specific columns?
For example, given the following table I want to be able to get back only the one row with the three expected values in their expected columns
<table>
<tr><td>foo</td><td>bar</td><td>xxx</td></tr>
<tr><td>xxx</td><td>bar</td><td>baz</td></tr>
<tr><td>foo</td><td>bar</td><td>baz</td></tr>
<tr><td>bar</td><td>baz</td><td>foo</td></tr>
<tr><td>foo</td><td>xxx</td><td>baz</td></tr>
</table>
This does the trick (assuming the
tableelement is the current context node):td[1]selects the firsttdchild,td[2]the second, etc. Then you combine the conditions withand.