[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Date conversion

Subject: RE: Date conversion
From: "Robert C. Lyons" <boblyons@xxxxxxxxxx>
Date: Wed, 1 Aug 2001 11:30:51 -0400
xml 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@xxxxxxxxxx'
     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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.