Question

I have the following in xslt

<?xml version="1.0" encoding="UTF-8"?>
<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/02/xpath-functions" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:variable name="cDate">
        <xsl:value-of select="current-dateTime()"/>
    </xsl:variable>
    <xsl:variable name="fcDate">
        <xsl:value-of select="format-dateTime($cDate,'[Y0001][M01][D01]')"/>
    </xsl:variable>
    <xsl:template match="/PublisherBooking">
        <dt>
            <xsl:attribute name="date"><xsl:value-of select="$fcDate"/></xsl:attribute>
        </dt>
    </xsl:template>
</xsl:stylesheet>

which gives me the output (given the current date is 12 Jan 2010):

<?xml version="1.0" encoding="UTF-8"?>
<dt date="2010112"/>

My problem is that i need the format to read as follows:

<?xml version="1.0" encoding="UTF-8"?>
<dt date="20100112"/>

So how do i get the zero padding on the month and day? Specifically what is wrong with the format picture '[Y0001][M01][D01]'.

FYI I am using the XSLT engine that ships with XMLSpy 2005.

Was it helpful?

Solution

Well, it looks like a bug in the engine that ships with my version of XMLSpy (2005 and a bit long in the tooth). Ran the transformation against Saxon 9.2 and the result was as required.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top