Combining the use of preceding and following sibling in the same xpath query

前端 未结 3 880
礼貌的吻别
礼貌的吻别 2020-12-08 08:16

I have a quite simple problem but i can\'t seem to resolve it. Let\'s say i have the following code:


    zyx
            


        
3条回答
  •  盖世英雄少女心
    2020-12-08 08:50

    XPath 1.0:

    /a/b[preceding-sibling::b/@property='p1' and following-sibling::b/@property='p2']
    

    XPath 2.0:
    The expression above has some quirks in XSLT 2.0, it is better to use the new and safer operators << (before) and >> (after).

    /a/b[../b[@property='p2'] << . and . >> ../b[@property='p1']]
    

提交回复
热议问题