XSLT sub total problem
Hello,
I am able to get the line-break sub totals..
I get it only at the end. Can you help?
Here's the XML:
<MyDataSet>
<MyTable>
<BSGROUP>Assets</BSGROUP>
<BSCATEGORY>Categ1</BSCATEGORY>
<cust_cif>135852 </cust_cif>
<ps_reg_rpt>A04C_L8</ps_reg_rpt>
<Call_Report>1161071.45</Call_Report>
</MyTable>
<MyTable>
<BSGROUP>Assets</BSGROUP>
<BSCATEGORY>Categ1</BSCATEGORY>
<cust_cif>135852 </cust_cif>
<ps_branch>X01</ps_branch>
<ps_reg_rpt>A04C_L8</ps_reg_rpt>
<Call_Report>-112222.45</Call_Report>
</MyTable>
<MyTable>
<BSGROUP>Asset3</BSGROUP>
<BSCATEGORY>Categ2</BSCATEGORY>
<cust_cif>135852 </cust_cif>
<ps_reg_rpt>A04C_L8</ps_reg_rpt>
<Call_Report>1161075.692</Call_Report>
</MyTable>
<MyTable>
<BSGROUP>Asset3</BSGROUP>
<BSCATEGORY>Categ3</BSCATEGORY>
<cust_cif>135852 </cust_cif>
<ps_reg_rpt>A04C_L8</ps_reg_rpt>
<Call_Report>1161076.70</Call_Report>
</MyTable>
</MyDataSet>
Here's the xslt:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="k-bs_group" match="MyTable" use="BSGROUP"/>
<xsl:key name="k-bs_group_categ" match="MyTable" use="concat(BSGROUP,'+',BSCATEGORY)" />
<xsl:variable name="grand-total" select="sum(/MyDataSet/MyTable/Call_Report)" />
<xsl:template match="/">
<xsl:apply-templates select="MyDataSet" />
</xsl:template>
<xsl:template match="MyDataSet">
<TABLE id="mytab" style="width:1000px;table-layout:fixed;" border='1' cellpadding="3">
<tr>
<th >BS group</th>
<th >BS Categ</th>
<th >Cust CIF</th>
<th >PS Reg Rpt</th>
<th >Call Rpt</th>
</tr>
</TABLE>
<TABLE style="width:1000px;border-collapse:collapse;table-layout:fixed" >
<TBODY>
<xsl:apply-templates select="MyTable" />
</TBODY>
</TABLE>
</xsl:template>
<xsl:template match="MyTable">
<tr >
<td style="WIDTH:8%" >
<xsl:value-of select="BSGROUP" />
</td>
<td style="WIDTH:22%" >
<xsl:value-of select="BSCATEGORY" />
</td>
<td style="WIDTH:10%" >
<xsl:value-of select="cust_cif"/>
</td>
<td style="WIDTH:10%" >
<xsl:value-of select="ps_reg_rpt"/>
</td>
<td style="WIDTH:16%" >
<xsl:value-of select="Call_Report"/>
</td>
</tr>
<xsl:if test="(following-sibling::row[1]/BSGROUP != BSGROUP) or
(following-sibling::row[1]/BSCATEGORY != BSCATEGORY)
or (position() = last())">
<tr>
<td></td>
<td>Total</td>
<td></td>
<td></td>
<td>
<xsl:value-of select="sum(key('k-bs_group_categ',concat(BSGROUP,'+',BSCATEGORY))/Call_Report)"/>
</td>
</tr>
</xsl:if>
<xsl:if test="(following-sibling::row[1]/BSGROUP != BSGROUP)
or (position() = last())">
<tr>
<td>Total</td>
<td></td>
<td></td>
<td></td>
<td>
<xsl:value-of select="sum(key('k-bs_group',BSGROUP)/Call_Report)"/>
</td>
</tr>
</xsl:if>
<xsl:if test="position() = last()">
<tr bgcolor="whitesmoke" style="color:red">
<td colspan="4" align="right">Grand Total</td>
<td>
<xsl:value-of select="$grand-total"/>
</td>
</tr>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
SS
__________________
SS
|