Selecting siblings between two nodes using XPath

前端 未结 2 1596
梦毁少年i
梦毁少年i 2020-12-02 11:49

How would I select all the tables between the table whose id is header_completed and the first table after the header_completed one that has an align of center? Here is the

2条回答
  •  广开言路
    2020-12-02 12:13

    I believe this XPath expression selects the nodes you want:

    //table[@class="header_completed"]/
        following-sibling::table[@align="center"][1]/
            preceding-sibling::table[
                preceding-sibling::table[@class="header_completed"]
            ]
    

    First I navigate to the table with @class="header_completed".

    From there I select the first following sibling table with @align="center".

    From there I select all preceding sibling tables that have a preceding sibling which is the table with @class="header_completed".

提交回复
热议问题