XPath : select all following siblings until another sibling

前端 未结 3 1166
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 05:54

Here is an excerpt of my xml :



content





        
3条回答
  •  渐次进展
    2020-11-27 06:14

    You could do it this way:

    ../node[not(text()) and preceding-sibling::node[@id][1][@id='1']]
    

    where '1' is the id of the current node (generate the expression dynamically).

    The expression says:

    • from the current context go to the parent
    • select those child nodes that
    • have no text and
    • from all "preceding sibling nodes that have an id" the first one must have an id of 1

    If you are in XSLT you can select from the following-sibling axis because you can use the current() function:

    
    
      
    
    

    or simpler (and more efficient) with a key:

    
    
    
    

提交回复
热议问题