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="*[(_at_)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', *[(_at_)colno=$catCol] )[1] )]"
mode="catcols">
<xsl:sort select="*[(_at_)colno=$catCol]"/>
</xsl:apply-templates>
</table>
</xsl:template>
<xsl:template match="account" mode="catcols">
<tr>
<td colspan="2">
<b><xsl:value-of
select="*[(_at_)colno=$catCol]" /></b> ( <xsl:value-of select="count(.|key(
'categorise', *[(_at_)colno=$catCol] ) )" /> )
</td>
<td colspan="2">
<xsl:value-of
select="sum(*[(_at_)colno=3][position()])" />
</td>
<xsl:apply-templates select="key('categorise',
*[(_at_)colno=$catCol])" mode="catrows" />
</tr>
</xsl:template>
<xsl:template match="account" mode="catrows">
<tr>
<td width="100"> <xsl:value-of
select="*[(_at_)colno=0]" /> </td>
<td width="100"> <xsl:value-of
select="*[(_at_)colno=1]" /> </td>
<td width="100"> <xsl:value-of
select="*[(_at_)colno=3]" /> </td>
<td width="100"> <xsl:value-of
select="*[(_at_)colno=4]" /> </td>
</tr>
</xsl:template>
</xsl:stylesheet>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--