0

I need to find the maximum of different values, some that are mathematical equations.

Below is my XML:

<History AccountBalance="100" 
         AccountLimit="500" 
         AccountBalanceAvailable="400" 
         ValueX="50" 
         ValueY="75"/>

I want to find the Max of:

Max((AccountBalance + ValueX + ValueY), (AccountBalanceAvailable - ValueY))

I'm new to XPath and can't find examples of something like this.

Don't even know where to start. In this example

This would evaluate to Max(225 or 325) = 325

I don't know how to do that in XPATH.

Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
user3179585
  • 123
  • 1
  • 1
  • 11
  • This may be relevant: http://stackoverflow.com/questions/1128745/how-can-i-use-xpath-to-find-the-minimum-value-of-an-attribute-in-a-set-of-elemen Is a scripting language solution any use? – Sobrique Oct 08 '15 at 14:04

2 Answers2

1

You can use max() function from Xpath 2.0.

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
0

In XPath 2.0,

max((@AccountBalance + @ValueX + @Value, @AccountBalanceAvailable - @ValueY))

Note the double parens, because max() doesn't take two arguments, it takes a single argument which is a sequence of numbers.

In XPath 1.0 it's much trickier because there is no max function and no conditional expression. Depending on what host language you are using, I think I would return both values to the calling application and have the calling application compare them.

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
Michael Kay
  • 156,231
  • 11
  • 92
  • 164