xpath parent attribute of selection

前端 未结 3 810
不思量自难忘°
不思量自难忘° 2021-02-06 19:26

Syntax of the xml document:


  
    Z 
    Z__2
    Z__3   
           


        
3条回答
  •  有刺的猬
    2021-02-06 19:33

    I dont have a reputation, so I cannot add comment to accepted answer by Blender. But his answer will not work in general. Correct version is

    //x[.//z]/@name
    

    Explanation is simple - when you use filter like [//z] it will search for 'z' in global context, i.e. it returns true if xml contains at least one node z anywhere in xml. For example, it will select both names from xml below:

    
      
      
      
         
            Z 
            Z__2
            Z__3   
         
      
    
    

    Filter [.//z] use context of current node (.) which is xand return only 2nd name.

提交回复
热议问题