views:

34

answers:

1

Evidently MSXML6 doesn't support XSLT 2.0, at least not the max() function. I need to find out the node that contains the highest value among its siblings. They are in arbitrary order.

I want the order to remain identical so adding order-by and checking [0] is out of question.

I want to do this with a single XPath statement. I don't want to call templates or involve any more complex logic than that. I'm sure there is a horrifying MS Scripting Extensions embedded somewhere. Eww.

I thought of:

elem1[count(../elem1[@value < current()/@value]) = 0]

But it didn't work as I expected (returns the first node always). Any other nifty XPath magic can you think of there?

+4  A: 

Try

elem1[not(../elem1/@value > @value)]

That is, you want the elem1 for which it is not the case that another elem1 has a greater @value.

Inspiration from this handy page

AakashM
Worked like a charm, thanks!
ssg
It's worth mentioning that the `>` operator, when fed a node set (`../elem1/@value`), compares all nodes in the set against `@value`. This also means that the expression actually should be `elem1[not(../elem1/@value > @value)][1]`, since there could be more than one node with the same, maximum value. In such a case all these nodes are returned, even though you are only interested in one of them.
Tomalak
Good catch, although <xsl:variable /> selects the first node always when XPath expression returns a node-set. It seems to be automatic.
ssg