Reputation: 53
I need help on XSLT to reformat time, without much luck.
<names>
<name>
<foo id='x_date'>
<value> 01/23/2011 13:20:00 PDT</value>
</foo>
</name>
</names>
How will I change the date from '01/23/2011 01:23:00 PDT' to '01/23/2011 09:24:00 GMT+00:00' via XSLT?
Please help, it's killing me :-)
Upvotes: 1
Views: 846
Reputation: 220922
If you're open to use a non-XSLT solution using Java's Xalan extensions, for instance, you could opt for the date time functions as documented here:
http://exslt.org/date/index.html
Something along the lines of
<xsl:value-of select="
date:format-date(
date:parse-date(/names/name/foo/value, $inPattern),
$outPattern)" />
In your specific case, you'd probably have to implement your own date formatter in a custom namespace. This is quite simple:
package org.example;
public class MyExtension {
public static String myFormat(String date) {
// Do the formatting
}
}
<xsl:stylesheet xmlns:myextension="http://org.example.MyExtension">
..
<xsl:value-of select="myextension:myFormat(/names/name/foo/value)"/>
..
</xsl:stylesheet>
More documentation can be found here:
Upvotes: 1