A program we use in my office exports reports by translating a XML file it exports with an XSLT file into XHTML. I'm rewriting the XSLT to change the formatting and to add more information from the source XML File.
I'd like to include the date the file was created in the final report. But the current date/time is not included in the original XML file, nor do I have any control on how the XML file is created. There doesn't seem to be any date functions building into XSLT that will return the current date.
Does anyone have any idea how I might be able to include the current date during my XSLT transformation?
XSLT 1.0 does not provide any standard way to get the current date/time. You can call an extension function to do it (depends on your processor), or you can pass it to the stylesheet as the value of a parameter.
XSLT current() Function The current() function returns a node-set that contains only the current node. Usually the current node and the context node are the same.
The XSLT processor operates on two inputs: the XML document to transform, and the XSLT stylesheet that is used to apply transformations on the XML. Each of these two can actually be multiple inputs.
XSLT allows a stylesheet author to transform a primary XML document in two significant ways: manipulating and sorting the content, including a wholesale reordering of it if so desired, and transforming the content into a different format.
Date functions are available natively, such as:
<xsl:value-of select="current-dateTime()"/>
There is also current-date()
and current-time()
.
Use the EXSLT date and times extension package.
date.xsl
to the location of your XSL files.date.xsl
.For example:
<xsl:stylesheet version="1.0" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date" ...> <xsl:import href="date.xsl" /> <xsl:template match="//root"> <xsl:value-of select="date:date-time()"/> </xsl:template> </xsl:stylesheet>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With