[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Formatting date

Subject: RE: Formatting date
From: "Ben Robb" <Ben@xxxxxxxxxx>
Date: Fri, 8 Nov 2002 14:41:21 -0000
date format uk
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:  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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.