N
Newbie
Suppose that I have an HTML table of numbers, and I need to replace the value of each cell with
itself divided by the total for that column. The best I can think of is as follows:
<xsl:for-each select="tr">
<xsl:copy>
<xsl:for-each select="td">
<xsl:variable name="col" select="position()" />
<xsl:variable name="total" select="sum(../../tr/td[position()=$col])" />
<xsl:copy>
<xsl:value-of select=". div $total" />
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
This is rather verbose (the temporary col variable), and has to be recalculated for each row. Is
there a more concise/efficient way of doing this?
itself divided by the total for that column. The best I can think of is as follows:
<xsl:for-each select="tr">
<xsl:copy>
<xsl:for-each select="td">
<xsl:variable name="col" select="position()" />
<xsl:variable name="total" select="sum(../../tr/td[position()=$col])" />
<xsl:copy>
<xsl:value-of select=". div $total" />
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
This is rather verbose (the temporary col variable), and has to be recalculated for each row. Is
there a more concise/efficient way of doing this?