Note that there are some explanatory texts on larger screens.

plurals
  1. POsorting dates in XML using xslt
    text
    copied!<p>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 </p> <p>XML</p> <pre><code>&lt;Trade xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;Symbol xsi:type="TradedSymbol" Type="Swap"&gt; &lt;Economic xsi:type="EconomicLeg"&gt; &lt;Leg xsi:type="IRLegGeneratedFixed"&gt; &lt;Schedule xsi:type="ScheduleGeneratorFixed"&gt; &lt;Date&gt;2014-06-17&lt;/Date&gt; &lt;/Schedule&gt; &lt;/Leg&gt; &lt;/Economic&gt; &lt;/Symbol&gt; &lt;Symbol xsi:type="TradedSymbol" Type="Swap"&gt; &lt;Economic xsi:type="EconomicDetailIRLeg"&gt; &lt;Leg xsi:type="IRLegFloat"&gt; &lt;Schedule xsi:type="ScheduleGeneratorFloat"&gt; &lt;Date&gt;2018-06-17&lt;/Date&gt; &lt;/Schedule&gt; &lt;/Leg&gt; &lt;/Economic&gt; &lt;/Symbol&gt; &lt;Symbol xsi:type="TradedSymbol" Type="Floor"&gt; &lt;Economic xsi:type="EconomicDetailIRLeg"&gt; &lt;Leg xsi:type="IRLegFloat"&gt; &lt;Schedule xsi:type="ScheduleGeneratorFloat"&gt; &lt;Date&gt;2000-06-17&lt;/Date&gt; &lt;/Schedule&gt; &lt;/Leg&gt; &lt;/Economic&gt; &lt;/Symbol&gt; &lt;/Trade&gt; </code></pre> <p>XSD</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:template name="fiExoticStructuredDeal"&gt; &lt;fixedIncomeExoticDeal&gt; &lt;frontOfficeDealDescription&gt;Empty decription&lt;/frontOfficeDealDescription&gt; &lt;component&gt; &lt;frontOfficeComponentType&gt; &lt;optionDetails&gt; &lt;optionStyle&gt;European&lt;/optionStyle&gt; &lt;optionDates&gt; &lt;adjustedDate&gt; &lt;xsl:for-each select="/Trade/Symbol/Economic/Leg/Schedule"&gt; &lt;xsl:sort select="concat(substring-before(Date,'-'), substring-before(substring-after(Date,'- '),'-'),substring-after(substring-after(Date,'-'),'-'))" order="ascending"/&gt; &lt;xsl:choose&gt; &lt;xsl:when test="position() = last()"&gt; &lt;xsl:value-of select="Date"/&gt; &lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;/xsl:for-each&gt; &lt;/adjustedDate&gt; &lt;/optionDates&gt; &lt;/optionDetails&gt; &lt;/frontOfficeComponentType&gt; &lt;/component&gt; &lt;/fixedIncomeExoticDeal&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload