0

查看文档,目标是从第一个表中的第二行中选择第二个单元格。

我创建了以下表达式:

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

但它不返回任何行。不幸的是,我看不出有什么问题。

对我来说,看起来还不错。表达式应该:

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

如果您能指出我做错了什么,我将不胜感激。

示例 XML 文档:

<?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

1 回答 1

4

乍一看,我认为您的意思是这样写:

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

奇怪的是,我在您的示例数据中没有看到任何符合所有三个条件的节点。

编辑:根据反馈,这是另一个可以尝试的查询。

//tr[td/@class="identifier"][td/span="identifier"]/td[2]/text()
于 2010-03-21T18:16:45.833 回答