xslt中的时间计算

xslt中的时间计算,xslt,Xslt,我使用的是XSL2.0版 我有一个需要添加1的时间域。 我正在从以下节点获取格式化的编号: <xsl:value-of select="Master/End/Timecode"/> <xsl:text> “Master/End/Timecode”中的数据看起来像01:00:00:00 基本上是时间--小时:分钟:秒:帧 帧是从oo到23的计数。如何将1添加到帧中,并在帧=23时使秒和分钟递增 示例01:00:59:23加1将得到01:01:00:00

我使用的是XSL2.0版

我有一个需要添加1的时间域。 我正在从以下节点获取格式化的编号:

    <xsl:value-of select="Master/End/Timecode"/>
    <xsl:text>

“Master/End/Timecode”中的数据看起来像01:00:00:00 基本上是时间--小时:分钟:秒:帧 帧是从oo到23的计数。如何将1添加到帧中,并在帧=23时使秒和分钟递增

示例01:00:59:23加1将得到01:01:00:00的结果。
任何想法

这听起来像是你想写的东西,或者。有几种方法可以实现这一点,但它们变得非常复杂,非常迅速。

只需将其转换为帧,递增,然后再转换回:

  <xsl:analyze-string select="Master/End/Timecode" regex="^(\d+):(\d+):(\d+):(\d+)$">
    <xsl:matching-substring>

      <!-- Split into components -->
      <xsl:variable name="hours"
                    select="xs:integer(regex-group(1))"/>
      <xsl:variable name="minutes"
                    select="xs:integer(regex-group(2))"/>
      <xsl:variable name="seconds"
                    select="xs:integer(regex-group(3))"/>
      <xsl:variable name="frames"
                    select="xs:integer(regex-group(4))"/>

      <!-- Calculate total amount of frames -->
      <xsl:variable name="total-frames"
                    select="$hours * 60 * 60 * 24 +
                            $minutes * 60 * 24 +
                            $seconds * 24 +
                            $frames "/>

      <!-- Add 1 frame -->
      <xsl:variable name="remaining-frames"
                    select="$total-frames + 1"/>

      <!-- Calculate new component values -->
      <xsl:variable name="new-hours"
                    select="$remaining-frames idiv (60 * 60 * 24)"/>
      <xsl:variable name="remaining-frames"
                    select="$remaining-frames mod (60 * 60 * 24)"/>
      <xsl:variable name="new-minutes"
                    select="$remaining-frames idiv (60 * 24)"/>
      <xsl:variable name="remaining-frames"
                    select="$remaining-frames mod (60 * 24)"/>
      <xsl:variable name="new-seconds"
                    select="$remaining-frames idiv 24"/>
      <xsl:variable name="new-frames"
                    select="$remaining-frames mod 24"/>

      <!-- Recombine components -->
      <xsl:value-of select="$new-hours"/>
      <xsl:text>:</xsl:text>
      <xsl:value-of select="$new-minutes"/>
      <xsl:text>:</xsl:text>
      <xsl:value-of select="$new-seconds"/>
      <xsl:text>:</xsl:text>
      <xsl:value-of select="$new-frames"/>

    </xsl:matching-substring>
  </xsl:analyze-string>

:
:
:

以HH:mm:ss:ff为单位的正确转换算法毫秒(SSS) 上述情况并非如此

Developed an algorithm: z = 8415
ch=z idiv (60*60*25)
m=(z-ch*60*60*25) idiv (60*25)
s=(z-ch*60*60*25-m*60*25) idiv 25
f=(z-ch*60*60*25-m*60*25-s*25)

Total: 0:5:36:15

这是我的XSLT时间码库可以完成的事情:。 使用它,您可以执行以下操作:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:tc="http://screenstaring.com/xslt/timecode">

<xsl:import href="timecode.xsl"/>

<xsl:call-template name="tc:add">
  <xsl:with-param name="timecode1">01:00:00:00</xsl:with-param>
  <xsl:with-param name="timecode2">00:00:00:01</xsl:with-param>
</xsl:call-template>

<!-- Or -->

<xsl:variable name="frames">
  <xsl:call-template name="tc:to-frames">
    <xsl:with-param name="timecode">01:00:00:00</xsl:with-param>
    <xsl:with-param name="fps">23.97</xsl:with-param>
  </xsl:call-template>
</xsl:variable>

<xsl:variable name="plus-one">
  <xsl:call-template name="tc:from-frames">
    <xsl:with-param name="frames" select="$frames + 1"/>
    <xsl:with-param name="fps">23.97</xsl:with-param>
  </xsl:call-template>
</xsl:variable>

01:00:00:00
00:00:00:01
01:00:00:00
23.97
23.97

遗憾的是,您不能只加1,尽管
乘法
除法
支持整数操作数,因此
加法
可能也支持它

命令分析字符串和正则表达式对sablotron处理器有效吗?不,sablotron是XSLT1.0处理器<代码>分析字符串和朋友都是XSLT2.0的组成部分。也就是说,您在问题中特别提到您正在使用XSLT2.0,所以现在我感到困惑,因为您不可能使用Sablotron来实现它。边走边学。我将寻找xslt处理器并重试。非常感谢您的帮助。唯一像样的XSLT2.0处理器是Saxon,IMO()。也有Altova,但速度较慢且不跨平台。