|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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'T'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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








