XSLT Sort / Group question

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all,
in my XML I have a collection/NodeSet list (of people). In this NodeSet list I have many repeated people (who have the same <PersonNumber>, but they have different date values in their node, <FromDate>.
As I only need to process one instance of each person, for those person with multiple entries, I need to take the person NodeSet entry that has the latest date.
I know how to sort in XSLT and to pull the latest NodeSet entry based on date, but my requirement seems to require a form of grouping based on <PersonNumber> ordering (descending by <FromDate>). Example source and required result XML is below....
Source XML...

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; CurrentDirectors<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; CurrentDirector<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; PersonNumber<span style="color:Blue; >6410124801<span style="color:Blue; </<span style="color:#A31515; PersonNumber<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Sofia Helena Frändberg<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; FromDate<span style="color:Blue; >1998-06-02T00:00:00<span style="color:Blue; </<span style="color:#A31515; FromDate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; CurrentDirector<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; CurrentDirector<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; PersonNumber<span style="color:Blue; >6410124801<span style="color:Blue; </<span style="color:#A31515; PersonNumber<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Sofia Helena Frändberg<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; FromDate<span style="color:Blue; >1999-09-24T00:00:00<span style="color:Blue; </<span style="color:#A31515; FromDate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; CurrentDirector<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; CurrentDirector<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; PersonNumber<span style="color:Blue; >6604145216<span style="color:Blue; </<span style="color:#A31515; PersonNumber<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Per Arne Mikael Hagström<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; FromDate<span style="color:Blue; >2006-11-21T00:00:00<span style="color:Blue; </<span style="color:#A31515; FromDate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; CurrentDirector<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; CurrentDirector<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; PersonNumber<span style="color:Blue; >6604145216<span style="color:Blue; </<span style="color:#A31515; PersonNumber<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Per Arne Mikael Hagström<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; FromDate<span style="color:Blue; >2006-11-28T00:00:00<span style="color:Blue; </<span style="color:#A31515; FromDate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; CurrentDirector<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; CurrentDirector<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; PersonNumber<span style="color:Blue; >4607317338<span style="color:Blue; </<span style="color:#A31515; PersonNumber<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Valborgs Lars Erik <span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; FromDate<span style="color:Blue; >2010-06-18T00:00:00<span style="color:Blue; </<span style="color:#A31515; FromDate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; CurrentDirector<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; CurrentDirectors<span style="color:Blue; >
[/code]

Desired Result XML

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; CurrentDirectors<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Director<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Sofia Helena Frändberg<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; AppointmentDate<span style="color:Blue; >1999-09-24T00:00:00<span style="color:Blue; </<span style="color:#A31515; AppointmentDate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Director<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Director<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Per Arne Mikael Hagström<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; AppointmentDate<span style="color:Blue; >2006-11-28T00:00:00<span style="color:Blue; </<span style="color:#A31515; AppointmentDate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Director<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Director<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Valborgs Lars Erik<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; AppointmentDate<span style="color:Blue; >2010-06-18T00:00:00<span style="color:Blue; </<span style="color:#A31515; AppointmentDate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Director<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; CurrentDirectors<span style="color:Blue; >
[/code]


Any help on this would be greatly appreciated.
Thanks <hr class="sig Tryst

View the full article
 
Back
Top