xpath how to find node with max attribute valuehttp://forums.asp.net/t/1109320.aspx/1?xpath+how+to+find+node+with+max+attribute+valueMon, 14 May 2007 15:24:18 -040011093201704692http://forums.asp.net/p/1109320/1704692.aspx/1?xpath+how+to+find+node+with+max+attribute+valuexpath how to find node with max attribute value <p>Hi guys</p> <p>can any one tell what would be xpath to find node with max value of val attribute i.e. &lt;node val=&quot;4&quot; /&gt;</p> <p>&lt;root&gt;</p> <p>&lt;node val=&quot;1&quot;/&gt;</p> <p>&lt;node val=&quot;2&quot;/&gt;</p> <p>&lt;node val=&quot;3&quot;/&gt;</p> <p>&lt;node val=&quot;4&quot;/&gt;</p> <p>&lt;/root&gt;</p> <p>Thank&nbsp; you,</p> <p>KK</p> 2007-05-10T21:19:01-04:001704752http://forums.asp.net/p/1109320/1704752.aspx/1?Re+xpath+how+to+find+node+with+max+attribute+valueRe: xpath how to find node with max attribute value <p>Hey </p> <p>you can try somethine like this:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; XmlDocument xmlDoc = new XmlDocument();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xmlDoc.LoadXml(file);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlNodeList nodeList = xmlDoc.SelectNodes(&quot;root/node&quot;);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; foreach (XmlNode xmlNode in nodeList)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strName = xmlNode.Attributes[&quot;val&quot;].Value;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int intStatsValue = Convert.ToInt32(xmlNode.InnerText);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //now you can store and compare the values <br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br> &nbsp;</p> &nbsp; <p>Hope this helps.</p> <p>&nbsp;</p> <p>Please don't forget to &quot;Mark as Answer&quot; if this post answered your question.&nbsp;</p> 2007-05-10T22:18:13-04:001704757http://forums.asp.net/p/1109320/1704757.aspx/1?Re+xpath+how+to+find+node+with+max+attribute+valueRe: xpath how to find node with max attribute value <p>Thank you for the repsonse. But don't we have any xpath or xslt functions&nbsp;&nbsp;to acheive that.</p> <p>&nbsp;</p> <p>Thanks,</p> <p>KK</p> 2007-05-10T22:24:54-04:001707659http://forums.asp.net/p/1109320/1707659.aspx/1?Re+xpath+how+to+find+node+with+max+attribute+valueRe: xpath how to find node with max attribute value <blockquote><span class="icon-blockquote"></span> <h4>kalvagadda</h4> <p>Thank you for the repsonse. But don't we have any xpath or xslt functions&nbsp;&nbsp;to acheive that.</p> <p>&nbsp;</p> <p>Thanks,</p> <p>KK</p> <p></p> </blockquote> <br> <br> In XPath try this: <p></p> <p>/root/node[not(@val &lt;= preceding-sibling::node/@val) and not(@val &lt;=following-sibling::node/@val)]</p> 2007-05-14T04:40:40-04:001707973http://forums.asp.net/p/1109320/1707973.aspx/1?Re+xpath+how+to+find+node+with+max+attribute+valueRe: xpath how to find node with max attribute value <p>Have a look into this link. It uses a function math:max. It has a link for source for that function and explains how it can be implemented</p> <p><a href="http://www.exslt.org/math/functions/max/index.html">http://www.exslt.org/math/functions/max/index.html</a></p> <p>Hope this helps you</p> 2007-05-14T09:14:59-04:001708494http://forums.asp.net/p/1109320/1708494.aspx/1?Re+xpath+how+to+find+node+with+max+attribute+valueRe: xpath how to find node with max attribute value <p>Hi,</p> <p>Thanks for the reply. It was very helpful.</p> <p>&nbsp;</p> <p>Thanks,</p> <p>Kiran</p> 2007-05-14T15:24:18-04:00