I want to sort the dates in xml using xslt and my date element is validated in xsd with datatype as date below is my xml and xsl
XML
<Trade xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Symbol xsi:type="TradedSymbol" Type="Swap"> <Economic xsi:type="EconomicLeg"> <Leg xsi:type="IRLegGeneratedFixed"> <Schedule xsi:type="ScheduleGeneratorFixed"> <Date>2014-06-17</Date> </Schedule> </Leg> </Economic> </Symbol> <Symbol xsi:type="TradedSymbol" Type="Swap"> <Economic xsi:type="EconomicDetailIRLeg"> <Leg xsi:type="IRLegFloat"> <Schedule xsi:type="ScheduleGeneratorFloat"> <Date>2018-06-17</Date> </Schedule> </Leg> </Economic> </Symbol> <Symbol xsi:type="TradedSymbol" Type="Floor"> <Economic xsi:type="EconomicDetailIRLeg"> <Leg xsi:type="IRLegFloat"> <Schedule xsi:type="ScheduleGeneratorFloat"> <Date>2000-06-17</Date> </Schedule> </Leg> </Economic> </Symbol> </Trade> XSD
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template name="fiExoticStructuredDeal"> <fixedIncomeExoticDeal> <frontOfficeDealDescription>Empty decription</frontOfficeDealDescription> <component> <frontOfficeComponentType> <optionDetails> <optionStyle>European</optionStyle> <optionDates> <adjustedDate> <xsl:for-each select="/Trade/Symbol/Economic/Leg/Schedule"> <xsl:sort select="concat(substring-before(Date,'-'), substring-before(substring-after(Date,'- '),'-'),substring-after(substring-after(Date,'-'),'-'))" order="ascending"/> <xsl:choose> <xsl:when test="position() = last()"> <xsl:value-of select="Date"/> </xsl:when> </xsl:choose> </xsl:for-each> </adjustedDate> </optionDates> </optionDetails> </frontOfficeComponentType> </component> </fixedIncomeExoticDeal> </xsl:template> </xsl:stylesheet> I am not able sort the Date using xslt.It always gives me the last date in Schedule element. It will be great if someone let me know if i am missing something.