Thursday, January 29, 2015

XPath for the node with maximum value for a particular element : XPath1.0

Here is the list of bond characters played in bond movies and their earnings from movies,

<JamesBondCharacters>
<JamesBond>
<Name>Sean Connery</Name>
<Earnings>40000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
<JamesBond>
<Name>Roger Moore</Name>
<Earnings>55000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
<JamesBond>
<Name>George Lazenby</Name>
<Earnings>20000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
<JamesBond>
<Name>Timothy Dalton</Name>
<Earnings>25000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
<JamesBond>
<Name>Pierce Brosnan</Name>
<Earnings>70000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
<JamesBond>
<Name>Danial Craig</Name>
<Earnings>30000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
</JamesBondCharacters>

From this list I want to get the Bond details who earned the highest and least during his time. This example is just taken for fun to understand the XPath. 

To get the highest earned bond details use the below XPath

//JamesBond[not(./Earnings<//JamesBond/Earnings)]

To get the least earned bond details use the below XPath

//JamesBond[not(./Earnings>//JamesBond/Earnings)]

Note : The XPath which we used here is valid in XPath1.0. Alternatively you can check the same here in the below link

http://www.online-toolz.com/tools/xpath-editor.php

Credits :
GIB Learnings from Anitha and Padma Priya Iyengar

No comments:

Post a Comment