tags:

views:

562

answers:

4

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.

+1  A: 

Take a look at the XSLT concat function. In your case it would be something like this (untested):

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

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))"/>
Oded
+1  A: 

Try this

<xsl:value-of select="concat(substring($Date,7,2),substring($Date,5,2),substring($Date,1,4))"/>
ArsenMkrt
+2  A: 
<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)"/>
Darin Dimitrov