a sample of xml document:
<xml>
<list>
<item refid="1" />
<item refid="3" />
</list>
<catalogue>
<model id="1"><details /></model>
<model id="2"><details /></model>
<model id="3"><details /></model>
</catalogue>
</xml>
I’d like to query something like //model[ @id = (//item/@refid) ]
to obtain all “model” having a referenced id in “list”
The main problem here is your lack of confidence and not actually running an XPath engine to evaluate the expressions you’ve come up with.
If you evaluate the XPath expression you proposed:
You’ll see that it selects exactly the (two)
modelelements, whoseidattributes are referenced by therefidattributes ofitemelements that are children oflist.@Jörn-Horstmann in his answer already explained why you get these results.
A minor remark is to generally avoid using the
//abbreviation. It causes the whole document to be scanned and is very inefficient. In this case I would use the equivalent but probably faster to evaluate XPath expression: