我在 XML 文件中有一个日期(字符串)值,格式如下:
Tue Apr 17 03:12:47 IST 2012
我想使用 XSL 转换将字符串/日期转换成这种格式:
4/17/2012 03:12:47 AM
如何在我的 XSL 转换中做到这一点?
最佳答案
如果你正在使用
XSLT 1.0 版本,使用 EXSLT - date:format-date 日期扩展
XSLT 2.0 版本,使用 built-in: Formatting Dates and Times 日期扩展
但我的建议是
Have a standard XSD datetime format on XML, on the code-behind (that is, on rendering time) you can format as you like.
更新:
始终通过 XSLT 处理 XML,日期应采用标准 XSD 格式。目前您的输入不是标准格式,因此会引发错误。
示例:
<xsl:variable name="dt" as="xs:dateTime" select="xs:dateTime('2012-10-21T22:10:15')"/>
<xsl:value-of select="format-dateTime($dt, '[Y0001]/[M01]/[D01]')"/>
输出:
2012/10/21
关于xml - 将字符串转换为 XSLT 中的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16892344/