i want to sorting by descending order based on date.i dont know how to accomplish this :
Here is my xml :
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<inm:Results productTitle="Inmagic DB/Text WebPublisher PRO" productVersion="13.00" xmlns:inm="http://www.inmagic.com/webpublisher/query" oex="ISO-8859-1">
<inm:Recordset AC="QBE_QUERY" sn="AUTO26264" se="1392" queryCount="139" page="1" pageCount="1" setCount="139">
<inm:Record setEntry="0">
<inm:Title>BBBBBB</inm:Title>
<inm:Pub_Date>12-Jun-2012</inm:Pub_Date>
<inm:Words />
</inm:Record>
<inm:Record setEntry="1">
<inm:Title>TESTING ESTING</inm:Title>
<inm:Pub_Date>12-jul-2012</inm:Pub_Date>
<inm:Words />
</inm:Record>
<inm:Record setEntry="2">
<inm:Title>TESFDS SDFASDFASDt</inm:Title>
<inm:Pub_Date>30-Jun-2012</inm:Pub_Date>
<inm:Words />
</inm:Record>
</inm:Recordset>
</inm:Results>
and my xml is :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:inm="http://www.inmagic.com/webpublisher/query">
<xsl:output method="html"/>
<xsl:template match="/">
<ul class="baseList newsList">
<xsl:for-each select="inm:Results/inm:Recordset/inm:Record" >
<xsl:sort select="inm:Pub_Date" order="descending"/>
<li>
<span class="title">
<a href="#">
<xsl:value-of select="inm:Title" />
</a>
</span>
<p class="meta">
<span class="dateTime">
<xsl:value-of select="inm:Pub_Date"/>
</span>
</p>
</li>
</xsl:for-each>
</ul>
</xsl:template>
i try to sorting in xslt script but its not worked perfectly.
output was :
– 30-Jun-2012
– 12-jul-2012
– 12-jun-2012
but output should be :
-12-jul-2012
-30-jun-2012
-12-Jun-2012
I agree with the other answer posters that you should convert your dates to ISO date format.
Having said that, if you insist on using the format as supplied in the sample document, you can use the following xsl:sort instructions …
The first sorts on year, the second on month, and then finally day.
The style-sheet as a whole is …
Update
Just as a helpful hint, here is a neat template you can use to convert dates from the 30-Jun-2012 format to ISO/XML format. Let me know if you can use XSLT 2.0 . The conversion gets simpler in XSLT 2.0 .
Ok, its quiet obtuse! But I like it.