xsl-list
[Top] [All Lists]

Re: Grouping by key

2004-12-02 04:30:51
Hi,

The suggestions Geert gave for the problem worked well regarding 
grouping/categorising.  I am trying to display only the categories or 
categories and records under that category using a parameter.  I have a 
xsl:param collapse and I want to use/apply some templates based on that 
param but the <xsl:if> element doesn't seems to be working.  I want to 
know whether the usage of if element is right or I can use the element in 
this context.  I have 

Here is the xsl file and I have used <xsl:if> element at 3 places (look 
for $collapse).  Please let me know whether you need the xml file or any 
other information regarding this.  Thanks.

<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:param name="indent" select="'   '"/>
        <xsl:param name="collapse" select=""/>

        <xsl:key name="total" match="*[(_at_)colno='10']" 
use="../*[(_at_)colno='2']" />
        <xsl:key name="categorise" match="account" use="*[(_at_)colno='2']" />

        <xsl:param name="columnHeaders">
                <header>CompanyName</header>
                <header>AccountNumber</header>
                <header>Town</header>
                <header>Postcode</header>
                <header>Phone</header>
        </xsl:param>

        <xsl:if test="$collapse=1">
                <xsl:template match="/">
                        <div>
                        <hr/>
                        <xsl:apply-templates select="documents" />
                        </div>
                </xsl:template>
        </xsl:if>

        <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">
                <xsl:if test="position()=1">
                        <tr>
                                <th colspan="6" 
align="right">Total</th><th colspan="2"><xsl:value-of select="sum( 
//*[(_at_)colno='10'] )" /></th>
                        </tr>
                        <tr>
                                <th> <xsl:value-of 
select="msxsl:node-set($columnHeaders)/header[position()=3]" /> </th>
                                <th> <xsl:value-of 
select="msxsl:node-set($columnHeaders)/header[position()=1]" /> </th>
                                <th> <xsl:value-of 
select="msxsl:node-set($columnHeaders)/header[position()=2]" /> </th>
                                <th> <xsl:value-of 
select="msxsl:node-set($columnHeaders)/header[position()=4]" /> </th>
                                <th> <xsl:value-of 
select="msxsl:node-set($columnHeaders)/header[position()=5]" /> </th>
                        </tr>
                </xsl:if>
                <tr class="resultCategory">
                        <td colspan="3">
                                <b> <xsl:value-of 
select="*[(_at_)colno=$catCol]" /></b> ( <xsl:value-of select="count(.|key( 
'categorise', *[(_at_)colno=$catCol] ) )" /> )
                        </td>
                        <td colspan="2">
                                <b><xsl:value-of select="sum( key( 'total', 
town ) )" /></b>
                        </td>

                        <xsl:if test="$collapse=1">
                                <xsl:apply-templates 
select="key('categorise', *[(_at_)colno=$catCol])" mode="catrows" />
                        </xsl:if>
                </tr>

        </xsl:template>

        <xsl:if test="$collapse=1">
                <xsl:template match="account" mode="catrows">
                        <tr>
                                <xsl:if test="position() mod 2 != 1">
                                        <xsl:attribute 
name="class">resultAlternate</xsl:attribute>
                                </xsl:if>
                        <td width="40"> <xsl:value-of select="$indent" /> 
</td>
                        <td width="100"> <xsl:value-of 
select="*[(_at_)colno=0]" /> </td>
                        <td width="100"> <xsl:value-of 
select="*[(_at_)colno=1]" /> </td>
                        </tr>
                </xsl:template>
        </xsl:if>

    </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>
--~--



<Prev in Thread] Current Thread [Next in Thread>