Re: [xsl] Converting date formats

Subject: Re: [xsl] Converting date formats
From: Gary Frederick <gary.frederick@xxxxxxxxx>
Date: Thu, 07 Jun 2001 15:40:06 -0500
I agree. Go for simple and then work your way up. I was pretty much an XSLT newby several weeks ago. Read the various examples you can find and try them yourself. Then start modifying them.

I was giving some input on how to use that XSLT template library. Save the pointer and go back to it in a few weeks. I'd be willing to e-mail you the working example. It's pretty specific to my needs (web pages of iCalendar events) but it may be useful once you have Xiaocun's example working.

Hmmm... I'll clean it up and post it's location. Soon...


Xiaocun Xu wrote:

Hi, Doug:

  If you are new to XSLT, you really should start by
going through a primer before trying to code anything
productive.  If you have any question, check out FAQ
  In any case, here is a complete working XSL
illustrate date formatting.  I set current date into a
variable and output it in the format you wanted.  This
is a good start point for you to massage this code
into your own code:
  <xsl:template match="/">	
    <xsl:variable name="date" select="20010607"/>
    <xsl:value-of select="concat(substring($date, 7,
2),'/',substring($date, 5, 2),'/',substring($date, 1,

Hope this helps,

--- "Hewko, Doug" <Doug.Hewko@xxxxxxxxxxxxxxx> wrote:

Thanks for the help. Do you have an example? I am
very new to XML (just
starting to learn even what a DTD is for) and am
unable to get the previous
suggestions to work. When I entered the
"xsl:variable" solution, I got a
"can not use xsl:variable there" type message.

-----Original Message-----
From: Gary Frederick
Sent: June 7, 2001 2:41 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Converting date formats

Others gave the direct way to translate dates. You
can also use the XSLT Standard Library

I use it to print events for a calendar. The input
is iCalendar converted to XML.

   <param kind="TZID">CT(America/Chicago)</param>

The stylesheet parts are ... <xsl:call-template name="DATE"> <xsl:with-param name="this-date" select="DTSTART/value"/> </xsl:call-template> ... <xsl:template name="DATE"> <xsl:param name="this-date"/>

   <xsl:call-template name="dt:format-date-time">
     <xsl:with-param name="year"
select='substring($this-date, 1, 4)' />
     <xsl:with-param name="month"
select='substring($this-date, 5, 2)'/>
     <xsl:with-param name="day"
select='substring($this-date, 7, 2)'/>
     <xsl:with-param name="hour"
select='substring($this-date, 10, 2)'/>
     <xsl:with-param name="minute"
select='substring($this-date, 12, 2)'/>
     <xsl:with-param name="second"
select='substring($this-date, 14, 2)'/>
     <xsl:with-param name="format"
select="'%Y-%m-%dT %H:%M:%S'" />

It's overkill if you just want to convert the date.
Perhaps you want to format dates in several ways...


Hewko, Doug wrote:

In my XML document, I have a date stored in ISO




How can I convert this in my XSL file to dd/mm/yyy

format (with the dashes)?

I am currently using the command:
			<td><xsl:value-of select="LASTUPDATED"/></td>

XSL-List info and archive:

XSL-List info and archive:

XSL-List info and archive:

Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 a year!

XSL-List info and archive:

XSL-List info and archive:

Current Thread