XML is like
<a id="1">
<b>value1</b>
<b>value2</b>
</a>
I want to write XPath to find id of <a> where there will be two <b> child nodes having fix value value1 and value2. I tried to to find out XPath with condition like
$xml->xpath('*[b=value1] | *[b=value2]');
value1 and value2 are present in <b> node, but I can not get exactly as I am using XPath first time.
The following XPath,
//a[b = 'value1' and b = 'value2']/@id
will select id attributes of all a elements with a child b element having string value equal to value1 AND another child b element having string value equal to value2 as requested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With