在xsl中将dd / mm / yy转换为dd-MM-YYYY格式 [英] Convert dd/mm/yy to dd-MM-YYYY format in xsl
问题描述
谢谢您的支持。
我的日期格式为 dd / MMM / YY
和需要使用 XSL
转换为另一种格式 dd-MM-YYYY
。
I have the date formats as dd/MMM/YY
and need to be converted into the another format dd-MM-YYYY
using XSL
.
这里的问题是,年份为短格式,需要转换为长格式。如何确定年份?
The problem here is, year is in short format need to be converted into long format. How can the year be determined ?
这里有几个例子,
dd/MMM/YY - dd-MM-YYYY
01/FEB/91 - 01-02-1991.
13/APR/13 - 13-04-2013.
使用字符串操作, XSL
可以是转换为长格式,但无法确定实际年份。
Using string manipulations,XSL
it can be converted to long format but actual year cannot be determined.
例如
01 / FEB / 91
可以转换为 01-02-1991
或 01-02-2091
使用字符串函数。
01/FEB/91
can be converted to 01-02-1991
or 01-02-2091
using string functions.
那么,如何使用 XSL 1.0或XSL 2.0
获取实际日期?
So, how to get the actual date using XSL 1.0 or XSL 2.0
?
推荐答案
您需要考虑您的要求。 XSLT无法知道01 / FEB / 91表示01-02-1991还是01-02-2091或01-02-1891。您需要确定截止日期在哪里。
You need to think about what you're asking. XSLT has no way of knowing whether 01/FEB/91 means 01-02-1991 or 01-02-2091 or 01-02-1891. You need to decide where the cutoff year is.
您可以将截止日期定为2013年,并执行以下操作:
You could make the cutoff 2013 and do this:
<xsl:variable name="longYear"
select="$shortYear + 2000 - (100 * ($shortYear > 13))" />
这将导致小于或等于13的年份为20XX,大于13的年份为19XX
This will result in 20XX for years less than or equal to 13, and 19XX for years greater than 13.
在其自己的模板中:
<xsl:template name="LongYear">
<xsl:param name="shortYear" select="." />
<xsl:param name="cutoff" select="13" />
<xsl:value-of select="$shortYear + 2000 - (100 * ($shortYear > $cutoff))" />
</xsl:template>
您可以通过以下方式调用:
Which you can invoke with:
<xsl:call-template name="LongYear">
<xsl:with-param name="shortYear" select="substring(Date, 8, 2)" />
</xsl:call-template>
这篇关于在xsl中将dd / mm / yy转换为dd-MM-YYYY格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!