|
Subject: Re: [xsl] Date Formating From: "Perry Molendijk" <perry@xxxxxxxxxxxxxx> Date: Sun, 12 Jan 2003 23:27:11 +0800 |
I have used this on numerous occassions, perhaps not the most elegant
solution but it works:
create a file (calendar.xml) with xml that looks something like this:
<calendar>
<days-in-week>
<day number="1" short="Sun" long="Sunday"/>
<day number="2" short="Mon" long="Monday"/>
<day number="3" short="Tue" long="Tuesday"/>
<day number="4" short="Wed" long="Wednesday"/>
<day number="5" short="Thu" long="Thursday"/>
<day number="6" short="Fri" long="Friday"/>
<day number="7" short="Sat" long="Saturday"/>
</days-in-week>
<months-of-year>
<month number="01" short="Jan" long="January"/>
<month number="02" short="Feb" long="February"/>
<month number="03" short="Mar" long="March"/>
<month number="04" short="Apr" long="April"/>
<month number="05" short="May" long="May"/>
<month number="06" short="Jun" long="June"/>
<month number="07" short="Jul" long="July"/>
<month number="08" short="Aug" long="August"/>
<month number="09" short="Sep" long="September"/>
<month number="10" short="Oct" long="October"/>
<month number="11" short="Nov" long="November"/>
<month number="12" short="Dec" long="December"/>
</months-of-year>
</calendar>
in your XSL at create a parameter that holds this document:
<xsl:param name="calendarReference" select="document('calendar.xml')"/>
<xsl:template match="date-created">
<xsl:call-template name="date-writer">
<xsl:with-param name="thisDate" select="."/>
</xsl:template>
</xsl:template>
and a named template like this:
<xsl:template match="date-writer">
<xsl:param name="thisDate"/>
<xsl:variable name="day" select="substring($thisDate,9,2)"/>
<xsl:variable name="month"
select="normalize-space(substring($thisDate,6,2))"/>
<xsl:variable name="year" select="substring($thisDate,1,4)"/>
<xsl:value-of select="$day"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="$calendarReference/calendar/months-of-year/month[@number=$month]/@sh
ort"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="$year"/>
</xsl:template>
off course this template only works with YYYY-MM-DD format but it is easily
adapted to any other format. Its biggest down fall is when you need the name
of the day.
EXSLT has a lot of date-time functions you could use. (www.exslt.org)
Perry Molendijk
----- Original Message -----
From: "Arthur" <ArthurMaloney@xxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, December 12, 2003 9:09 PM
Subject: [xsl] Date Formating
> Hello xsl-list,
>
> I'm transforming an xml file that gives me a nicely formatted report
> (html 80 odd pages).
> Part of the transform uses format-number() for decimal places etc.
>
> one of the elements in the xml, is a date
> <date-created>2003-01-12</date-created>
>
> How do you transform this to 12-Jan-03 ?
>
>
> --
> Best regards,
> Arthur mailto:ArthurMaloney@xxxxxxxxxx
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
----- Original Message -----
From: "Arthur" <ArthurMaloney@xxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, December 12, 2003 9:09 PM
Subject: [xsl] Date Formating
> Hello xsl-list,
>
> I'm transforming an xml file that gives me a nicely formatted report
> (html 80 odd pages).
> Part of the transform uses format-number() for decimal places etc.
>
> one of the elements in the xml, is a date
> <date-created>2003-01-12</date-created>
>
> How do you transform this to 12-Jan-03 ?
>
>
> --
> Best regards,
> Arthur mailto:ArthurMaloney@xxxxxxxxxx
>
>
> 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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Date Formating, Elizabeth Barham | Thread | Re: [xsl] Date Formating, James Fuller |
| Re: [xsl] Date Formating, Elizabeth Barham | Date | Re: [xsl] Proposal: Copying with So, Dimitre Novatchev |
| Month |