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?
The XPath count() method is used to count the number of nodes matching a given XpathExpression .
int product_count = driver. findElements(By. xpath("//id('product')/x:tbody/x:tr[1]")). size();
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.
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.
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])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With