XML xpath, get the parent element till a specific element

后端 未结 2 1663
半阙折子戏
半阙折子戏 2021-02-01 15:40

I\'m looking for the right xpath syntax to get a specific parent of an element. Example:

root
   |- div
   |     |
   |     |----??? ---|
   |     |           |-         


        
2条回答
  •  逝去的感伤
    2021-02-01 16:05

    Use:

    /root/div[.//a[@class='1']]/text()
    

    This selects any text node that is a child of any a element that has a class attribute with value '1' and that (the a element) is a descendent of any div element that is a child of the top element named root.

提交回复
热议问题