开发者

XPath to find element based on another XPath element

开发者 https://www.devze.com 2022-12-24 19:40 出处:网络
I have an Java AST and I try to find a variable inside it via XPath. Lets say the variable is called \'foobar\' I could use

I have an Java AST and I try to find a variable inside it via XPath.

Lets say the variable is called 'foobar' I could use

开发者_开发知识库
//VariableDeclarator/VariableDeclaratorId[@Image='foobar']

but what if I dont know the text 'foobar', but want to read it from another element

//VariableDeclarator/VariableDeclaratorId[@Image=//SynchronizedStatement/Expression/PrimaryExpression/PrimaryPrefix/Name]

the 'Name' node has the information 'foobar' in @Image, but PrimaryPrefix/Name[@Image] does not work.

How must I rewrite the condition //SynchronizedStatement/Expression/PrimaryExpression/PrimaryPrefix/Name that it is the same as @Image='foobar' ?

Thanks


Try this XPath:-

//VariableDeclarator/VariableDeclaratorId[@Image=//SynchronizedStatement/Expression/PrimaryExpression/PrimaryPrefix/Name/@Image]
0

精彩评论

暂无评论...
验证码 换一张
取 消