RE: formatting date using xslt

Subject: RE: formatting date using xslt
From: Matthew Bentley <matthew.bentley@xxxxxxxxxxxxxx>
Date: Fri, 22 Sep 2000 08:19:48 +1000
>Should I use a JavaScript function for formatting date using XSLT
> or is there any built-in function for this purpose?

Heres three functions for formatting a date of the form "YYYYMMDD" into
other formats in XSLT:

<xsl:template name="standard_date">
	<xsl:param name="date" />
	<!-- Day -->
	<xsl:value-of select="substring($date, 7, 2)" />
	<xsl:text>/</xsl:text>
	<!-- Month -->
	<xsl:value-of select="substring($date, 5, 2)" />
	<xsl:text>/</xsl:text>
	<!-- Year -->
	<xsl:value-of select="substring($date, 3, 2)" />
</xsl:template>

<xsl:template name="short_date">
	<xsl:param name="date" />
	<!-- Month -->
	<xsl:value-of select="substring($date, 5, 2)" />
	<xsl:text>/</xsl:text>
	<!-- Year -->
	<xsl:value-of select="substring($date, 3, 2)" />
</xsl:template>

<xsl:template name="long_date">
	<xsl:param name="date" />
	<!-- Day -->
	<xsl:value-of select="number(substring($date, 7, 2))" />
	<xsl:text> </xsl:text>
	<!-- Month -->
	<xsl:variable name="month" select="number(substring($date, 5, 2))"/>
	<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:otherwise>INVALID MONTH</xsl:otherwise>
	</xsl:choose>
	<xsl:text> </xsl:text>
	<!-- Year -->
	<xsl:value-of select="substring($date, 1, 4)" />
</xsl:template>

-M@T
=====================================================================
WARNING -This e-mail, including any attachments, is for the 
personal use of the recipient(s) only.
Republication and re-dissemination, including posting to news 
groups or web pages, is strictly prohibited without the express
prior consent of
Thomson Legal & Regulatory Group Asia Pacific Ltd 
ACN 058 914 668
=====================================================================


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


Current Thread