[xsl] Sub total generation - filter problem

Subject: [xsl] Sub total generation - filter problem
From: "Srinivasan, Sundar" <sundar.srinivasan@xxxxxxxx>
Date: Thu, 16 Dec 2004 16:37:59 -0000
I think I am NOT good enough to be in this list..but I NEED help.
I am creating detail lines and sub totals. It works fine with XSLT-ONE . The
bs_categ totals are off or not produced
when I filter by currency in the <key> and apply-templates as in XSLT-TWO. Any
help would be greatly appreciated.
Regards.

XML:..................XSLT-ONE: and XSLT-TWO follow
=================================================
<MyDataSet>
	<MyTable>
		<bs_group>Assets</bs_group>
		<bs_categ>01. Cash &amp; Due from Banks</bs_categ>
		<curr_code>AUD</curr_code>
		<ps_download>487637.750</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Assets</bs_group>
		<bs_categ>01. Cash &amp; Due from Banks</bs_categ>
		<curr_code>AUD</curr_code>
		<ps_download>-587788.493</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Assets</bs_group>
		<bs_categ>01. Cash &amp; Due from Banks</bs_categ>
		<curr_code>CAD</curr_code>
		<ps_download>73108.752</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Assets</bs_group>
		<bs_categ>04.Loans</bs_categ>
		<curr_code>AUD</curr_code>
		<ps_download>93587.020</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Assets</bs_group>
		<bs_categ>04.Loans</bs_categ>
		<curr_code>AUD</curr_code>
		<ps_download>5802.950</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Assets</bs_group>
		<bs_categ>04.Loans</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-742934.750</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Assets</bs_group>
		<bs_categ>04.Loans</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-15000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Assets</bs_group>
		<bs_categ>05.Trading Assets</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>17878.430</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Assets</bs_group>
		<bs_categ>05.Trading Assets</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>11952104.300</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>08.Deposits</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-400000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>08.Deposits</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-500000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>08.Deposits</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-600000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>08.Deposits</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-604000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>09.FFP &amp; REPOS</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-5064000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>09.FFP &amp; REPOS</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-250000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>09.FFP &amp; REPOS</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-1000000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>09.FFP &amp; REPOS</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-1030000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>10.Other Borrowings</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-365000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>10.Other Borrowings</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-365000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>10.Other Borrowings</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-400000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>10.Other Borrowings</bs_categ>
		<curr_code>USD</curr_code>
		<ps_download>-600000000.000</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>11.Trading Liabilities</bs_categ>
		<curr_code>EUR</curr_code>
		<ps_download>219496.600</ps_download>
	</MyTable>
	<MyTable>
		<bs_group>Liabilities</bs_group>
		<bs_categ>11.Trading Liabilities</bs_categ>
		<curr_code>JPY</curr_code>
		<ps_download>-0.010</ps_download>
	</MyTable>
</MyDataSet>

XSLT-ONE:
==================================================
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">

<xsl:key name="key-group"			match="MyTable" use="bs_group"/>
<xsl:key name="key-group-bs_categ"	match="MyTable"
use="concat(bs_group,'+',bs_categ)"/>

<xsl:template match="/">
<xsl:apply-templates select="MyDataSet" />
</xsl:template>

<xsl:template match="MyDataSet">

	<TABLE   width='800px'  >
		 <tr>
			<th  id="bs_group"		style="WIDTH:3%;"	   align='center' >BS Group				</th>
			<th  id="bs_categ"		style="WIDTH:5%;"	   align='center' >BS category
</th>
			<th id="curr_code"		style="WIDTH:3%;"	   align='center' > Currency			</th>
			<th id="ps_download"	style="WIDTH:4%;"	   align='center' > Amount			 </th>
		</tr>
	</TABLE>

		<TABLE   width='800px'   >
			<TBODY>
				<xsl:apply-templates select="MyTable" >
						<xsl:sort select="0" data-type="text" order="ascending" />
				</xsl:apply-templates>
			</TBODY>
		</TABLE>

</xsl:template>

<xsl:template match="MyTable">

				<tr>
					<td style="WIDTH:3%;" > <xsl:value-of select="bs_group"			/>	</td>
					<td style="WIDTH:5%"> <xsl:value-of select="bs_categ"			/>	</td>
					<td style="WIDTH:3%;"> <xsl:value-of select="curr_code"		/>	</td>
					<td align="right" style="WIDTH:4%;">
						<xsl:value-of select="ps_download"/>
					</td>
				</tr>

		<!-- Categ total -->
			<xsl:if test="(following-sibling::MyTable[1]/bs_categ != bs_categ) or
(following-sibling::MyTable[1]/bs_group != bs_group)  or (position() =
last())">
				<xsl:variable name="ps_download_categ_sub_total"
select="sum(key('key-group-bs_categ',concat(bs_group,'+',bs_categ))/ps_download)"></xsl:variable>

				<tr >
					<td  colspan="3">Categ Total</td>
					<td align="right" >
						<xsl:value-of select="$ps_download_categ_sub_total"/>
					</td>
				</tr>
			</xsl:if>

</xsl:template>
</xsl:stylesheet>

XSLT-TWO:
==============================================
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">

<xsl:key name="key-group"			match="MyTable[curr_code='AUD']" use="bs_group"/>
<xsl:key name="key-group-bs_categ"	match="MyTable"
use="concat(bs_group,'+',bs_categ)"/>

<xsl:template match="/">
<xsl:apply-templates select="MyDataSet" />
</xsl:template>

<xsl:template match="MyDataSet">

	<TABLE   width='800px'  >
		 <tr>
			<th  id="bs_group"		style="WIDTH:3%;"	   align='center' >BS Group				</th>
			<th  id="bs_categ"		style="WIDTH:5%;"	   align='center' >BS category
</th>
			<th id="curr_code"		style="WIDTH:3%;"	   align='center' > Currency			</th>
			<th id="ps_download"	style="WIDTH:4%;"	   align='center' > Amount			 </th>
		</tr>
	</TABLE>

		<TABLE   width='800px'   >
			<TBODY>
				<xsl:apply-templates select="MyTable[curr_code='AUD']" >
						<xsl:sort select="0" data-type="text" order="ascending" />
				</xsl:apply-templates>
			</TBODY>
		</TABLE>

</xsl:template>

<xsl:template match="MyTable">

				<tr>
					<td style="WIDTH:3%;" > <xsl:value-of select="bs_group"			/>	</td>
					<td style="WIDTH:5%"> <xsl:value-of select="bs_categ"			/>	</td>
					<td style="WIDTH:3%;"> <xsl:value-of select="curr_code"		/>	</td>
					<td align="right" style="WIDTH:4%;">
						<xsl:value-of select="ps_download"/>
					</td>
				</tr>

		<!-- Categ total -->
			<xsl:if test="(following-sibling::MyTable[1]/bs_categ != bs_categ) or
(following-sibling::MyTable[1]/bs_group != bs_group)  or (position() =
last())">
				<xsl:variable name="ps_download_categ_sub_total"
select="sum(key('key-group-bs_categ',concat(bs_group,'+',bs_categ))/ps_download)"></xsl:variable>

				<tr >
					<td  colspan="3">Categ Total</td>
					<td align="right" >
						<xsl:value-of select="$ps_download_categ_sub_total"/>
					</td>
				</tr>
			</xsl:if>

</xsl:template>
</xsl:stylesheet>

==============================================================================
This message is for the sole use of the intended recipient. If you received
this message in error please delete it and notify us. If this message was
misdirected, CSFB does not waive any confidentiality or privilege. CSFB
retains and monitors electronic communications sent through its network.
Instructions transmitted over this system are not binding on CSFB until they
are confirmed by us. Message transmission is not guaranteed to be secure.
==============================================================================

Current Thread