XPath to find element based on another XPath element

Posted by martymcfly on Stack Overflow See other posts from Stack Overflow or by martymcfly
Published on 2010-03-25T09:33:53Z Indexed on 2010/03/25 9:43 UTC
Read the original article Hit count: 768

Filed under:
|
|
|

Hi,

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

© Stack Overflow or respective owner

Related posts about xpath

Related posts about java