RE: [xsl] date formating

Subject: RE: [xsl] date formating
From: "Roman Kisin" <rkisin@xxxxxxxxxxx>
Date: Fri, 17 Aug 2001 12:21:49 -0700
I'm a new to this list so I don't know what XSLT processor you are talking
about but I'd suspect that node is passed into your extension function.
I use Xalan processor and the way it would work is that for
<xsl:variable name="moreover-date"
      select="harvest_time" />
if would store a node/Element in the variable.
Easiest fix I think would be change it to look like:
<xsl:variable name="moreover-date">
	<xsl:value-of select="harvest_time" />
</xsl:variable>

In this case the text value is stored in the variable.

Thanks,
Roman

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Samina Islam
Sent: Friday, August 17, 2001 11:42 AM
To: xsl-list-digest@xxxxxxxxxxxxxxxxxxxxxx;
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] date formating


Hi All,

For some reason the parse method in SimpleDateFormat
class is not recognizing harvest_time value as a valid
string.  Does anyone know why?  It is giving me a
runtime error that says:

javax.xml.transform.TransformerException: Cannot
format given Object as a Date.


Again, my XML document looks like this:
<moreovernews>
  <article id="_23314341">
    <url>http://c.moreover.com/</url>
    <harvest_time>Aug 15 2001 1:07PM</harvest_time>
  </article>

...

In my XSL stylesheet I have this:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:DateFormat="myDateFormat"
    extension-element-prefixes="DateFormat">

...

<xsl:variable name="moreover-date"
      select="harvest_time" />
<xsl:value-of select= "DateFormat:transformDate(
        $moreover-date,
        'yyyy-MM-dd&apos;T&apos;HH:mm:ssz',
        'MMM dd yyyy hh:mma' )" />

...


myDateFormat java class looks like this:

import java.util.*;
import java.text.*;

public class myDateFormat {

   public SimpleDateFormat init(
            String isoDate,
            TimeZone tz) {

       SimpleDateFormat prismDate = new
           SimpleDateFormat(isoDate);
       prismDate.setTimeZone(tz);
       return prismDate;
   }

   public String transformDate(
            String moreoverTime,
            String isoDateFormat,
            String oldDateFormat) {

       SimpleDateFormat moreoverDate = new
            SimpleDateFormat(oldDateFormat);

       TimeZone tz = new SimpleTimeZone(0, "Z");
       SimpleDateFormat prismDate =
             this.init(isoDateFormat,tz);

       ParsePosition pp = new ParsePosition(0);
       moreoverDate.parse(moreoverTime, pp);
       String isoDate =
prismDate.format(moreoverTime);

       return isoDate;
   }
}

Any suggestions on why this is happening will be
great!!  Thanks!

Samina

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

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



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


Current Thread