Transform 20050416 to 2005-04-16

J

J-M Andersson

How can I transform.
<date>20050416</date>
to
<date>2005-04-16</date>


Today I do like this (but I guess there should be some better ways)

<xslt:template match="date">
<xslt:copy>
<xslt:value-of select="substring(.,1,4)"/>-
<xslt:value-of select="substring(.,5,2)"/>-
<xslt:value-of select="substring(.,7)"/>
</xslt:copy>
</xslt:template>
 
K

Keith Davies

J-M Andersson said:
How can I transform.
<date>20050416</date>
to
<date>2005-04-16</date>


Today I do like this (but I guess there should be some better ways)

<xslt:template match="date">
<xslt:copy>
<xslt:value-of select="substring(.,1,4)"/>-
<xslt:value-of select="substring(.,5,2)"/>-
<xslt:value-of select="substring(.,7)"/>
</xslt:copy>
</xslt:template>

<xsl:template match='date'>
<xsl:copy>
<xsl:value-of select='concat(substring(.,1,4),"-",
substring(.,5,2),"-",
substring(.,7,2))' />
</xsl:copy>
</xsl:template>

Not a *lot* better, mind. A little. XSLT is limited in its string-
processing capabilities.


Keith
 
J

J-M Andersson

Keith said:
<xsl:template match='date'>
<xsl:copy>
<xsl:value-of select='concat(substring(.,1,4),"-",
substring(.,5,2),"-",
substring(.,7,2))' />
</xsl:copy>
</xsl:template>

Not a *lot* better, mind. A little. XSLT is limited in its string-
processing capabilities.

Looks good to me, thanks for the hint.

/JM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top