![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: xsl date format issue [Thread Next] Re: xsl date format issueTo: NULL Date: 7/16/2007 9:35:00 AM
Here is a solution that should work with any XSL processor (not tested):
<xsl:template name="expand-date">
<!-- (YYYYMMDD) -->
<xsl:param name="date" />
<!-- Parse date -->
<xsl:variable name="year" select="substring($date,1,4)" />
<xsl:variable name="month" select="number(substring($date,5,2))" />
<xsl:variable name="day" select="number(substring($date,7,2))" />
<!-- Output -->
<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:choose>
<xsl:value-of select="$day" /><xsl:text>, </xsl:text>
<xsl:value-of select="$year" />
</xsl:template>
There is probably a cleaner/more efficient solution for parsing the month
name, but this should work. Here is how you might call the template:
<xsl:call-template name="expand-date">
<xsl:with-param name="date" select="/path/to/@date-node" />
</xsl:call-template>
-bgano
----- Original Message -----
From: "Martin Honnen" <mahotrash@y...>
Newsgroups: microsoft.public.xsl
Sent: Sunday, July 08, 2007 4:30 AM
Subject: Re: xsl date format issue
> kamkaro wrote:
>> Thanks Martin. I have to say, you have very strong knowledge about XML. i
>> have two more questions, first i m using Java base parser so can i use
>> Microsoft stuff, second according to your reply you give me the following
>> code;
>> <xsl:value-of
>> xmlns:msxsl="urn:schemas-microsoft-com:xslt"
>> select="msxsl:format-date('2001-03-06', 'MMMM dd, yyyy', 'en-US')"/>
>>
>> how do i call the date element's data, e.g i m doing <xsl:template
>> match="Date">
>> <xsl:value-of select="." />
>> </xsl:template>
>
> An XSLT processor implemented in Java does very likely not implement those
> MS specific extension functions my suggested solution uses. It might offer
> other extension functions, in particular the possibility to use Java
> objects and methods but I am not familiar with that. Try a
> forum/newsgroup/mailing list dedicated to that XSLT processor you use.
>
> As for the template, you would simply use
>
> <xsl:template match="Date">
> <xsl:value-of
> xmlns:msxsl="urn:schemas-microsoft-com:xslt"
> select="msxsl:format-date(., 'MMMM dd, yyyy', 'en-US')"/>
> </xsl:template>
>
> assuming Date has contents in the form yyyy-mm-dd and you are using MSXML
> 4 or later or XslCompiledTransform.
>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
