Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 13th, 2004, 02:46 PM
Authorized User
 
Join Date: May 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT expert required..thanks.

I am generating subtotals and it works fine..however it does not generate them or generated improperly if I filter in the apply-template like <xsl:apply-templates select="MyTable[curr_code='AUD']" >. If I just code <xsl:apply-templates select="MyTable"/> it works.

The XML is :

<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>01. Cash &amp; Due from Banks</bs_categ>
        <curr_code>GBP</curr_code>
        <ps_download>4262274.160</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>01. Cash &amp; Due from Banks</bs_categ>
        <curr_code>GBP</curr_code>
        <ps_download>-2956402.499</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>01. Cash &amp; Due from Banks</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>10514518.380</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>02.Securities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>18294190.340</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>02.Securities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-18206224.390</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>Assets</bs_group>
        <bs_categ>05.Trading Assets</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>53801336.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>05.Trading Assets</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>450000000.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>06.Other Assets</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-4786154.220</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>06.Other Assets</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-6098133.630</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>06.Other Assets</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-6976731.810</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>06.Other Assets</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-8804476.850</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>07.Due To/From Related Parties</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-188018136.380</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>07.Due To/From Related Parties</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-195306355.530</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>07.Due To/From Related Parties</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-2635857513.620</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Assets</bs_group>
        <bs_categ>07.Due To/From Related Parties</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-36672230504.810</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>08.Deposits</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-340000000.000</ps_download>
    </MyTable>
    <MyTable>\r\n
        <bs_group>Liabilities</bs_group>
        <bs_categ>08.Deposits</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-350000000.000</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>-400000000.000</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>-400000000.000</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>-450000000.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>08.Deposits</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-455000000.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>-500000000.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>-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>08.Deposits</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-620500000.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>08.Deposits</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-660000000.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>08.Deposits</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-990000000.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>08.Deposits</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-1058000000.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>08.Deposits</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-1150000000.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>08.Deposits</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-1299000000.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>08.Deposits</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-1500000000.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>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>11.Trading Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>0.010</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>11.Trading Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>0.010</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>11.Trading Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>93193.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>11.Trading Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>206472.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>11.Trading Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-0.030</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>11.Trading Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-5888.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>11.Trading Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-305686.520</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>11.Trading Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-1788707.000</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>12.Other Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-32.850</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>12.Other Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-67.260</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>12.Other Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-21991446.060</ps_download>
    </MyTable>
    <MyTable>
        <bs_group>Liabilities</bs_group>
        <bs_categ>12.Other Liabilities</bs_categ>
        <curr_code>USD</curr_code>
        <ps_download>-22959632.690</ps_download>
    </MyTable>
</MyDataSet>

XSLT:
=====

<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:variable name="ps_download_asset_sub_total" select="sum(key('key-group','Assets')/ps_download)"></xsl:variable>

<xsl:variable name="ps_download_liab_sub_total" select="sum(key('key-group','Liabilities')/ps_download)"></xsl:variable>

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

<xsl:template match="MyDataSet">

<div>
        <div id="CmnSpanSearchCriteria" ></div>
    <div id="CmnListOverFlowDiv" style="width:820px;position:absolute;display:inlin e">
    <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>
    </div>
</div>
</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="format-number(ps_download,'$#,###,###,###,###,###.000')"/>
                    </td>
                </tr>


            <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="format-number($ps_download_categ_sub_total,'$#,###,###,## #,###,###.000')"/>
                    </td>
                </tr>
            </xsl:if>


            <xsl:if test="(following-sibling::MyTable[1]/bs_group != bs_group) and (bs_group='Assets')">
                <tr >
                        <td colspan="3">Total <xsl:value-of select="bs_group" /></td>
                        <td align="right">
                            <xsl:value-of select="format-number($ps_download_asset_sub_total,'$#,###,###,## #,###,###.000')"/>
                        </td>
                </tr>
            </xsl:if>


            <xsl:if test="position() = last()">
                <tr>
                        <td colspan="3">Total <xsl:value-of select="bs_group" /></td>
                        <td align="right">
                            <xsl:value-of select="format-number($ps_download_liab_sub_total,'$#,###,###,### ,###,###.000')"/>
                        </td>
                </tr>


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



SS
__________________
SS
 
Old December 13th, 2004, 08:01 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

<xsl:variable name="ps_download_categ_sub_total" select="sum(key('key-group-bs_categ',concat(bs_group,'+',bs_categ))/ps_download)">
With this you're still going to get all the nodes that match the group and the category but aren't displayed.

Now you have to add new criteria so that the currency code is also considered when you calculate your subtotals. Have to change the key and the corresponding call.
eg, concat the curr_code as well.






Similar Threads
Thread Thread Starter Forum Replies Last Post
The expert programmers take a look ojbrowser Visual Studio 2005 0 August 12th, 2008 07:04 AM
hi expert! Can u give me solution for this???? jasdeephere ASP.NET 1.0 and 1.1 Professional 1 February 10th, 2007 02:16 AM
XSLT for complicated xml to xml transf. required doug@sirvisetti XSLT 3 June 17th, 2005 04:26 PM
Anyone Expert in SQL Queries? itHighway HTML Code Clinic 3 June 3rd, 2005 09:57 AM
is there any expert who can help me surya221 Classic ASP Databases 1 March 24th, 2005 10:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.