开发者

Xslt code to get minutes past

I get an xml from SQL. The xml has a node that contains开发者_JS百科 date time information. The xml is getting transformed using xslt. I need to calculate the minutes past in the xslt.

For example, in the xml i have the below node:

2011-08-28T22:11:52.383-07:00

I need to take current time as reference and caculate how many minutes passed by from the date that is there in the xml node. Appreciate your help.

Thanks


This transformation:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
   Current time: <xsl:sequence select="current-dateTime()"/>

   Elapsed minutes since: <xsl:sequence select="string(/)"/>:

   <xsl:sequence select=
   "(current-dateTime() - xs:dateTime(/) )
    div
     xs:dayTimeDuration('PT1M')
     "/>

 </xsl:template>
</xsl:stylesheet>

when applied on this XML document:

<t>2011-08-28T22:11:52.383-07:00</t>

produces the wanted, correct result:

   Current time: 2011-08-29T21:28:27.153-07:00

   Elapsed minutes since: 2011-08-28T22:11:52.383-07:00:

   1396.5795

Explanation: The elapsed minutes are calculated as the result of division of two durations:

  1. The time difference between now and the specified date-time, and
  2. The xs:dayTimeDuration value of exactly one minute.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜