我如何在我的 xpath 表达式中使用 AND 操作来查找文章和 inproceedings 文件夹中 pid=1234 的作者总数?
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);
?>
这是一个错误。请建议使用 AND 运算符的正确方法。
随便用(不需要的话可以去掉XPath的count()函数):
count(//author[@pid="1234"][parent::article or parent::inproceedings])
示例:https://dblp.org/pers/g/Gauthier:Fran=ccedil=ois.xml
count(//author[@pid="65/9612"][parent::article or parent::inproceedings])
结果:21
<?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);
?>
这是一个错误。请建议使用 AND 运算符的正确方法。
随便用(不需要的话可以去掉XPath的count()函数):
count(//author[@pid="1234"][parent::article or parent::inproceedings])
示例:https://dblp.org/pers/g/Gauthier:Fran=ccedil=ois.xml
count(//author[@pid="65/9612"][parent::article or parent::inproceedings])
结果:21