Adding numbers
I am struggling to figure out XML and XSL as I go, so please treat me like a complete novice.
I have the following XML output from an SQL database:
- <Target>
- <Target_T Test_Run_ID="47" Target_ID="76" Target_Name_VC="auto-target12">
<Test_T PF="1" Duration="324" />
<Test_T PF="1" Duration="371" />
<Test_T PF="1" Duration="166" />
<Test_T PF="1" Duration="169" />
<Test_T PF="2" Duration="0" />
<Test_T PF="1" Duration="1658" />
</Target_T>
</Target>
I'm trying to get a sum of the Duration values, and displaying it in a table. I've created the template at the end of this message, and am calling it via the following:
<xsl:for-each select="Target/Target_T">
<TR>
<TD>
<xsl:apply-template name="totDuration"/>
</TD>
</TR>
</xsl:for-each>
IE6 reports "Keyword xsl:apply-template may not be used here." I can't figure out why. Can anyone help me? Any hints would be most appreciated.
Here's the template:
<xsl:template name="totDuration">
<xsl:param name="Tests" select="Test_T" />
<xsl:param name="subtotal" select="0" />
<xsl:choose>
<xsl:when test="$Tests">
<xsl:call-template name="totDuration">
<xsl:with-param name="Tests"
select="$Tests[position() > 1]" />
<xsl:with-param name="subtotal"
select="$subtotal + substring-before($Tests[1], ':')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$subtotal" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
|