This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Date Function to get System Date using XSLT 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 "Date Function to get System Date using XSLT" Watch "Date Function to get System Date using XSLT" New topic

Date Function to get System Date using XSLT

vishme vish

Joined: Jun 07, 2005
Posts: 7
Hi Everyone,

I have an xml file. and i need to generate the html page out of it. I am using XSLT to achieve this. But When ever the page is rendered the user should get the current date. Can any one please explain how Can i achieve this using XSLT.

Thanks in Advance
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

There's no way I can think of using standard XSLT. Not surprising really - XSLT is not really the technology you would use to make calls to the OS to get data like this. Its just a transformation mechanism.

That being said, depending on how you are performing the transformation, you might be able to find an extenstion which can do it (this for example claims to do it).

Alternatively, you could just render a bit of JavaScript which writes the current date in your HTML.
[ June 21, 2005: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jessica Tan

Joined: Mar 01, 2005
Posts: 11

Using the exslt functions in xslt 1.0 is not very hard. Here's what to do:

1) download the date and numerical format material from
2) Put the following attribute in your xsl:stylesheet root element:

xmlns ate="";

3) put the following include at the top level of your document (right after the root element).
<xsl:include href="path-to-installed-the-exslt-elements/date.xsl" />

4) Add the function to your sheet where you want it to appear:

<xsl:when test="function-available('date ate-time')">
(<xsl:value-of select="date ate-time()"/>
<xsl therwise>
</xsl therwise>

The only problem I had when I did this, was there was a bad include in one of the exslt stylesheets (it was looking in the wrong directory for a padding stylesheet). It wasn't hard to fix, though.
I agree. Here's the link:
subject: Date Function to get System Date using XSLT
It's not a secret anymore!