XSLT transformation datetime to date format
Posted
by freggel
on Stack Overflow
See other posts from Stack Overflow
or by freggel
Published on 2009-01-28T14:21:01Z
Indexed on
2010/03/23
18:53 UTC
Read the original article
Hit count: 518
I'm trying to transform a datetime to a date format yyyy-MM-dd, because I'm using the xsd.exe tool the xs:date datatypes are automatically changed into a datetime datatype, because there is no type in the .NET Framework that matches the type xs:date completely.
But I can't get it to work
<articles>
<article>
<articleid>48992</articleid>
<deliverydateasked>2009-01-29T00:00:00+01:00</deliverydateasked>
</article>
<article>
<articleid>48993</articleid>
<deliverydateasked>2009-01-30T00:00:00+01:00</deliverydateasked>
</article>
</articles>
trying to convert the xml to
<articles>
<article>
<articleid>48992</articleid>
<deliverydateasked>2009-01-29</deliverydateasked>
</article>
<article>
<articleid>48993</articleid>
<deliverydateasked>2009-01-30</deliverydateasked>
</article>
</articles>
currently I'm using this XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<articles>
<xsl:apply-templates select="article">
</xsl:apply-templates>
</articles>
</xsl:template>
<xsl:template name="FormatDate">
<xsl:param name="DateTime" />
<xsl:variable name="date">
<xsl:value-of select="substring-before($DateTime,'T')" />
</xsl:variable>
<xsl:if test="string-length($date) != 10">
<xsl:value-of select="$DateTime"/>
</xsl:if>
<xsl:if test="string-length($date) = 10">
<xsl:value-of select="$date"/>
</xsl:if>
</xsl:template>
<xsl:template match="article">
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="deliverydateasked"/>
</xsl:call-template>
</xsl:template>
Does anyone know a good xslt transformation.
Thanks in advance
The output result of my code is
<articles />
© Stack Overflow or respective owner