I\'m rather new to coding xslt and have got rather stuck trying to do the following.
I have an xml file that has breeding info for horses broken into two main sectio
This transformation:
Sire
when applied on the provided XML document:
1
hrsA
101
4800
2
hrsB
102
3600
3
hrsC
102
2800
4
hrsD
101
56
5
hrsE
100
20000
6
hrsF
101
20000
7
hrsG
101
559
8
hrsH
102
386
10000
100
srA
117
101
srB
774
102
srC
43
produces the wanted, correct result:
Sire 101 (srB) Stakes: 25415
Sire 100 (srA) Stakes: 20000
Sire 102 (srC) Stakes: 16786
Explanation:
We define a key that specifies a Horse as a function of its SireID. This is useful in selecting all offspring of a given Sire just by providing its ID in a call to the standard XSLT key() function -- like this: key('kOffspring', ID).
Similarly, the sum of Stakes of all offspring of a given Sire is: sum(key('kOffspring', ID)/*/Stakes) .
We apply templates to all Sire elements in the XML document and sort these by the decreasing values of the sums of the Stakes of their offsprings.
For each Sire we output its ID, Name and the sum of Stakes of its offspring.