|
next
|
Subject: Formatting Date Author: Manikandan Surendranath Date: 12 May 2005 05:51 AM
|
Thanks for the response. I have written a template that will format the date to the format I need. Can you just look at this and tell me if this is optimal solution or can it be better.
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="format-date">
<xsl:param name="dateTime"/>
<xsl:if test="string-length(normalize-space($dateTime)) > 0" >
<xsl:variable name="space" select="' '"/>
<xsl:variable name="date">
<xsl:value-of select="substring-before($dateTime,'T')" />
</xsl:variable>
<xsl:variable name="year">
<xsl:value-of select="substring-before($date,'-')" />
</xsl:variable>
<xsl:variable name="temp">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="substring-after($date,'-')"/>
<xsl:with-param name="replace" select="$year"/>
<!--<xsl:with-param name="with" select=""/>-->
</xsl:call-template>
</xsl:variable>
<xsl:variable name="day">
<xsl:value-of select="number(substring-after($temp,'-'))" />
</xsl:variable>
<xsl:variable name="month">
<xsl:value-of select="number(substring-before($temp,'-'))" />
</xsl:variable>
<xsl:choose>
<xsl:when test="$month = 1">January</xsl:when>
<xsl:when test="$month = 2">February</xsl:when>
<xsl:when test="$month = 3">March</xsl:when>
<xsl:when test="$month = 4">April</xsl:when>
<xsl:when test="$month = 5">May</xsl:when>
<xsl:when test="$month = 6">June</xsl:when>
<xsl:when test="$month = 7">July</xsl:when>
<xsl:when test="$month = 8">August</xsl:when>
<xsl:when test="$month = 9">September</xsl:when>
<xsl:when test="$month = 10">October</xsl:when>
<xsl:when test="$month = 11">November</xsl:when>
<xsl:when test="$month = 12">December</xsl:when>
</xsl:choose>
<xsl:value-of select="concat(' ',$day,', ',$year)" />
</xsl:if>
</xsl:template>
|
|
|