xsl-list
[Top] [All Lists]

Re: Muenchian Grouping and Sum

2005-10-03 07:24:32





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(_dot_)gillan(_at_)gma         To:      
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com                                
         
                      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

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





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

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