views:

69

answers:

1

Looking at the document, the goal is to select the second cell from the second row, in the first table.

I've created the following expression:

//row/td[2]/text()[td[@class="identifier"]/span[text()="identifier"]]

but it does not return any rows. Unfortunately I do not see what's wrong.

To me, it looks alright. The expression should:

select the text
    in the second cell 
        in any row
where
    the text of a span equals to "identifier"
        and the span is located in cell with a "identifier" class

I'd appreciate it if you could point out what I'm doing wrong.

Sample XML document:

<?xml version="1.0"?>
<html>
    <table class="first">
        <tr>
            <td>row 1, cell 1</td>
            <td>row 1, cell 2</td>
        </tr>
        <tr>
            <td class="identifier">
                <span>identifier</span>
            </td>
            <td>
                foo
                <span>ignore</span>
                bar
            </td>
        </tr>
        <tr>
            <td>row 3, cell 1</td>
            <td>row 3, cell 2</td>
        </tr>
    </table>

    <table class="second">
        <tr>
            <td>row 1, cell 1</td>
            <td>row 1, cell 2</td>
        </tr>
        <tr>
            <td class="identifier">
                <span>not an identifier</span>
            </td>
            <td>
                not a target
            </td>
        </tr>
        <tr>
            <td>row 3, cell 1</td>
            <td>row 3, cell 2</td>
        </tr>
    </table>
</html>
+4  A: 

Just at first glance, I think you mean to write:

//tr/td[2][@class="identifier"][span="identifier"]

The odd thing is I don't see any nodes in your sample data that match all three conditions.

EDIT: Based on feedback, here's another query to try.

//tr[td/@class="identifier"][td/span="identifier"]/td[2]/text()
Jweede
No, I don't think so.The markup has a key/value-like structure but the culprit is that the classname of the cell is not the key, the content of the span in the first cell is.
Adam Asham
so the `@class` attribute covers the whole row, even though it's only in the first cell?
Jweede
With your update I get expected results. Many thanks! :)
Adam Asham