Search code examples
phpxmlxpathdomdocument

How can i use AND operation in my xpath expression to find total number of authors having pid=1234 in both article and inproceedings folder?


<?php

$xmlDoc = new DomDocument();
$xmlDoc -> load("books.xml");


$xpath = new DOMXpath($xmlDoc);
$elements = $xpath->evaluate("//dblpperson/r/**article**/author[@pid = '1234']" | "//dblpperson/r/**inproceedings**/author[@pid = '1234']" );

echo count($elements);

?>

This is giving an error. Please suggest the correct way to use AND operator.


Solution

  • Just use (you can remove the XPath count () function if you don't want it) :

    count(//author[@pid="1234"][parent::article or parent::inproceedings])
    

    Example with : https://dblp.org/pers/g/Gauthier:Fran=ccedil=ois.xml

    count(//author[@pid="65/9612"][parent::article or parent::inproceedings])
    

    Result : 21