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

Re: date formating

Subject: Re: date formating
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 17 Aug 2001 14:17:38 +0100
date simpledateformat
Hi Samina,

> I'm not too sure if this is the answer your looking for, but I'm
> using Xalan and Xerces packages.

Yes, that was the answer I was looking for. You can use Java methods
as extension functions in Xalan. You need to declare a namespace for
the class that you're using. The namespace points to the Java
implementation and assigns a namespace prefix for the functions that
you'll use.

The simplest way of doing so is by declaring the namespace in the
document element of the stylesheet, using the 'xalan' protocol e.g.:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:date="xalan://java.text.SimpleDateFormat"
                extension-element-prefixes="date">
...
</xsl:stylesheet>

You can then call the methods on that class as functions with the
date: prefix. You can create instances of a class using the a new()
function in that namespace. You need to create a SimpleDateFormat
object for the two date formats that you're using:

  <xsl:variable name="prism-date"
                select="date:new('MMM dd yyyy h:mma')" />
  <xsl:variable name="iso-date"
                select='date:new("yyyy-MM-dd&apos;T&apos;hh:mm:ssz")' />

Then you need to parse the harvest_time element using the $prism-date
SimpleDateFormat. You can call an instance method by passing the
instance as the first argument to the function:

  <xsl:variable name="date"
                select="date:parse($prism-date, harvest_time)" />

And format the result of that parse using the $iso-date
SimpleDateFormat:

  <xsl:value-of select="date:format($iso-date, $date)" />

Alternatively, you could write your own class/method in Java that does
the whole conversion, and then call that class/method in the same way
as above.

I haven't tested this, so some of it may be wrong. I've been looking
at the Java API to find out the methods available on
java.text.SimpleDateFormat [1] and the Xalan documentation to work out
how to call methods from there [2]. It's probably worth reading both
yourself.

Cheers,

Jeni

[1] http://java.sun.com/products/jdk/1.2/docs/api/java/text/SimpleDateFormat.html
[2] http://xml.apache.org/xalan-j/extensions.html

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


 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.