这将通过一个例子得到最好的说明: 我正在寻找一个主要前缀名称,其祖先包含名称中包含SEARCH_KEY的内容,这很有效. //PrimaryExpression/PrimaryPrefix/Name [ ancestor::MethodDeclaration//Something/Somethi
          我正在寻找一个主要前缀名称,其祖先包含名称中包含SEARCH_KEY的内容,这很有效.
//PrimaryExpression/PrimaryPrefix/Name [
    ancestor::MethodDeclaration//Something/Something[contains(@Image,'SEARCH_KEY')]
] 
 现在有没有办法让SEARCH_KEY成为Name元素的Image属性?
在XPath 1.0中,无法定义和引用范围变量.在XPath 2.0中,可以像这样使用for expression:
//PrimaryExpression
  /PrimaryPrefix
     /Name 
       [for $key in @someNameAttrib 
         return
            ancestor::MethodDeclaration
                       //Something/Something
                         [contains(@Image, $key)]  
       ]
        
             