Re: [xsl] Muenchian Grouping and Sum

Subject: Re: [xsl] Muenchian Grouping and Sum
From: omprakash.v@xxxxxxxxxxxxx
Date: Mon, 3 Oct 2005 19:54:32 +0530
Hi Bret,
   Please try this xslt. This does what you want.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="xml"></xsl:output>


<xsl:key name="plu" match="/ItemList/Item" use="PLU"/>

<xsl:template match="/ItemList">

<xsl:for-each select="Item[generate-id(.) = generate-id(key('plu',
PLU)[1])]">

<xsl:variable name="items" select="key('plu', PLU)"/>

<xsl:call-template name="calcSum">
<xsl:with-param name="item" select="$items"/>
<xsl:with-param name="qty" select="Qnt"/>
<xsl:with-param name="price" select="Price"/>
<xsl:with-param name="index" select="1"/>
</xsl:call-template>

</xsl:for-each>

  </xsl:template>

<xsl:template name="calcSum">
<xsl:param name="item"/>
<xsl:param name="qty"/>
<xsl:param name="price"/>
<xsl:param name="index"/>


<xsl:choose>
<xsl:when test="$item[number($index)+1]">

<xsl:call-template name="calcSum">
<xsl:with-param name="item" select="$item[number($index)+1]"/>
<xsl:with-param name="qty" select="$qty + $item[number($index)+1]/Qnt"/>
<xsl:with-param name="price" select="$price +
$item[number($index)+1]/Price"/>
</xsl:call-template>

</xsl:when>
<xsl:otherwise>


<xsl:value-of select="$qty"/>
<xsl:text>
</xsl:text>
<xsl:value-of select="$price"/>


</xsl:otherwise>
</xsl:choose>


</xsl:template>

</xsl:stylesheet>



cheers,
prakash








                                                                                                                                
                      Bret Gillan                                                                                               
                      <bret.gillan@gma         To:      xsl-list@xxxxxxxxxxxxxxxxxxxxxx                                         
                      il.com>                  cc:      (bcc: omprakash.v/Polaris)                                              
                                               Subject: [xsl] Muenchian Grouping and Sum                                        
                      10/03/2005 05:48                                                                                          
                      PM                                                                                                        
                      Please respond                                                                                            
                      to xsl-list                                                                                               
                                                                                                                                
                                                                                                                                




Hiya folks. I'm learning the ropes of XSLT 1.0 using MSXSL v1.0.0.1and
I'm having a real hard time with the following problem. Given the XML:

<ItemList>
<Item>
<PLU>1234678</PLU>
<Qnt>4</Qnt>
<Price>17.49</Price>
</Item>
<Item>
<PLU>1234670</PLU>
<Qnt>5</Qnt>
<Price>17.49</Price>
</Item>
<Item>
<PLU>1234678</PLU>
<Qnt>2</Qnt>
<Price>17.49</Price>
</Item>
</ItemList>

I'm trying to group these items by PLU using Muenchian grouping, which
I know how to do, but I'm also supposed to sum the Qnt and the Price,
which is where I fail. Could someone show me how it's done? Thanks.

-Bret





This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. 
If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in

Current Thread