• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
Apr 13, 2006 Apr 13, 2006

Copy link to clipboard

Copied

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.

TOPICS
Advanced techniques

Views

494

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Apr 18, 2006 Apr 18, 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.

Votes

Translate

Translate
Guest
Apr 16, 2006 Apr 16, 2006

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 18, 2006 Apr 18, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 18, 2006 Apr 18, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2006 Apr 19, 2006

Copy link to clipboard

Copied

LATEST
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....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation