Using the below XML, I need to figure out which person worked more hours in each site. For instance in the below XML, person 1 worked 8 hours in site 1 but person 2 worked only 6 hours. So result should contain person 1 and site 1 in transformed XML. If the hours are equal, select first person.
EDIT: I want this to be implemented using XSLT 1.0.
<root>
<WorkSite Person="P1" Site="S1">
<Hours>8</Hours>
</WorkSite>
<WorkSite Person="P1" Site="S2">
<Hours>2</Hours>
</WorkSite>
<WorkSite Person="P1" Site="S3">
<Hours>9</Hours>
</WorkSite>
<WorkSite Person="P2" Site="S1">
<Hours>6</Hours>
</WorkSite>
<WorkSite Person="P2" Site="S2">
<Hours>10</Hours>
</WorkSite>
<WorkSite Person="P2" Site="S3">
<Hours>2</Hours>
</WorkSite>
</root>
XSLT transform result should be like this:
<root>
<WorkSite Person="P1" Site="S1"/>
<WorkSite Person="P2" Site="S2"/>
<WorkSite Person="P1" Site="S3"/>
</root>
An XSLT 1.0 solution. This stylesheet:
Output:
This XSLT 1.0 transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Do note:
The use of the Muenchian method for grouping to find all different
Site
values.The way maximum is found by sorting in descending order and getting the first result from the sorted node-list.