Wednesday, 03 May 2017
autanabp
In this case, we will discuss a workaround in XSLT 1.0 for a native XSLT 2.0 function. to display the current date.
XSL is a language that together with XPath allows to describe how the information contained in any XML document should be transformed or formatted for presentation. With XSLT 2.0 we have at our disposal many more features than we had with version 1.0
So in XSLT 2.0 we have ways to do it naturally:
<xsl:value-of select=”current-dateTime()” />
<xsl:value-of select=”current-date()” />
However, with XSLT 1.0 we do not have advanced XPath functions, so only depending on third-party packages can we show the date.
Here are 2 different ways to achieve this:
- Downloading the EXSLT extension “Dates and Times” (http://exslt.org/date/index.html) which can be found on Github (https://github.com/exslt/exslt.github.io/tree/master/date).
- Extract date.xsl where we need to refer later to it in our header.
- Add in header (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 we work with Eclipse XSLT we can also use a Java function. We only need to import the corresponding reference in our header.
<xsl:value-of select=”java:util. Date.new()” />
We only need to import into our header
<xsl:stylesheet … xmlns:java=”java” …….. >
