4 Replies Latest reply on Apr 19, 2006 4:57 AM by mr. modus

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

    mr. modus Level 1
      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.

        • 1. Re: Using XSL to format a date. I'm soooo lost.
          tconley
          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>
          • 2. Re: Using XSL to format a date. I'm soooo lost.
            mr. modus Level 1
            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.
            • 3. Re: Using XSL to format a date. I'm soooo lost.
              tconley Level 1
              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. Re: Using XSL to format a date. I'm soooo lost.
                mr. modus Level 1
                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....