all groups > dotnet xml > april 2006 >
You're in the

dotnet xml

group:

XPath get the max value


Re: XPath get the max value Martin Honnen
4/27/2006 2:27:40 PM
dotnet xml:


[quoted text, click to view]

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
XPath get the max value beachboy
4/27/2006 4:08:45 PM
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.

Re: XPath get the max value beachboy
4/28/2006 12:00:00 AM
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" <mahotrash@yahoo.de> ???
news:O0HP7XfaGHA.1348@TK2MSFTNGP05.phx.gbl ???...
[quoted text, click to view]

Re: XPath get the max value Martin Honnen
4/28/2006 1:53:22 PM


[quoted text, click to view]


[quoted text, click to view]

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
AddThis Social Bookmark Button