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

前端 未结 3 776
礼貌的吻别
礼貌的吻别 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:37

    You can combine the tests in the predicate using and.

    0 讨论(0)
  • 2020-12-08 08:47

    Also, this XPath 1.0:

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

    Note: Don't use // as first step. Whenever you can replace and operator by predicates, do it.

    In XPath 2.0:

    /a/b[. >> ../b[@property='p1']][../b[@property='p2'] >> .]
    
    0 讨论(0)
  • 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']]
    
    0 讨论(0)
提交回复
热议问题