This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Date conversion


Katie asks:
> The format of the date returned in my XML is 17-Dec-2000 07:23:31
> I need to display the date as 12/17/2000.
>
> How do I do this using xsl?

Katie,

You can do this as follows:

  <xsl:variable name="months"
                select="'JanFebMarAprMayJunJulAugSepOctNovDec'"/>

  <xsl:template match="date">
      <xsl:text>Old date: </xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>&#x0D;&#x0A;</xsl:text>

      <xsl:variable name="day" select="substring( ., 1, 2 )"/>
      <xsl:variable name="earlier_months"
                    select="substring-before( $months, substring( ., 4,
3 ))"/>
      <xsl:variable name="month_number"
                    select="string-length( $earlier_months ) div 3 + 1"/>
      <xsl:variable name="month"
                    select="format-number( $month_number, '00' )" />
      <xsl:variable name="year" select="substring( ., 8, 4 )"/>
      <xsl:text>New date: </xsl:text>
      <xsl:value-of select="concat( $month, '/', $day, '/', $year )"/>
      <xsl:text>&#x0D;&#x0A;</xsl:text>
  </xsl:template>

Hope this helps.

Bob

<sig name    = 'Bob Lyons'
     title   = 'XML Consultant'
     company = 'Unidex, Inc.'
     phone   = '+1-732-975-9877'
     email   = 'boblyons@unidex.com'
     url     = 'http://www.unidex.com/'
     product = 'XML Convert: transforms flat files to XML and vice versa' />


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]