Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xsl format date (substring + concatenate ?)

Tags:

c#

.net

xml

xslt

I have the input

<Date value="20091223"/>

and I want the output to be

<Date>23122009</Date>

I was trying to use substring function to reformat the date

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

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

like image 679
ala Avatar asked Dec 21 '09 08:12

ala


1 Answers

Assuming whitespace isn't preserved, just put them one after the other:

<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 whitespace is preserved, just put them all on the line, without 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))"/>
like image 184
Oded Avatar answered Sep 24 '22 14:09

Oded