Skip to content
Autana Business Partners

XSL Snippets - Add Date with XSL 1.0 and 2.0

Published on 1 min read

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" ........ >

Updated on

Tags

← Back to the blog

  • Data Management

    Optimization of energy consumption

    Discover how the optimization of energy consumption reduces costs and environmental impact. Learn to analyze data, simulate scenarios, and implement energy-saving strategies.

    Read article

  • Analytics

    Talent retention in the digital age: how analytics can help

    Learn how talent retention in the digital age benefits from analytics. Discover how data helps reduce turnover and retain your top employees.

    Read article

  • Success Stories

    Proyect Sourcing Optimization

    In the digital age, Project Sourcing Optimization has become essential for companies aiming to enhance their purchasing processes. By integrating data-driven decision-making and…

    Read article