我目前正在使用XML中的总帧数。我试图做的是在一段时间内转换它。我知道我的fps是30.我已经成功计算了我拥有的帧总数并将其转换为秒。我现在要做的是用hh:mm:ss格式改变这个总秒数。
以下是我的代码中的内容:
<!-- call in template time-calc and then divid by 30fps to calulate total seconds of time-->
<xsl:variable name="TotalDurationShow"><xsl:call-template name="time-calculation"></xsl:call-template></xsl:variable>
<xsl:variable name="TotalSeconds" select="$TotalDurationShow div 30"/>
<!-- Time-in-seconds to time in hh:mm:ss.000 form-->
<xsl:template name="secondsToTime">
<xsl:param name="seconds" />
<xsl:variable name="partHours" select="floor($seconds div 60 div 60)" />
<xsl:variable name="partMinutes" select="floor(($seconds - ($partHours * 60 * 60)) div 60)" />
<xsl:variable name="partSeconds" select="$seconds - ($partHours * 60 * 60) - ($partMinutes * 60)" />
<xsl:value-of select="concat(substring('0', 1, 2 - string-length(string( $partHours ))), $partHours)" /><xsl:text>:</xsl:text>
<xsl:value-of select="concat(substring('0', 1, 2 - string-length(string( $partMinutes ))), $partMinutes)" /><xsl:text>:</xsl:text>
<xsl:value-of select="concat(substring('0', 1, 2 - string-length(string( $partSeconds ))), $partSeconds)" />
</xsl:template>
<!-- test to make sure this is a number value in for total seconds
call in template secondstotime on totalseconds variable to convert to time code formate hh:mm:ss-->
<xsl:if test="$TotalSeconds != 0 and string(number($TotalSeconds)) != 'NaN'">
<xsl:variable name="TimeFrame"><xsl:call-template name="secondsToTime"><xsl:with-param name="seconds" select="$TotalSeconds" /></xsl:call-template></xsl:variable>
</xsl:if>
我收到一条错误消息,指出xsl:if不能是电子表格的子代。当我删除if的测试时,我收到一条错误消息,说明没有定义参数秒。我在变量totalseconds上调用模板secondstotime时是否做错了什么?
答案 0 :(得分:1)
如何转换我计算的总秒数 (此示例值为2670)并将其放入输出中 显示hh:mm:ss
假设:
<xsl:variable name="TotalSeconds" select="2670"/>
你可以使用:
<xsl:variable name="h" select="floor($TotalSeconds div 3600)"/>
<xsl:variable name="m" select="floor($TotalSeconds div 60) mod 60"/>
<xsl:variable name="s" select="$TotalSeconds mod 60"/>
<xsl:value-of select="concat(format-number($h, '00'), format-number($m, ':00'), format-number($s, ':00'))" />
返回:
00:44:30