Display current date in XML element

formatxslt

I'm using an XSL to transform one XML into another. My problem is that in one element I have to display the current date with the format:YYYYMMDD.

I tried using a variable like these:

<xsl:variable name="dateNow" select="current-dateTime()"/>
<xsl:variable name="dateNow2" select="current-date()"/>

And then tried to format then, but no success.

<FRUEHESTER_LIEFERTERMIN><xsl:value-of select="format-dateTime($dateNow, '[Y0001][M01][D01]')"/></FRUEHESTER_LIEFERTERMIN>

Best Solution

What exactly is happening (what does "no success" mean). What XSLT processor are you using?

Here is a minimal test case of what you are trying to do (input XML document doesn't matter)

    <?xml version="1.0" encoding="UTF-8"?>
&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"  exclude-result-prefixes="xs fn"&gt;

    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:variable name="dateNow" select="current-dateTime()"/>
    <xsl:variable name="dateNow2" select="current-date()"/>

    <xsl:template match="/">
        <FL><xsl:value-of select="format-dateTime($dateNow, '[Y0001][M01][D01]')"/></FL>
    </xsl:template>

</xsl:stylesheet>

and here is what it produces -- do you get the same if you try this test case?

<?xml version="1.0" encoding="UTF-8"?>
<FL>20120111</FL>
Related Question