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

Re: Date Formating

Subject: Re: Date Formating
From: Elizabeth Barham <lizzy@xxxxxxxxxxxxxxxxx>
Date: 12 Jan 2003 09:21:05 -0600
month abbrev
Arthur writes:

>   I'm transforming an xml file that gives me a nicely formatted report
>   (html 80 odd pages).
>   Part of the transform uses format-number() for decimal places etc.
> 
>   one of the elements in the xml, is a date
>   <date-created>2003-01-12</date-created>
> 
>   How do you transform this to 12-Jan-03 ?

   I generally like to use look-up elements for this type of thing. In
version 1.1 you can place elements like:

<data>
  <month-names>
    <month sequence="1">Jan</month>
    <month sequence="2">Feb</month>
    <month sequence="3">Mar</month>
    <month sequence="4">Apr</month>
    <month sequence="5">May</month>
    <month sequence="6">Jun</month>
    <month sequence="7">Jul</month>
    <month sequence="8">Aug</month>
    <month sequence="9">Sep</month>
    <month sequence="10">Oct</month>
    <month sequence="11">Nov</month>
    <month sequence="12">Dec</month>
  </month-names>
</data>

in the stylesheet itself and use the "document('')" function. I
generally place this type of info in a separate file that is consulted
during the transformation. For this example, assume the above contents
are in a file entitled "data.xml":

  <xsl:template match="date-created">
    <!-- get each separate part of the date:
           YYYY-MM-DD
    -->

    <xsl:variable name="year">
      <xsl:value-of select="substring(., 3, 2)"/>
    </xsl:variable>
    <xsl:variable name="month">
      <xsl:value-of select="number(substring(., 6, 2))"/>
    </xsl:variable>
    <xsl:variable name="day">
      <xsl:value-of select="number(substring(., 8, 2))"/>
    </xsl:variable>
        
    <xsl:variable name="month-abbrev">
      <xsl:value-of select="document('data.xml')/data/month-names/month[@sequence =  $month]"/>
    </xsl:variable>

    <!-- and the output -->
    <xsl:value-of select="$day"/>
    <xsl:text>-</xsl:text>
    <xsl:value-of select="$month-abbrev"/>
    <xsl:text>-</xsl:text>
    <xsl:value-of select="$year"/>

   The document() function makes the document 'data.xml' just another
data set to work with.

   Elizabeth


 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.