Skip to main content
Inspiring
Apr 13, 2006 10:54 PM UTC
Answered

Using XSL to format a date. I'm soooo lost.

Hello,

I'm using XSL to format a large XML set I get from a webservice. So far it's been working great but I need to format the date so that is looks something like this: Sunday 05/21/2006 8:00 PM
rather than this: 2006-05-21T20:00:00.0000000-04:00

I know you can format dates in the XSL but I have no idea how and all the info I can find on the net is for XSL savvy people. Which I am not.

Any help would be greatly appreciated.
Here's what I have as an xsl.
Note that eventDate is the param I need to format.

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer
Apr 19, 2006 2:42 AM UTC
If <xsl:value-of select='eventDate'/> is currently returning 2006-05-21T20:00:00.0000000-04:00

Then in the substring calls replacing the "." with "eventDate" should do it.

4 replies

Correct answer
Apr 19, 2006 2:42 AM UTC
If <xsl:value-of select='eventDate'/> is currently returning 2006-05-21T20:00:00.0000000-04:00

Then in the substring calls replacing the "." with "eventDate" should do it.
Translate
mr. modusAuthor
Inspiring
Apr 19, 2006 11:57 AM UTC
Thanks so much TCloney. Works great.

You don't happen to know how to to do alternating row color do you?
The CF equivalent would be IIF(currentRow MOD 2....
Translate
Apr 16, 2006 5:58 PM UTC
This would seem to work

<xsl:element name="formatted_date">
<xsl:value-of select="substring(., 6, 2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring(., 9, 2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring(., 1, 4)"/>
<xsl:text> </xsl:text>
<xsl:if test="substring(., 12, 2) &lt; 13">
<xsl:value-of select="substring(., 12, 2)"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="substring(., 15, 2)"/>
<xsl:text> AM</xsl:text>
</xsl:if>
<xsl:if test="substring(., 12, 2) > 12">
<xsl:if test="substring(., 12, 2) > 21">
<xsl:value-of select="number(substring(., 12, 2)) - 12"/>
</xsl:if>
<xsl:if test="substring(., 12, 2) &lt; 22">
<xsl:text>0</xsl:text><xsl:value-of select="number(substring(., 12, 2)) - 12"/>
</xsl:if>
<xsl:text>:</xsl:text>
<xsl:value-of select="substring(., 15, 2)"/>
<xsl:text> PM</xsl:text>
</xsl:if>
</xsl:element>
Translate
mr. modusAuthor
Inspiring
Apr 18, 2006 8:56 PM UTC
Thanks for the reply. How do I get it to parse the actual eventDate value in the XML?
I pasted what you posted in place of <xsl:value-of select='eventDate'/> and I get values like:
Da/e /
Ni/e /
Ne/ Y/

What am I doing wrong? Sorry for being such a XSL newbie.
Translate