RE: [xsl] Formatting date

Subject: RE: [xsl] Formatting date
From: "Ben Robb" <Ben@xxxxxxxxxx>
Date: Fri, 8 Nov 2002 14:41:21 -0000
Yes:

<xsl:template match="creation_date">
	<!-- get the day part, and then expand it to 2 sig. figures -->
	<xsl:variable name="dayPart" select="substring-before(., '/')"/>
	<xsl:variable name="day">
		<xsl:number format="01" value="$dayPart"/>
	</xsl:variable>
	<!-- get the month part, and then expand it to 2 sig. figures
-->
	<xsl:variable name="monthPart"
select="substring-before(substring-after(.,'/'),'/')"/>
	<xsl:variable name="month">
		<xsl:number format="01" value="$monthPart"/>
	</xsl:variable>
	<!-- from the lengths of the day and month parts, it is easy to
see where to start the substring call for the year -->
	<xsl:variable name="yearStart" select="string-length($dayPart) +
string-length($monthPart) + 3"/>
	<xsl:variable name="year" select="substring(., $yearStart ,
4)"/>
	
	<cr_date day="{$day}" month="{$month}" year="{$year}" />
</xsl:template>

Though you really ought to consider using XML dates in your XML file
[e.g. in the form "yyyy-mm-ddThh:mm:ss"], since that avoids confusion
about whether you are on US or UK date formats (mm/dd/yyyy or
dd/mm/yyyy). Once you have that, you could also benefit from the generic
templates which have been developed as part of the eXSLT initiative.

Rgs,

Ben

-----Original Message-----
From: Felix Garcia [mailto:fnmtool@xxxxxxxxxxx] 
Sent: 08 November 2002 13:56
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Formatting date


I want to format the next element:

  <creation_date>2/9/2001 9:23:13</creation_date>

And transform to:

  <cr_date day="02" month="09" year="2001"/>

Can I do this transformation using XSL.

Thanks in advance



_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus


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


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


Current Thread