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 October 5th, 2004, 02:52 PM
Authorized User
 
Join Date: May 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old October 5th, 2004, 02:55 PM
Authorized User
 
Join Date: May 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I meant, I am NOT able to get the sub totals..

SS
 
Old October 7th, 2004, 03:55 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

You have used row[1].No elements named row in the XML file.
Instead of following-sibling::row[1] try following-sibling::node()
or following-sibling::MyTable[1].





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem With Total in the Shopping Cart learningASP.Net BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 October 27th, 2007 09:33 AM
Problem in calculating total sales in MDX query jaee SQL Server 2000 0 March 9th, 2007 11:10 AM
problem in getting total sarah lee ASP.NET 1.0 and 1.1 Basics 4 December 12th, 2006 12:37 PM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
total noob xslt question mrscott XSLT 3 February 22nd, 2006 04:35 PM





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