This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]