开发者

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).singleNodeVal开发者_开发问答ue;
alert("max:" + result.textContent);

but doesn't work, :(


Use:

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜