[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Muenchian Grouping and Sum
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: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|