i'm having issue selecting distinct values each group. result doesn't display on screen. desired result shown below:
<xsl:for-each-group select="items/item" group-by="providername"> <xsl:sort select="current-grouping-key()"/> <tr> <th> <xsl:value-of select="current-grouping-key()"/> </th> </tr> <tr> <td> <xsl:text>item number</xsl:text> </td> <td> <xsl:text>quantity</xsl:text> </td> <td> <xsl:text>unit price</xsl:text> </td> <td> <xsl:text>total</xsl:text> </td> </tr> <xsl:apply-templates select="current-group()"/> </xsl:for-each-group> what intend select distinct values current-group() in apply-templates tag this
<xsl:template match="item"> <xsl:value-of select="distinct-values(./itemname)"/> </xsl:template> i've read several samples on net , optimum way employ generate-id() function for-each-group loop. have tried , no positive result. source xml:
<items> <item itemnumber="1148087"> <productname>dolby metal-black-matte</productname> <providername>vestal watches</providername> <quantity>4</quantity> <unitprice>67.99</unitprice> </item> <item itemnumber="1150197"> <productname>vercilli blk-tan</productname> <providername>boston babes</providername> <quantity>1</quantity> <unitprice>23.99</unitprice> </item> <item itemnumber="1151464"> <productname>spritz grape seat , seat</productname> <providername>bambeano</providername> <quantity>1</quantity> <unitprice>56.99</unitprice> </item> <item itemnumber="1148087"> <productname>dolby metal-black-matte</productname> <providername>vestal watches</providername> <quantity>2</quantity> <unitprice>67.99</unitprice> </item> <item itemnumber="1150197"> <productname>vercilli blk-tan</productname> <providername>boston babes</providername> <quantity>2</quantity> <unitprice>23.99</unitprice> </item> <item itemnumber="1150173"> <productname>lucille tan</productname> <providername>boston babes</providername> <quantity>1</quantity> <unitprice>24.99</unitprice> </item> <item itemnumber="1151464"> <productname>spritz grape seat , seat</productname> <providername>bambeano</providername> <quantity>1</quantity> <unitprice>56.99</unitprice> </item> <item itemnumber="1148089"> <productname>plexi leather-silver-black</productname> <providername>vestal watches</providername> <quantity>1</quantity> <unitprice>189.99</unitprice> </item> </items> notice source xml contains several same productname elements different itemnumber attributes. desire group item elements similar itemnumber , summation of quantity. guys. appreciate it.
the example output be: 
please have modified version of xslt:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output indent="yes"/> <xsl:template match="/"> <table> <thead> <tr> <th> <xsl:text>item number</xsl:text> </th> <th> <xsl:text>quantity</xsl:text> </th> <th> <xsl:text>unit price</xsl:text> </th> <th> <xsl:text>total</xsl:text> </th> </tr> </thead> <tbody> <xsl:for-each-group select="items/item" group-by="@itemnumber"> <xsl:sort select="current-grouping-key()"/> <tr> <td> <xsl:value-of select="current-grouping-key()"/> </td> <td> <xsl:value-of select="sum(current-group()/quantity)"/> </td> <td> <xsl:value-of select="current-group()/unitprice"/> </td> <td> <xsl:value-of select="sum(for $x in current-group() return $x/unitprice * $x/quantity)"/> </td> </tr> <xsl:apply-templates select="current-group()"/> </xsl:for-each-group> </tbody> </table> </xsl:template> <xsl:template match="item"> <xsl:value-of select="distinct-values(./itemname)"/> </xsl:template> </xsl:stylesheet> output:
<table> <thead> <tr> <th>item number</th> <th>quantity</th> <th>unit price</th> <th>total</th> </tr> </thead> <tbody> <tr> <td>1148087</td> <td>6</td> <td>67.99</td> <td>407.93999999999994</td> </tr> <tr> <td>1148089</td> <td>1</td> <td>189.99</td> <td>189.99</td> </tr> <tr> <td>1150173</td> <td>1</td> <td>24.99</td> <td>24.99</td> </tr> <tr> <td>1150197</td> <td>3</td> <td>23.99</td> <td>71.97</td> </tr> <tr> <td>1151464</td> <td>2</td> <td>56.99</td> <td>113.98</td> </tr> </tbody> </table>
Comments
Post a Comment