XPath count() function

2020-02-10 02:37发布

问题:

Suppose I have an XML tree as below:

proceedings
   -name
   -contents
      -article
         -author
         -title
         -pages

How can I identify any title that has only one author? And the number of articles that have more than three author using xpath?

回答1:

Title with one author:

/proceedings/contents/article[count(author)=1]/title

Number of articles with more than three authors:

count(/proceedings/contents/article[count(author)>3])


标签: xml xpath