xsl-list
[Top] [All Lists]

RE: Sorting different date formats

2004-01-13 15:13:10

Thank you very much everyone!!




                                                                                
                                                                
                      "Josh Canfield"                                           
                                                                
                      <josh(_dot_)canfield(_at_)plumtree(_dot_)co        To:    
   <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>                           
                  
                      m>                                cc:                     
                                                                
                      Sent by:                          Subject:  RE: [xsl] 
Sorting different date formats                                      
                      owner-xsl-list(_at_)lists(_dot_)mulbe                     
                                                                           
                      rrytech.com                                               
                                                                
                                                 |---------------------|        
                                                                
                                                 | ( ) Urgent(4 hours) |        
                                                                
                      14/01/2004 04:26           | (*) Normal(24-48)   |        
                                                                
                      Please respond to xsl-list | ( ) Low(72 hours)   |        
                                                                
                                                 |---------------------|  
Expires on                                                            
                                                                                
                                                                
                                                                                
                                                                
                                                                                
                                                                
                                                                                
                                                                
                                                                                
                                                                





I think you can simplify this a lot. The text value for the date sorts
correctly without transforming it to a number.

<xsl:template match="/dates">
  <xsl:for-each select="endDate">
     <xsl:sort select="." data-type="text"/>
     <xsl:copy-of select="."/>
  </xsl:for-each>
</xsl:template>

If you did need to do the processing, it seems like it would be simpler to
put the translate into the sort elements select statement instead of
creating a variable:

<xsl:template match="/dates">
  <xsl:for-each select="endDate">
     <xsl:sort select="translate(.,'-','')" data-type="number"/>
     <xsl:copy-of select="."/>
  </xsl:for-each>
</xsl:template>


Josh
-----Original Message-----
From: Mukul Gandhi [mailto:mukulgandhi2003(_at_)yahoo(_dot_)co(_dot_)in]
Sent: Tuesday, January 13, 2004 8:27 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Sorting different date formats


Hi Allan,
  I have come up with a sorting algorithm. Hope its
correct, and suits your requirement ;)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">
<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>

<xsl:template match="/dates">
  <xsl:variable name="RTF">
    <xsl:for-each select="endDate">
      <endDate>
             <xsl:value-of select="translate(.,'-','')"/>
      </endDate>
    </xsl:for-each>
  </xsl:variable>

  <xsl:for-each select="msxsl:node-set($RTF)/endDate">
     <xsl:sort select="." data-type="number"/>
     <endDate>
             <xsl:value-of select="substring(. , 1, 4 )"
/>-<xsl:value-of select="substring(. , 5, 2 )"
/>-<xsl:value-of select="substring(. , 7, 2 )" />-
     </endDate>
   </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

 --- allan(_dot_)mccluskey(_at_)centrelink(_dot_)gov(_dot_)au wrote: > Hi
all,

Could someone please show me how to perform and
XSL:SORT on an date in this
format? <endDate>2004-02-15</endDate>

I have many other sorts that I need to perform so an
explantion would also
be much appreciated so I can fully understand how
you do it : )

Many thanks,
Allan






Important:  This e-mail is intended for the use of
the addressee and may contain information that is
confidential, commercially valuable or subject to
legal or parliamentary privilege.  If you are not
the intended recipient you are notified that any
review, re-transmission, disclosure, use or
dissemination of this communication is strictly
prohibited by several Commonwealth Acts of
Parliament.  If you have received this communication
in error please notify the sender immediately and
delete all copies of this transmission together with
any attachments.


 XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list


________________________________________________________________________
Yahoo! India Mobile: Download the latest polyphonic ringtones.
Go to http://in.mobile.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list








Important:  This e-mail is intended for the use of the addressee and may 
contain information that is confidential, commercially valuable or subject to 
legal or parliamentary privilege.  If you are not the intended recipient you 
are notified that any review, re-transmission, disclosure, use or dissemination 
of this communication is strictly prohibited by several Commonwealth Acts of 
Parliament.  If you have received this communication in error please notify the 
sender immediately and delete all copies of this transmission together with any 
attachments.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>