user1679378
user1679378

Reputation: 1410

DateTime Conversion in XSLT

How can I changes the below xml timestamp attribute value to xs:dateTime Format.

<TimeValidations>
<timestamp>2017-01-30 09:30:10</timestamp>
</TimeValidations>

I need to convert timestamp attribute value(2002-05-30 09:30:10) to ISO 8601 format like

2017-01-30T09:30:10(xs:dateTime) 

in XSLT 1.0.Can anyone help me to do this conversion?

Upvotes: 0

Views: 203

Answers (1)

Stephan Lechner
Stephan Lechner

Reputation: 35164

Maybe I'm thinking in a too simple way, but if your format differs from the desired format always only in the T seperating date and time parts, you could use translate-function:

<xsl:template match="/TimeValidations/timestamp">
  <xsl:value-of select="translate(.,' ', 'T')"/>
</xsl:template>

When applied to your xml, it yields 2017-01-30T09:30:10. Of course, you could then use this to construct an xs:datetime value.

Upvotes: 1

Related Questions