How to use AND operator in XPath?

16,634

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.

Share:
16,634
hrishi
Author by

hrishi

Updated on July 28, 2022

Comments

  • hrishi
    hrishi almost 2 years

    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.