Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xsl date format issue

From: "Brandon Gano" <bgano@----------.--->
To: 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/




transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent