我正在尝试使用格式日期函数来执行我认为是简单的XSLT转换。XSLT中的日期时间戳转换
我想将2012-01-18T11:47:41.877000000转换为YYYY/MM/DD格式。
所以我的样本数据集是:
<?xml version="1.0" encoding="UTF-8" ?>
<Users>
<User>
<FullName>Johnny Test</FullName>
<DateHired>2012-01-18T11:47:41.877000000</DateHired>
</User>
</Users>
,我试图与改造日期:
<xsl:for-each select="Users/User">
<xsl:for-each select="*">
<xsl:choose>
<xsl:when test="local-name()='DateHired'">
<Date>
<Value>
<xsl:value-of select="format-date(.,'YYYY/MM/DD')" />
</Value>
</Date>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
说实话,除了用于XML和M2M通信的ISO 8601外,别无他法。其他一切都是不好的。 –
xsl:当对元素名称进行测试时是反模式。使用apply-templates和与DateHired匹配的模板规则。 –