Reputation: 123
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.
Upvotes: 0
Views: 842
Reputation: 163332
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.
Upvotes: 0