I am trying to figure out the XSLT (CSV output) for the below XML.
I would like to sort the grandchildren nodes i.e. sort Month node and pick the Sales_Program-ID node value of the set with the highest month value.
XML
<Root>
<Level1>
<EMPLID>123</EMPLID>
<Program>
<Sales_Program Name="XYZ">
<ID1>ab</ID1>
</Sales_Program>
<Start_Date>Jan1st</Start_Date>
**<Month>1</Month>**
</Program>
<Program>
<Sales_Program Name="ABC">
<ID1>cd</ID1>
</Sales_Program>
<Start_Date>Feb1</Start_Date>
**<Month>2</Month>**
</Program>
</Level1>
<Level1>
<EMPLID>456</EMPLID>
<Program>
<Sales_Program Name="XYZ">
<ID1>ab</ID1>
</Sales_Program>
<Start_Date>Jan1st</Start_Date>
<Month>1</Month>
</Program>
</Level1>
</Root>
Expected Output:
123,ab,Feb1,2 - (From first Level1 Node)
456,cd,Jan1st,1 (From second Level1 Node)
So you want to sort the
Program
elements by theMonth
child, in XSLT 3 with support for the higher-ordersort
function you can do that within XSLT 2 you need to implement the sorting in your own function with
xsl:perform-sort
: