Skip to main content
Inspiring
April 13, 2006
Answered

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

  • April 13, 2006
  • 4 replies
  • 626 views
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 has been closed for replies.
Correct answer
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
April 19, 2006
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.
mr. modusAuthor
Inspiring
April 19, 2006
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....
April 16, 2006
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>
mr. modusAuthor
Inspiring
April 18, 2006
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.