File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Display current date/time in xsl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Display current date/time in xsl" Watch "Display current date/time in xsl" New topic

Display current date/time in xsl

JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303
I have an xml document which uses xsl for transformation to excel.

in the xsl document, i need to also write code to display the current date/time in the format - {$DD-Mmm-YYYY 24HH:MN:SS TZN}" timestamp unwrapped. TZN is user's time zone.

I actually get the idea to use xs:datetime, however, i am unfamiliar with the usage in xsl. Could someone please help me with the syntax?

SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

There isn't any function in XSLT 1.0 to produce the current timestamp.
Dmitrij Beloborodov

Joined: Mar 09, 2010
Posts: 2
For XSLT 2.0 you have a wealth of date functions, i.e.:

as well as current-date() and current-time().

For XSLT 1 you'll have to use the dates-and-times EXSLT extension package. Here's a usage example for XSLT 1:

The only problem is get date in specific format.
Dmitrij Beloborodov

Joined: Mar 09, 2010
Posts: 2
This solution worked out for me. It might help you:

smee bond
Ranch Hand

Joined: Sep 29, 2007
Posts: 34
Thanks for posting the solution Dmitrij Beloborodov. It helped me resolve my problem too!
I agree. Here's the link:
subject: Display current date/time in xsl
It's not a secret anymore!