问题描述:

I have two variables with putdate and puttime(format is HHMMSSTH). These two variables are taken from mqmd header.

<xsl:variable name="putdate">

<xsl:value-of select="'20051114'"/>

</xsl:variable>

<xsl:variable name="puttime">

<xsl:value-of select="'10594016'"/>

</xsl:variable>

The format of puttime is 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).

I have a third variable, incrementtime, which is in milliseconds, in this case it is 1990 milliseconds. What I need the xslt to do is add the value 1990 milliseconds to the puttime, I guess the below are the steps

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

The resultant time is 10594315. The output of the xslt should be "2005-11-14 10:59:42:15"(In GMT actually), converted to Mountain Time.

网友答案:

XSLT 1.0 does not have any built-in support for time values. To be able to add to time values, you have to implement all the overflow logic yourself.

  • Fractions ≥ 100 ⇒ Increment seconds
  • Seconds ≥ 60 ⇒ Increment minutes
  • Minutes ≥ 60 ⇒ Increment hours
  • Hours ≥ 24 ⇒ Increment days
  • Days ≥ 28, 29, 30 or 31 ⇒ Increment months
  • Months ≥ 12 ⇒ Increment years

And then you also have to handle DST rules, or the value will be messed up when the switch date is passed. If you do manage to implement it, it will end up being a huge, unmaintainable chunk of code.

In XSLT 2.0 you have the xs:dateTime type (and similar) that can do the calculations for you. It would be much simpler to do it in XSLT 2.0, or even an imperative programming language (Java, C#, Python, etc.).

相关阅读:
Top