我刚刚开始学习XSLT,希望转换一些XML时间和日期数据,以便将其完全阐明。虽然我看到了将日期信息输出为单词(12到12月)的方法,但是我看不到任何可以将时间(6:30转换为六点三十)或将年份(2005转换为二千五百)的方法。
有一些标准的方法吗?如果不是,那么使用xsl:if这样做是否可行(如果冗长)?我可能可以将输入限制为四分之一小时。
那一年呢?
在XSLT 2.0中,可以使用format-date(),format-time()和format-dateTime()函数以多种方式格式化日期和时间,例如:
XML格式
<input>2014-04-30T15:45:12</input>
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<output>
<xsl:value-of select="format-dateTime(input,
'The [DWwo] Day of [MNn] in the Year [YWw], at [hWw] Hours and [mWv] Minutes [PN]'
)" />
</output>
</xsl:template>
</xsl:stylesheet>
结果
<?xml version="1.0" encoding="UTF-8"?>
<output>The Thirtieth Day of April in the Year Two Thousand and Fourteen, at Three Hours and Forty Five Minutes P.M.</output>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句