I'm having an issue selecting distinct values for each group. The result just doesn't display on screen. The desired result is 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 I intend to do is to select distinct values for current-group()
in the apply-templates
tag which is like this
<xsl:template match="Item">
<xsl:value-of select="distinct-values(./ItemName)"/>
</xsl:template>
I've read several samples on the net and the most optimum way to do so is to employ the generate-id()
function with the for-each-group
loop. But I have tried and get no positive result. This is the 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 and Extra 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 and Extra 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 that the source XML contains several same ProductName
elements with different ItemNumber
attributes. What I desire is to group all the Item
elements with similar ItemNumber
and do a summation of the quantity. Thanks for the help guys. Really appreciate it.
The example output would be: