xsl-list
[Top] [All Lists]

RE: Re: date-time formatting question

2004-02-03 13:26:41
You're right. It is simple, just a bit long, and no, you don't necessarily need 
those templates. They are good, but big. Try this simple approach.:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:output method="xml" indent="yes" encoding="UTF-8" />

 <xsl:template match="/">
   <xsl:apply-templates />
 </xsl:template>

 <xsl:template match="text">
   <xsl:apply-templates />
 </xsl:template>

 <xsl:template match="date">
   <xsl:variable name="day-part">
     <xsl:choose>
       <xsl:when test="substring(.,8,1) = '0'">
         <xsl:value-of select="substring(.,9,1)" />
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="substring(.,9,2)" />
       </xsl:otherwise>
     </xsl:choose>
   </xsl:variable>

   <xsl:variable name="year-part" select="substring(.,1,4)" />

   <xsl:variable name="month-part">
     <xsl:choose>
       <xsl:when test="substring(.,6,2) = '01'">January</xsl:when>
       <xsl:when test="substring(.,6,2) = '02'">February</xsl:when>
       <xsl:when test="substring(.,6,2) = '03'">March</xsl:when>
       <xsl:when test="substring(.,6,2) = '04'">April</xsl:when>
       <xsl:when test="substring(.,6,2) = '05'">May</xsl:when>
       <xsl:when test="substring(.,6,2) = '06'">June</xsl:when>
       <xsl:when test="substring(.,6,2) = '07'">July</xsl:when>
       <xsl:when test="substring(.,6,2) = '08'">August</xsl:when>
       <xsl:when test="substring(.,6,2) = '09'">September</xsl:when>
       <xsl:when test="substring(.,6,2) = '10'">October</xsl:when>
       <xsl:when test="substring(.,6,2) = '11'">November</xsl:when>
       <xsl:when test="substring(.,6,2) = '12'">December</xsl:when>
       <xsl:otherwise></xsl:otherwise>
     </xsl:choose>
   </xsl:variable>

   <date><xsl:value-of select="concat($month-part, ' ', $day-part, ', ', $year-part)" 
/></date>
 </xsl:template>

</xsl:stylesheet>

--
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Bruce D'Arcus <bdarcus(_at_)fastmail(_dot_)fm>
Sent:     Tue, 3 Feb 2004 15:13:45 -0500
To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:  Re: [xsl] date-time formatting question


I wrote:

Input example:

        <text>
           <date>2003-03-15</date>
        </text>

Desired output:

        March 3, 2003

Umm, just to avoid potential confusion, I of course meant to write:

        March 15, 2003

Bruce


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




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



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