Re: [xsl] problem converting date format

Subject: Re: [xsl] problem converting date format
From: "David N Bertoni/Cambridge/IBM" <david_n_bertoni@xxxxxxxxxx>
Date: Tue, 9 Apr 2002 09:10:34 -0700
I think you've got several problems.  One is your indices are incorrect for
substrings.  XPath indexes string starting at 1, not at 0.  This is also a
bad example, as it's hard to figure out whether you want MM-DD-YYYY or
DD-MM-YYYY.  For the former, this works:

<xsl:template name="DateTime">
             <xsl:param name="date"/>
             <xsl:value-of select="substring($date, 6, 2)" />
             <xsl:text>-</xsl:text>
             <xsl:value-of select="substring($date, 9, 2)" />
             <xsl:text>-</xsl:text>
             <xsl:value-of select="substring($date, 1, 4)" />
             <xsl:text> </xsl:text>
             <xsl:value-of select="substring($date, 12,2)"/>
             <xsl:text>:</xsl:text>
             <xsl:value-of select="substring($date,15,2)"/>
             <xsl:text>:</xsl:text>
             <xsl:value-of select="substring($date,18)"/>
             <xsl:text> GMT</xsl:text>
</xsl:template>

If you're only getting the literal text from your xsl:text elements, you
might check to make sure you're actually selecting something with
"//bem:eventDateTime".  Try adding <xsl:value-of select="$date"/> to the
DateTime template for debugging purposes.

Dave



                                                                                                                                               
                      "Serrell, Rachael"                                                                                                       
                      <rachael.serrell@xxxxxxxx>         To:      "'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'" <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>        
                      Sent by:                           cc:      (bcc: David N Bertoni/Cambridge/IBM)                                         
                      owner-xsl-list@xxxxxxxxxxx         Subject: [xsl] problem converting date format                                         
                      rrytech.com                                                                                                              
                                                                                                                                               
                                                                                                                                               
                      04/09/2002 06:27 AM                                                                                                      
                      Please respond to xsl-list                                                                                               
                                                                                                                                               
                                                                                                                                               



Hi, I've tried a few of the solutions on the FAQ but still can't get this
to work..what am i doing wrong? I'm not too good at params yet and this may
be why!

trying to convert :
<eventDateTime>2002-02-02T12:15:44</eventDateTime>

to output  '02-02-2002 12:15:44 GMT'

using:

<eventDateTime>
                 <xsl:call-template name="DateTime">
                    <xsl:with-param name="date" select
="//bem:eventDateTime"/>
           </xsl:call-template>
 </eventDateTime>

<xsl:template name="DateTime">
             <xsl:param name="date"/>
             <xsl:value-of select="substring($date, 7, 2)" />
             <xsl:text>-</xsl:text>
             <xsl:value-of select="substring($date, 5, 2)" />
             <xsl:text>-</xsl:text>
             <xsl:value-of select="substring($date, 3, 2)" />
             <xsl:value-of select="substring($date, 10,2)"/>
             <xsl:text>:</xsl:text>
             <xsl:value-of select="substring($date,12,2)"/>
             <xsl:text>:</xsl:text>
             <xsl:value-of select="substring($date,14)"/>
             <xsl:text> GMT</xsl:text>
</xsl:template>


but I only get the text result and the rest of the stylesheet after this
point doesn't process:

<eventDateTime>--:: GMT</eventDateTime>

can anyone help?
many thx








 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread