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

Re: scripting

Subject: Re: scripting
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 15 Aug 2001 17:25:24 +0100
date parse date
Hi Samina,

> I'm converting an xml document to a prism document using a
> stylesheet. One of the elements in the XML document is date, which
> is given in "MM DD YYYY H:MM" format (example: "Jul 10 1999
> 9:10AM"). I want the date to be formated w/ the year first (ex:
> "1999-7-10 9:10AM" ). Can I change my XSL stylesheet to do this? Do
> I need to use bean scripting/java scripting? Is this compatible w/
> JAXP?

As Aleksei said, the most efficient portable method is to write
yourself a template that uses the string manipulation functions
available in XSLT to do a specific conversion between the two date
formats you're dealing with.

If you don't care about portability between processors, then you could
use extension functions to do the conversion or use existing Java
methods. How you use these depends on your processor and what methods
it supports for defining extension functions.

If you care about portability, but don't particularly care about
efficiency and just want to get the job done with the minimal amount
of work, I've just completed a couple of templates for parsing and
formatting dates that you might find useful for a pure XSLT solution.
The stylesheets with them in are at:

  http://www.exslt.org/date/functions/parse-date/date.parse-date.template.xsl
  http://www.exslt.org/date/functions/format-date/date.format-date.template.xsl

To use them, you need to declare the EXSLT - Dates and Times namespace
and import the two stylesheets:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:date="http://exslt.org/dates-and-times"
                extension-element-prefixes="date">

<xsl:import href="date.parse-date.template.xsl" />
<xsl:import href="date.format-date.template.xsl" />

...
                
</xsl:stylesheet>

You can then reformat your dates using something like:

  <xsl:variable name="iso-8601-dateTime">
    <xsl:call-template name="date:parse-date">
      <xsl:with-param name="date-time" select="$date" />
      <xsl:with-param name="format" select="'MMM DD yyyy h:mma'" />
    </xsl:call-template>
  </xsl:variable>
  <xsl:call-template name="date:format-date">
    <xsl:with-param name="date-time" select="$iso-8601-dateTime" />
    <xsl:with-param name="format" select="'yyyy-M-DD h:mma'" />
  </xsl:call-template>

The date format strings use characters in the same way as
java.text.SimpleDateFormat.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread
  • scripting
    • Samina Islam - Wed, 15 Aug 2001 08:59:34 -0400 (EDT)
      • Aleksei Valikov - Wed, 15 Aug 2001 09:15:32 -0400 (EDT)
        • cutlass - Wed, 15 Aug 2001 11:16:22 -0400 (EDT)
      • Jeni Tennison - Wed, 15 Aug 2001 12:34:51 -0400 (EDT) <=

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.