[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Grouping by key - another question

Subject: Re: [xsl] Grouping by key - another question
From: gopinath.emmidisetty@xxxxxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 9 Nov 2004 15:01:06 +0000
sum function xsl
Hi,

Thanks, now the categorised output is working fine.  Now, I have got 
another question.  While categorising the output, I want to total the 
values in one of the columns.  I know there is a function called 
sum(node-set) and tried to use(search for sum function in my xsl file). 
>From the fact that I don't get the results, I don't know how to apply sum 
function in juction with key function.  Any suggestions, please?

Thanks.

XML Docment:

<documents>
<account>
<accountnumber colno="0">0001</accountnumber>
<companyname colno="1">ABC Ltd</companyname>
<town colno="2">Ford</town>
<ordervalue colno="3">115.49</ordervalue>
<postcode colno="4">FD13QG</postcode>
</account>
<account>
<accountnumber colno="0">0002</accountnumber>
<companyname colno="1">XYZ Ltd</companyname>
<town colno="2">Ford</town>
<ordervalue colno="3">115.49</ordervalue>
<postcode colno="4">XY13QG</postcode>
</account>
...
...
...
</documents>

xsl document:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
        version="1.0">
        <xsl:output method="xml" omit-xml-declaration="yes"/>
        <xsl:param name="catCol" select="2"/>
        <xsl:key name="categorise" match="account" use="*[@colno]" />
 
        <xsl:template match="/">
                        <div> <xsl:apply-templates select="documents" /> 
</div>
        </xsl:template>

        <xsl:template match="documents">
                <table>
                        <xsl:apply-templates select="account[generate-id() 
= generate-id( key( 'categorise', *[@colno=$catCol] )[1] )]" 
mode="catcols">
                                <xsl:sort select="*[@colno=$catCol]"/>
                         </xsl:apply-templates>
                </table>
        </xsl:template>
 
        <xsl:template match="account" mode="catcols">
                <tr>
                        <td colspan="2">
                                <b><xsl:value-of select="*[@colno=$catCol]" /></b> ( <xsl:value-of select="count(.|key( 'categorise', *[@colno=$catCol] ) )" /> )
                        </td>
                        <td colspan="2">
                                <xsl:value-of select="sum(*[@colno=3][position()])" />
                        </td>
                        <xsl:apply-templates select="key('categorise', *[@colno=$catCol])" mode="catrows" />
                </tr>

        </xsl:template>

        <xsl:template match="account" mode="catrows">
                <tr>
                        <td width="100"> <xsl:value-of select="*[@colno=0]" /> </td>
                        <td width="100"> <xsl:value-of select="*[@colno=1]" /> </td>
                        <td width="100"> <xsl:value-of select="*[@colno=3]" /> </td>
                        <td width="100"> <xsl:value-of select="*[@colno=4]" />      </td>
                </tr>
        </xsl:template>
</xsl:stylesheet>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.