XPath count()函数

Eme*_*men 16 xml xpath

假设我有一个XML树,如下所示:

proceedings
   -name
   -contents
      -article
         -author
         -title
         -pages
Run Code Online (Sandbox Code Playgroud)

如何识别只有一位作者的任何标题?有超过三位作者使用xpath的文章数量?

Fra*_*ila 41

与一位作者的标题:

/proceedings/contents/article[count(author)=1]/title
Run Code Online (Sandbox Code Playgroud)

拥有三位以上作者的文章数量:

count(/proceedings/contents/article[count(author)>3])
Run Code Online (Sandbox Code Playgroud)

  • 无论哪种方式,我都可以使用//指示孩子的父母。在这种情况下,`// article [count(author)= 1] / title`。非常感谢弗朗西斯! (2认同)