Peter Walke

in

format-DateTime with XSL

I had to take a DateTime in the format of 2009-10-23 00:00:00 and convert it to 10/23/2009 using XSL.  XSL 1.0 doesn’t have any type of datetime formatting functions, so the following snippet should help anyone else in a similar predicament:

 

<xsl:element name="newdate">
         <xsl:call-template name="FormatDate">
           <xsl:with-param name="DateTime" select="@Date"/>
         </xsl:call-template>
       </xsl:element>

<xsl:template name="FormatDate">
   <xsl:param name="DateTime" />
   <xsl:variable name="Year">
     <xsl:value-of select='substring-before($DateTime,"-")'/>
   </xsl:variable>
   <xsl:variable name="NoYear">
     <xsl:value-of select='substring-after($DateTime,"-")'/>
   </xsl:variable>
   <xsl:variable name="Month">
     <xsl:value-of select='substring-before($NoYear,"-")'/>
   </xsl:variable>
   <xsl:variable name="DayWithTime">
     <xsl:value-of select='substring-after($NoYear,"-")'/>
   </xsl:variable>
   <xsl:variable name="Day">
     <xsl:value-of select='substring-before($DayWithTime," ")'/>
   </xsl:variable>
   <xsl:value-of select='$Month'/>
   <xsl:text>/</xsl:text>
   <xsl:value-of select='$Day'/>
   <xsl:text>/</xsl:text>
   <xsl:value-of select='$Year'/>
</xsl:template>

Comments

caddakushn said:

stricter contends issues 104 link albedo cycles bush

# December 23, 2009 3:37 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)