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 table
element is the current context node):
tr[(td[1] = 'foo') and (td[2] = 'bar') and (td[3] = 'baz')]
td[1]
selects the first td
child, td[2]
the second, etc. Then you combine the conditions with and
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With