mjsr
mjsr

Reputation: 7590

get id of the node with maximum value

i have something like this

 <ValueSet>
    <value id="0">109.3</value>
    <value id="1">110.6</value>
    <value id="2">111.1</value>
    <value id="3">111.5</value>
 </ValueSet>

and i need the id of the node that has the maximum value, i need do this in javascript using Xpath.

i do this:

var path = "//ValueSet[not(value <= preceding-sibling::ValueSet/value) and " +
           "           not(value <= following-sibling::ValueSet/value)]";
var result = this.documentRoot.evaluate(path, this.documentRoot, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
alert("max:" + result.textContent);

but doesn't work, :(

Upvotes: 3

Views: 166

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243479

Use:

/*/value[not(. < ../value)]/@id

Be ready to get more than one node, because there might be several nodes with the maximum value.

Upvotes: 3

Related Questions