Thomas Mann wrote:
using XSLT 2.0 I can get a timestamp with the following line:
<xsl:value-of select="current-dateTime()"/>
How can I format the date and the time ? For example I do not want the
milliseconds to be shown.
Well, check the XPath 2.0 function reference, it shows a function
http://www.w3.org/TR/xslt20/#function-format-dateTime
format-dateTime that should allow you to format the result returned by
current-dateTime().
Here is an example, the second argument to format-dateTime is a string
with a so called picture which in my view would better be called
formatting pattern:
<xsl:template match="/">
<xsl:variable name="now" select="current-dateTime()" />
<root>
<result-unformatted><xsl:value-of select="$now" /></result-unformatted>
<result-formatted picture="[Y]-[M]-[D]">
<xsl:value-of select="format-dateTime($now, '[Y]-[M]-[D]')" />
</result-formatted>
<result-formatted picture="[Y]-[M]-[D]T[H]:[m]:
">
<xsl:value-of select="format-dateTime($now,
'[Y]-[M]-[D]T[H]:[m]:')" />
</result-formatted>
</root>
</xsl:template>
An example output here on my machine with Saxon 8.1.1 is
<?xml version="1.0" encoding="UTF-8"?>
<root>
<result-unformatted>2004-10-14T12:27:39.921+02:00</result-unformatted>
<result-formatted picture="[Y]-[M]-[D]">2004-10-14</result-formatted>
<result-formatted
picture="[Y]-[M]-[D]T[H]:[m]:">2004-10-14T12:27:39</result-formatted>
</root>