I have some XML like this:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<root>
<line>
<ResourceName>Ren</ResourceName>
<Amount>20</Amount>
<OtherAmount>5</OtherAmount>
<SomeText>Nopls</SomeText>
</line>
<line>
<ResourceName>Stimpy</ResourceName>
<Amount>30</Amount>
<OtherAmount>10</OtherAmount>
<SomeText>Do_not_sum</SomeText>
</line>
</root>
but importantly the number of 'columns' below line node could more or less and any name (dynamic varying).
I want to generate a HTML table with the node names as a header and a total for any numeric columns in the footer.
So far I have an XSLT as follows:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="root">
<html>
<body>
<table border="1">
<thead>
<xsl:apply-templates select="line[1]" mode="thead"/>
</thead>
<tbody>
<xsl:apply-templates select="line" />
</tbody>
<tfoot>
<tr>
<td>Totals:</td>
<td>
<xsl:variable name="amount1Lines" select="line/Amount"/>
<xsl:value-of select="format-number(sum($amount1Lines), '0.00')" />
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</tfoot>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="line" mode="thead">
<tr>
<xsl:apply-templates select="*" mode="thead"/>
</tr>
</xsl:template>
<xsl:template match="*" mode="thead">
<th>
<xsl:value-of select="local-name()" />
</th>
</xsl:template>
<xsl:template match="line">
<tr>
<xsl:apply-templates select="*" />
</tr>
</xsl:template>
<xsl:template match="line/*">
<td>
<xsl:value-of select="." />
</td>
</xsl:template>
</xsl:stylesheet>
but obviously the footer section is hardcoded for each column.
Can anyone determine some xsl that will sum only numeric columns and leave other columns blank in the footer. ie. In the example it would sum 'Amount' and 'OtherAmount' but not resourcename or sometext columns.