109.3 110.6 1...">

Get node ID 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 node identifier that has the maximum value, I need to do this in javascript using Xpath.

I'm doing it:

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 does not work: (

+3
source share
1 answer

Using

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

Be prepared to get more than one node , as there may be several nodes with a maximum value.

+3
source

Source: https://habr.com/ru/post/1752855/


All Articles