假設你是在Muenchian grouping過程中,而不是:
<RunningTime><xsl:value-of select="sum(key('program-by-no', PNo)/RunningTime)"/></RunningTime>
做:
<RunningTime>
<xsl:call-template name="sum-times">
<xsl:with-param name="times" select="key('program-by-no', PNo)/RunningTime"/>
</xsl:call-template>
</RunningTime>
和下面的模板添加到您的樣式表:
<xsl:template name="sum-times">
<xsl:param name="times"/>
<xsl:param name="sum" select="0"/>
<xsl:choose>
<xsl:when test="$times">
<!-- add time as seconds -->
<xsl:variable name="summand" select="3600 * substring($times[1], 1, 2) + 60 * substring($times[1], 4, 2) + substring($times[1], 7, 2)"/>
<xsl:call-template name="sum-times">
<xsl:with-param name="times" select="$times[position() > 1]"/>
<xsl:with-param name="sum" select="$sum + $summand"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- convert seconds to time -->
<xsl:variable name="h" select="floor($sum div 3600)"/>
<xsl:variable name="m" select="floor($sum div 60) mod 60"/>
<xsl:variable name="s" select="$sum mod 60"/>
<xsl:value-of select="concat(format-number($h, '00'), format-number($m, ':00'), format-number($s, ':00'))" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
使用您的示例輸入,您應該看到類似於以下的結果:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<program num="1">
<RunningTime>00:08:18</RunningTime>
</program>
<program num="2">
<RunningTime>00:04:09</RunningTime>
</program>
</root>
您必須先將其轉換爲普通的秒數值。 – 2014-09-05 18:57:56