p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: Sorting the Total


Message #1 by "karthikeyan" <karthikeyan@a...> on Thu, 26 Sep 2002 17:21:41 +0530
I got the solution so please ignore but just let me know if the way i m
doing the program causes the performance issue

 solution
~~~~~~~~~~

    <xsl:apply-templates
       select="row[generate-id(.) = generate-id(key('rows', Id)[1])]">

       <xsl:sort select="rgbtotal" data-type="number" order="descending"/>

after apply-templates i did a sort on the <rgbtotal> tag i created in the
xslt.

getting clever lol :)

karthikeyan.
----- Original Message -----
From: "karthikeyan" <karthikeyan@a...>
To: "P2P_XSLT" <xslt@p...>
Sent: Thursday, September 26, 2002 5:21 PM
Subject: [xslt] Sorting the Total


>
> Hi All,
>
>   I have a sorting issue .  I need to sort on
>
>   [Total] which i calculate based on the SUM of <IdCount> for the
particular <Desc> under particular <Id>
>
>   i.e
>           <xsl:variable name="ids" select="Id"/>
>
>           <rgbtotal>
>             <xsl:value-of select="sum(/Recordset/row[Id 
$ids]/IdCount)"/>
>           </rgbtotal>
>
>           <xsl:value-of select="rgbtotal"/>
>
>   How do i sort the <rgbtotal> i.e
>
> Total
>
> 500
> 400
> 300
>
>   Heres my XML Snippet
>
> ~~~~~~~~~~~~~~~~~~~~
> <Recordset>
>  <row>
>   <Id>1</Id>
>   <Desc>Red</Desc>
>   <IdCount>5</IdCount>
>  </row>
>  <row>
>   <Id>1</Id>
>   <Desc>Green</Desc>
>   <IdCount>5</IdCount>
>  </row>
>  <row>
>   <Id>1</Id>
>   <Desc>Black</Desc>
>   <IdCount>5</IdCount>
>  </row>
>  <row>
>   <Id>2</Id>
>   <Desc>Red</Desc>
>   <IdCount>15</IdCount>
>  </row>
>  <row>
>   <Id>2</Id>
>   <Desc>Green</Desc>
>   <IdCount>15</IdCount>
>  </row>
>  <row>
>   <Id>2</Id>
>   <Desc>Black</Desc>
>   <IdCount>15</IdCount>
>  </row>
> </Recordset>
> ~~~~~~~~~~~~~~~~~~~~
>
> Heres my XSL snippet
> ~~~~~~~~~~~~~~~~~
> <xsl:stylesheet version="1.0"
>                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
>   <xsl:key name="rows" match="row" use="Id"/>
>
>   <xsl:output method="html"/>
>
>   <xsl:template match="/">
>
>     <HTML>
>
>       <BODY align="CENTER">
>
>           <TABLE width="500" border="1" bgcolor="#FFFFFF" cellpadding="2"
>                  cellspacing="0">
>             <xsl:apply-templates select="Recordset"/>
>
>           </TABLE>
>
>       </BODY>
>     </HTML>
>
>   </xsl:template>
>
>   <xsl:template match="Recordset">
>
>     <TR>
>       <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>         <B>Id</B>
>       </TD>
>       <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>         <B>Red</B>
>       </TD>
>       <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>         <B>Green</B>
>       </TD>
>       <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>         <B>Black</B>
>       </TD>
>       <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>         <B>Total</B>
>       </TD>
>     </TR>
>
>       <xsl:apply-templates
>          select="row[generate-id(.) = generate-id(key('rows', Id)[1])]">
>       <xsl:sort select="NetworkName"/>
>
>     </xsl:apply-templates>
>
>   </xsl:template>
>
>
>   <xsl:template match="row">
>
>     <TR><TD colspan="5">&#160;</TD></TR>
>
>
>       <TR>
>         <TD valign="TOP"><xsl:value-of select="Id"/></TD>
>
>         <TD valign="TOP">
>           <xsl:for-each select="key('rows', Id)">
>
>             <xsl:value-of select="IdCount[../Desc = 'Red']"/>
>           </xsl:for-each>
>         </TD>
>         <TD valign="TOP">
>           <xsl:for-each select="key('rows', Id)">
>             <xsl:value-of select="IdCount[../Desc = 'Green']"/>
>           </xsl:for-each>
>         </TD>
>         <TD valign="TOP">
>           <xsl:for-each select="key('rows', Id)">
>             <xsl:value-of select="IdCount[../Desc = 'Black']"/>
>           </xsl:for-each>
>         </TD>
>         <TD valign="TOP">
>         <xsl:variable name="ids" select="Id"/>
>
>           <rgbtotal>
>             <xsl:value-of select="sum(/Recordset/row[Id 
$ids]/IdCount)"/>
>           </rgbtotal>
>
>           <xsl:value-of select="rgbtotal"/>
>
>         </TD>
>       </TR>
>
>   </xsl:template>
>
> </xsl:stylesheet>
> ~~~~~~~~~~~~~~~~~
>
>   Hope the above question makes sense.
>
>   PS : Urgent Please
>
> karthikeyan.
>
>
>
>
> ---
> In developing the .NET Framework Microsoft has
> taken XML to heart, and with ASP.NET representing
> the cutting edge of Windows based web development,
> Professional ASP.NET XML with C# has been published
> to help web developers to appreciate how these
> technologies can work together to provide
> functional, powerful applications.
> http://www.wrox.com/acon11.asp?ISBN=1861007345
>



  Return to Index