and I want the result to be 23122009

Xsl formatting date (substring + concatenation?)

I have an input

<Date value="20091223"/>

and I want the result to be

<Date>23122009</Date>

I tried to use the substring function to format the date

<xsl:value-of select="substring($Date,1,4)"/>

But how to combine the extracted year and months and day together.

+5
source share
4 answers

Assuming no spaces remain, just place them one by one:

<xsl:value-of select="substring($Date,7,2)"/>
<xsl:value-of select="substring($Date,5,2)"/>
<xsl:value-of select="substring($Date,1,4)"/>

If spaces are saved, just put them all on a line, with no spaces between them.

The Xpath concatenation function will also work, but I find it less readable:

<xsl:value-of select="concat(substring($Date,7,2), substring($Date,5,2), substring($Date,1,4))"/>
+5
source
<xsl:value-of select="substring(Date/@value, 7, 2)"/>
<xsl:value-of select="substring(Date/@value, 5, 2)"/>
<xsl:value-of select="substring(Date/@value, 1, 4)"/>
+2
source

concat XSLT . - (untested):

<xsl:value-of select="concat(substring($Date,1,4), substring($Date,7,2), substring($Date,5,2))"/>
+1

<xsl:value-of select="concat(substring($Date,7,2),substring($Date,5,2),substring($Date,1,4))"/>
+1

All Articles