Altova Mailing List Archives

Re: [xsl] current-dateTime()

From: Abel Braaksma <>
Date: 4/18/2008 2:40:00 PM
Andrew Welch wrote:
I wrongly thought that the "implementation dependent" part meant the
processor could return different values for multiple calls to
current-dateTime()... instead of merely the freedom to choose the
instant at which it takes the fixed value.

It should be straightforward to write an extension function instead...


it may be tempting to write an extension function, but that binds you to 
a certain implementation and it really is unnecessary. It'd be nicer to 
get the current time/date at any moment of processing by means of 
standard XSLT / XPath functionality. This discussion thread makes it 
seem that such a thing is not possible, but, with a little help from the 
Internet, it actually is possible.

This is a short version of a related post of my, about one and a half 
years back.


 1) XSLT 2.0 processor that supports the document() function with the 
the HTTP URI scheme

 2) An internet (HTTP) source that returns the current time and date

 3) Access to that source (configure your firewall if necessary)

 4) a little effort to make XSLT 2.0 act non-pure-functional

I assume for the moment that 1-3 are easy to grasp and arrange. Nr 4 may 
need a little help:

<xsl:function name="my:randomString" as="xs:string">
    <xsl:variable name="node">
        <xsl:comment />
    <xsl:sequence select="generate-id($node)" />

<xsl:function name="my:current-DateTime" as="xs:dateTime">

   <xsl:variable name="dateTimeUrl" 
select="concat('http://yourtimesite/', my:randomString())" />

   <xsl:sequence select="document($dateTimeUrl)/currentDateTimeNode" />


There are obvious drawbacks and caveats to this solution, one being that 
the Net overhead is significant, the other being that the dependencies 
on external systems may be a larger problem to deal with then an 
extension function. But whatever it is, the point I was trying to make 
is that you can get the current date or time at the current execution 
point (regardless the ordered or unordered execution of the stylesheet) 
without using anything non-XSLT-like (I won't say non-declarative like, 
simply because the side effects I employ are not part of declarative 

A time server can return either an XML document or, easier, a simple 
string. Then you'd use the unparsed-text() function.

-- Abel Braaksma


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.