Xml 是否可以转义当前XPath谓词以从包含的谓词中获取值?

Xml 是否可以转义当前XPath谓词以从包含的谓词中获取值?,xml,xpath,Xml,Xpath,这将通过一个例子得到最好的说明: 我正在寻找一个主前缀名称,其祖先包含名称中带有搜索键的内容,这很有效 //PrimaryExpression/PrimaryPrefix/Name [ ancestor::MethodDeclaration//Something/Something[contains(@Image,'SEARCH_KEY')] ] 现在有没有办法将SEARCH_KEY作为Name元素的Image属性?在XPath 1.0中,无法定义和引用范围变量 在XPath 2.0

这将通过一个例子得到最好的说明:

我正在寻找一个主前缀名称,其祖先包含名称中带有搜索键的内容,这很有效

//PrimaryExpression/PrimaryPrefix/Name [
    ancestor::MethodDeclaration//Something/Something[contains(@Image,'SEARCH_KEY')]

]

现在有没有办法将SEARCH_KEY作为Name元素的Image属性?

在XPath 1.0中,无法定义和引用范围变量

在XPath 2.0中,可以使用这样的

//PrimaryExpression
  /PrimaryPrefix
     /Name 
       [for $key in @someNameAttrib 
         return
            ancestor::MethodDeclaration
                       //Something/Something
                         [contains(@Image, $key)]  
       ]