470,833 Members | 1,379 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

XPath get the max value

can we get the max value of element from xpath

e.g: Xpath Query Expression: /Books/Book[@id='3'] to select XMLNode which id
is "3"

Can I use Xpath to get the MAX Book id?

Thanks in advanced.
Apr 27 '06 #1
3 23037


beachboy wrote:
can we get the max value of element from xpath

e.g: Xpath Query Expression: /Books/Book[@id='3'] to select XMLNode which id
is "3"

Can I use Xpath to get the MAX Book id?


This XPath expression

/Books/Book[not(@id <= preceding-sibling::Book/@id) and not(@id <=
following-sibling::Book/@id)]

selects the Book element with the maximum id attribute value.

If you want to select the attribute itself then use

/Books/Book/@id[not(. <= ../preceding-sibling::Book/@id) and not(. <=
.../following-sibling::Book/@id)]

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 27 '06 #2
Thanks Martin,

I want to clarify my understanding..

I can get a XmlNode which has a max id attribute value for below syntax:
XmlNode node = doc.SelectSingleNode( /Books/Book[not(@id <=
preceding-sibling::Book/@id) and not(@id <= following-sibling::Book/@id)] )

but how to implement below expression? what type will return? XmlNode or
just a value of id
/Books/Book/@id[not(. <= ../preceding-sibling::Book/@id) and not(. <=
../following-sibling::Book/@id)]

Thanks again!!!

"Martin Honnen" <ma*******@yahoo.de> ???
news:O0**************@TK2MSFTNGP05.phx.gbl ???...


beachboy wrote:
can we get the max value of element from xpath

e.g: Xpath Query Expression: /Books/Book[@id='3'] to select XMLNode which id is "3"

Can I use Xpath to get the MAX Book id?


This XPath expression

/Books/Book[not(@id <= preceding-sibling::Book/@id) and not(@id <=
following-sibling::Book/@id)]

selects the Book element with the maximum id attribute value.

If you want to select the attribute itself then use

/Books/Book/@id[not(. <= ../preceding-sibling::Book/@id) and not(. <=
../following-sibling::Book/@id)]

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Apr 28 '06 #3


beachboy wrote:

but how to implement below expression? what type will return? XmlNode or
just a value of id
/Books/Book/@id[not(. <= ../preceding-sibling::Book/@id) and not(. <=
../following-sibling::Book/@id)]


That XPath expression selects attribute nodes with name id. Thus with
SelectSingleNode you will get one attribute node or null, with
SelectNodes you will get a node list with attribute nodes.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by bdinmstig | last post: by
7 posts views Thread by Sebastian Petzelberger | last post: by
4 posts views Thread by Son KwonNam | last post: by
9 posts views Thread by David Thielen | last post: by
3 posts views Thread by Jason Mobarak | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.