我试图将日期时间转换为日期格式yyyy-MM-dd,因为我正在使用xsd.exe工具,而xs:date数据类型会自动更改为日期时间数据类型,因为在.NET Framework中没有完全匹配xs:date类型的类型。但是我无法使它正常工作。
<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>
尝试将XML转换为
<articles>
<article>
<articleid>48992</articleid>
<deliverydateasked>2009-01-29</deliverydateasked>
</article>
<article>
<articleid>48993</articleid>
<deliverydateasked>2009-01-30</deliverydateasked>
</article>
</articles>
目前我正在使用这个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>
有人知道一个好的XSLT转换吗?
提前感谢。
我的代码输出结果是:
<articles />