Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath count() function

Tags:

xml

xpath

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?

like image 232
emen Avatar asked Apr 16 '12 15:04

emen


People also ask

What is count in XPath?

The XPath count() method is used to count the number of nodes matching a given XpathExpression .

How do you find the XPath count?

int product_count = driver. findElements(By. xpath("//id('product')/x:tbody/x:tr[1]")). size();

What is XPath function?

XPath can be used to navigate through elements and attributes in an XML document. XPath is a syntax for defining parts of an XML document. XPath uses path expressions to navigate in XML documents. XPath contains a library of standard functions. XPath is a major element in XSLT and in XQuery.

How can I get distinct values in XPath?

distinct-values() is available in XPath 2.0. Are you using that? If distinct-values() is not available, the standard way of getting distinct values is to use not(@result = preceding:: @result) to get unique @result. It will give you the first occurrence only.


1 Answers

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]) 
like image 62
Francis Avila Avatar answered Sep 23 '22 17:09

Francis Avila