基于父母兄弟姐妹的多个标准

时间:2013-09-12 20:10:09

标签: xpath

我想知道我是否可以同时组合一个XPath,查找具有特定文本的某个类的前一个兄弟,同时使用某个文本同时处理同级别的兄弟。

例如,我想找到以下单元格:

<td class="sdawatt_booknow"><a href="#" onclick="wa_class_book(160832)">Book</a></td>

通过查找包含文字sdawatt_hrdcell的{​​{1}}课程的同学,其中包含Spin的课程sdawatt_banner,文字为Monday - 16 September 2013

或以下td:

    <td class="sdawatt_booknow"><a href="#" onclick="wa_class_book(160864)">Book</a></td>

如果我们查找“星期五 - 2013年9月13日”的日期。

这在Xpath中是否可行?

<table cellspacing="0" cellpadding="0" border="0" style="border-collapse:collapse;" class="sdawatt_outer">
    <tbody><tr>
        <td class="sdawatt_hdrcell">Time</td>
        <td class="sdawatt_hdrcell">Class</td>
        <td class="sdawatt_hdrcell">Level</td>
        <td class="sdawatt_hdrcell">Spaces</td>
        <td class="sdawatt_hdrcell">Location</td>
        <td class="sdawatt_hdrcell">Instructors</td>
        <td class="sdawatt_hdrcell">Tags</td>
        <td class="sdawatt_hdrcell">Info</td>
        <td class="sdawatt_hdrcell">Book</td>
    </tr><tr>
        <td colspan="9" class="sdawatt_banner">Friday - 13 September 2013</td>
    </tr><tr class="sdawatt_classrow">
        <td class="sdawatt_time">07:45-08:15</td>
        <td class="sdawatt_classname">Boxing</td>
        <td class="sdawatt_level"> </td>
        <td class="sdawatt_spaces">14 Left</td>
        <td class="sdawatt_location">Main Studio</td>
        <td class="sdawatt_resources"> Darren</td>
        <td class=" sdawatt_infotags"></td>
        <td class="sdawatt_info"><img src="https://v4.fitnessandlifestylecentre.com/webaccess/TimetableView/information.gif" class="tiptip" /></td>
        <td class="sdawatt_booknow"><a href="#" onclick="wa_class_book(160848)">Book</a></td>
    </tr><tr class="sdawatt_classrow">
        <td class="sdawatt_time">12:00-12:45</td>
        <td class="sdawatt_classname">Spin</td>
        <td class="sdawatt_level"> </td>
        <td class="sdawatt_spaces">8 Left</td>
        <td class="sdawatt_location">Main Studio</td>
        <td class="sdawatt_resources"> Matt</td>
        <td class=" sdawatt_infotags"></td>
        <td class="sdawatt_info"><img src="https://v4.fitnessandlifestylecentre.com/webaccess/TimetableView/information.gif" class="tiptip" /></td>
        <td class="sdawatt_booknow"><a href="#" onclick="wa_class_book(160864)">Book</a></td>
    </tr><tr>
        <td colspan="9" class="sdawatt_banner">Monday - 16 September 2013</td>
    </tr><tr class="sdawatt_classrow">
        <td class="sdawatt_time">13:00-13:45</td>
        <td class="sdawatt_classname">Spin</td>
        <td class="sdawatt_level"> </td>
        <td class="sdawatt_spaces">12 Left</td>
        <td class="sdawatt_location">Main Studio</td>
        <td class="sdawatt_resources"> Marzena</td>
        <td class=" sdawatt_infotags"></td>
        <td class="sdawatt_info">
        <img src="https://v4.fitnessandlifestylecentre.com/webaccess/TimetableView/information.gif" class="tiptip" /></td>
            <td class="sdawatt_booknow"><a href="#" onclick="wa_class_book(160832)">Book</a></td>
    </tr>
</tbody></table>

1 个答案:

答案 0 :(得分:2)

//tr[
        contains(
            td[@class="sdawatt_banner"],
            "Monday - 16 September 2013")
    ]
    /following-sibling::tr[
                           contains(
                               td[@class="sdawatt_classname"],
                               "Spin")
                          ]/td[@class="sdawatt_booknow"]

产量

<td class="sdawatt_booknow">
  <a href="#" onclick="wa_class_book(160832)">Book</a>
</td>