xslt时间日期转换

时间:2012-02-28 05:00:14

标签: xml xslt date xslt-1.0

我有两个变量putdate和puttime(格式为HHMMSSTH)。这两个变量取自mqmd头。

<xsl:variable name="putdate">
        <xsl:value-of select="'20051114'"/>
      </xsl:variable>
      <xsl:variable name="puttime">
        <xsl:value-of select="'10594016'"/>
      </xsl:variable>

puttime的格式是HHMMSSTH

HH
Hours (00 to 23)
MM
Minutes (00 to 59)
SS
Seconds (00 to 59)
T
Tenths of a second (0 to 9)
H
Hundredths of a second (0 to 9).

我有第三个变量,incrementtime,以毫秒为单位,在这种情况下是1990毫秒。我需要xslt做的是将值1990毫秒添加到puttime,我猜以下是步骤

1) Take the 10th value, which is 9(from 1990), then add to puttime's H, which makes it 10594025(9+6=15)
2)Take the 100th value, which is 9(from 1990), then add to puttimes's T, which makes it 10594115(9+2=11)
3)Take the 1000th value, which is 1(from 1990), then add to puttime's SS, which makes it 10594215

结果时间是10594315. xslt的输出应该是&#34; 2005-11-14 10:59:42:15&#34;(实际上是GMT),转换为山地时间。

1 个答案:

答案 0 :(得分:1)

XSLT 1.0没有任何内置的时间值支持。为了能够添加时间值,您必须自己实现所有溢出逻辑。

  • 分数≥100⇒增加秒数
  • 秒数≥60⇒递增分钟
  • 分钟≥60⇒增量小时
  • 小时≥24⇒增加天数
  • 天数≥28,29,30或31⇒增加月数
  • 月份≥12⇒增量年份

然后你还必须处理DST规则,否则当传递切换日期时,该值将被搞砸。如果你设法实现它,它将最终成为一个巨大的,无法维护的代码块。

在XSLT 2.0中,您有xs:dateTime类型(和类似的)可以为您进行计算。在XSLT 2.0中执行它,或者甚至是命令式编程语言(Java,C#,Python等)都会简单得多。