I have this XML:
<doc>
<target>
<name>V1</name>
<value>3</value>
<more>foo</more>
</target>
<target>
<name>V3</name>
<value>5</value>
<more>bar</more>
</target>
<var>
<name>V1</name>
<value>3</value>
</var>
<var>
<name>V2</name>
<value>3</value>
</var>
</doc>
I want an XPath query that returns all target nodes where there exists a var node with whose name and value nodes match those specified in the target. In the example above, there should be no matches.
My attempts at a query look something like this:
//target[//var/name=name and //var/value=value]
This query returns the first target node because there exists a variable V1, and there exists a variable whose value is 3. But this is not what I am after; I only want matches where the name and the value of the same variable match the target.
I'm using XPath 1.0, so techniques to accomplish this with that version would be most helpful.
Note: Question updated to revise sample XML.