Is it possible to escape the current XPath predicate to get the value from the containing predicate?

This will be best illustrated with an example:

I am looking for the name of a primary prefix with an ancestor that contains something with SEARCH_KEY in the name, this works well.

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

Now, is there a way to SEARCH_KEY as the Image property of the Name element?

+4
source share
1 answer

In XPath 1.0, it is not possible to define and refer to range variables .

In XPath 2.0, you can use the for statement, for example :

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

Source: https://habr.com/ru/post/1394068/


All Articles