Name
[2.0] current-date()
Returns the current date as an xs:date
value.
Syntax
xs:datecurrent-date(
)
Inputs
None.
Output
An xs:date
value set to
the current time on the system. The returned value is set to the
default timezone. (You can get the details of the default timezone
with the implicit-timezone()
function).
The current-date()
function returns the same value throughout the
processing of the stylesheet. If you call current-date()
a dozen times
throughout your stylesheet, the function returns the same value
each time.
Defined in
XQuery 1.0 and XPath 2.0 Functions and Operators section 16, “Context Functions.”
Example
Here is a stylesheet that displays the current date. It uses
the current-date()
, format-date()
,
and implicit-timezone()
functions.
<?xml version="1.0"?> <!-- current-date.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>The current date is </xsl:text> <xsl:value-of select="format-date(current-date(), '[FNn], the [D1o] of [MNn], [Y01]')"/> <xsl:text>

The implicit timezone for the </xsl:text> <xsl:text>current context is: </xsl:text> <xsl:value-of select="implicit-timezone()"/> <xsl:text>

The timezone extracted from the </xsl:text> <xsl:text>current date is: </xsl:text> <xsl:value-of select="timezone-from-date(current-date())"/> </xsl:template> </xsl:stylesheet>
Here are the stylesheet’s results:
The current date is Thursday, the 6th of July, 06 The implicit ...
Get XSLT, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.