在 XSLT 中将字符串转换为日期格式 [英] Convert a string to Date format in XSLT

查看:39
本文介绍了在 XSLT 中将字符串转换为日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此格式的 XML 文件中有一个日期(字符串)值:

I have a date(string) value in an XML file in this format:

Tue Apr 17 03:12:47 IST 2012

我想使用 XSL 转换将字符串/日期转换成这种格式:

I want to use XSL transformation to convert the string/date into this format:

4/17/2012 03:12:47 AM

如何在我的 XSL 转换中做到这一点?

How can I do that in my XSL transform?

推荐答案

如果您正在使用

  • XSLT 1.0 version, use EXSLT - date:format-date date extension

XSLT 2.0 版本,使用内置:格式化日期和时间日期延长

XSLT 2.0 version, use built-in: Formatting Dates and Times date extension

但我的建议是

在 XML 上有一个标准的 XSD 日期时间格式,在代码隐藏(即渲染时间)上,您可以随意格式化.

更新:

总是通过 XSLT 处理 XML,日期应该是标准的 XSD 格式.目前您的输入不是标准格式,因此会引发错误.

Update:

Always XML to process through XSLT, dates should be in standard XSD format. Currently your input is not in standard format so that it throws error.

示例:

<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

这篇关于在 XSLT 中将字符串转换为日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆