格式通过XSLT在XML的日期 [英] Format a date in XML via XSLT

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

问题描述

当我使用XML序列化序列化的DateTime ,它是写在格式如下:

When I use the XML serializer to serialize a DateTime, it is written in the following format:

<Date>2007-11-14T12:01:00</Date>

在通过XSLT样式表输出HTML通过这个,我怎么能格式化这个?在大多数情况下,我需要的只是时间,而当我需要的时候我当然不希望搞笑T在里面。

When passing this through an XSLT stylesheet to output HTML, how can I format this? In most cases I just need the date, and when I need the time I of course don't want the "funny T" in there.

推荐答案

下面是一对夫妇的1.0模板,你可以使用: -

Here are a couple of 1.0 templates that you can use:-

<xsl:template name="formatDate">
	<xsl:param name="dateTime" />
	<xsl:variable name="date" select="substring-before($dateTime, 'T')" />
	<xsl:variable name="year" select="substring-before($date, '-')" />
	<xsl:variable name="month" select="substring-before(substring-after($date, '-'), '-')" />
	<xsl:variable name="day" select="substring-after(substring-after($date, '-'), '-')" />
	<xsl:value-of select="concat($day, ' ', $month, ' ', $year)" />
</xsl:template>

<xsl:template name="formatTime">
	<xsl:param name="dateTime" />
	<xsl:value-of select="substring-after($dateTime, 'T')" />
</xsl:template>

通过打电话给他们: -

Call them with:-

	<xsl:call-template name="formatDate">
		<xsl:with-param name="dateTime" select="xpath" />
	</xsl:call-template>

	<xsl:call-template name="formatTime">
		<xsl:with-param name="dateTime" select="xpath" />
	</xsl:call-template>

,其中XPath是路径的元素或属性,有标准的日期和时间格式。

where xpath is the path to an element or attribute that has the standard date time format.

这篇关于格式通过XSLT在XML的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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