[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Get to 2 max values and element names

Subject: Get to 2 max values and element names
From: "W Charlton" <XSLList@xxxxxxxxxx>
Date: Fri, 11 May 2012 14:36:27 +0100
 Get to 2 max values and element names
I have a peculiar problem. We have to extract the top 2 (modified) values from
some elements in a list and also get the element names. The xml is something
like:

<Data>
   <Modifier>6</Modifier>
   <List>
       <Julian>123</Julian>
       <Steve>45654</Steve>
       <Helen>98412</Helen>
       <Jack>-50</Jack>
       <Ruth>981</Ruth>
       <Susan>8431</Susan>
       <Trevor>354</Trevor>
       <Petra>6257</Petra>
       <Harold>25632</Harold>
       <Mary>8695</Mary>
   </List>
</Data>

Note: We know that sometimes Jackbs (and only Jackbs) value is negative,
in which case he is excluded from the calculation.
It is also possible that any of the numbers are NULL in which case they are
also excluded or ignored.

I need to do the following:

Depending on the value of the Modifier (1-10) we have 4 variables.
vSteveMod, vHelenMod, vJackMod and vPetraMod
These vary depending on the value of the Modifier, there are 10 quartets of
values.

We now need to calculate the modified values for Steve, Helen, Jack and Petra
(these 4 are chosen specifically for this test) dictated by the current
Modifier (6).
So say that when the Modifier = 6, the 4 Modifying vars are:
vSteveMod = 1.2
vHelenMod = 0.65
vJackMod = 0.89
vPetraMod = 1.32

We then multiply these *Mod vars by the related value, so:
vSteveResult = 1.2 * 45654 = 54784.8
vHelenResult = 0.65 * 98412 = 63967.8
vJackResult = 0.89 * -50 = EXCLUDED
vPetraResult = 1.32 * 6257 = 8259.24

Finally we need to extract 4 values:
The Top value and element name.
The next (penultimate) highest value and also the element name.

e.g. in this case:

TopValue = 63967.8
TopName = Helen
PenultValue = 54784.8
PenultName = Steve

All using XSLT1

William Charlton
The yMonda team
yMonda Limited
w: www.ymonda.net

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.