Hi everyone, I have a question regarding how to use xslt to format a
date so it gets into a CDATA tag in the resulting xml.
I have a date in my xml source document in the following format:
2005-07-06T10:32:21.1970000-04:00
In my XSLT I want to convert it to look like this:
<![CDATA[2004-06-14T01:00:00]]>
The xml source document looks like this:
<SomeDate>2005-07-06T10:32:21.1970000-04:00</SomeDate>
My xslt looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<MyMessage>
<Body>
<ActualizedDate>
<xsl:call-template name="standard_date">
<xsl:with-param name="date" select="/SomeDate"/>
</xsl:call-template>
</ActualizedDate>
</Body>
</MyMessage>
</xsl:template>
<xsl:template name="standard_date">
<xsl:param name="date" />
<xsl:variable name="date_length" select="string-length($date)" />
<xsl:if test="number($date_length) > 0">
![CDATA[
<!-- Year -->
<xsl:value-of select="substring($date, 1, 4)" />
<xsl:text>-</xsl:text>
<!-- Month -->
<xsl:value-of select="substring($date, 6, 2)" />
<xsl:text>-</xsl:text>
<!-- Day -->
<xsl:value-of select="substring($date, 9, 2)" />
T01:00:00
]] <xsl:text>></xsl:text>>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
The issue is that when I add a the the tags before the Cdata tag and
after, the xslt will not generate because it doesn't think it's valid
xml.
If I change my function from this:
![CDATA[
To
<![CDATA[
And the end from:
]] <xsl:text>></xsl:text>>
To
]] <xsl:text>></xsl:text>> >
results in the problem. Is there a way around this so I can generate it
into the tag so it looks like this: <![CDATA[2004-06-14T01:00:00]]>
?
TIA,
Magnus