Reputation: 31
it may sound strange, but is it the case that, for example, if we group it based on 3 things and also want to see a recurrence of a certain element in the key? Can anyone give a simple example if this exists? Although I searched for previous solutions, I only found one where duplicates were deleted.
I finally have my example.
My XML:
<?xml version="1.0" encoding="UTF-8"?>
<invoices>
<invoice buyer="Company_1">
<invoicenumbers>
<invoicenumber name="1234"/>
</invoicenumbers>
<cost>
<COSTGROUP name="Group_1"/>
</cost>
<amounts>
<amount localamount="1878.95"/>
</amounts>
</invoice>
<invoice buyer="Company_1">
<invoicenumbers>
<invoicenumber name="1234"/>
</invoicenumbers>
<cost>
<COSTGROUP name="Group_1"/>
</cost>
<amounts>
<amount localamount="0.00"/>
</amounts>
</invoice>
<invoice buyer="Company_1">
<invoicenumbers>
<invoicenumber name="5678"/>
</invoicenumbers>
<cost>
<COSTGROUP name="Group_1"/>
</cost>
<amounts>
<amount localamount="1900.00"/>
</amounts>
</invoice>
<invoice buyer="Company_1">
<invoicenumbers>
<invoicenumber name="5678"/>
</invoicenumbers>
<cost>
<COSTGROUP name="Group_1"/>
</cost>
<amounts>
<amount localamount="0.00"/>
</amounts>
</invoice>
<invoice buyer="Company_2">
<invoicenumbers>
<invoicenumber name="1234"/>
</invoicenumbers>
<cost>
<COSTGROUP name="Group_1"/>
</cost>
<amounts>
<amount localamount="1900.00"/>
</amounts>
</invoice>
<invoice buyer="Company_2">
<invoicenumbers>
<invoicenumber name="1234"/>
</invoicenumbers>
<cost>
<COSTGROUP name="Group_2"/>
</cost>
<amounts>
<amount localamount="2700.00"/>
</amounts>
</invoice>
<invoice buyer="Company_2">
<invoicenumbers>
<invoicenumber name="1234"/>
</invoicenumbers>
<cost>
<COSTGROUP name="Group_3"/>
</cost>
<amounts>
<amount localamount="500.00"/>
</amounts>
</invoice>
<invoice buyer="Company_3">
<invoicenumbers>
<invoicenumber name="1234"/>
</invoicenumbers>
<cost>
<COSTGROUP name="Group_1"/>
</cost>
<amounts>
<amount localamount="0.00"/>
</amounts>
</invoice>
<invoice buyer="Company_3">
<invoicenumbers>
<invoicenumber name="1234"/>
</invoicenumbers>
<cost>
<COSTGROUP name="Group_2"/>
</cost>
<amounts>
<amount localamount="100.00"/>
</amounts>
</invoice>
<invoice buyer="Company_3">
<invoicenumbers>
<invoicenumber name="1234"/>
</invoicenumbers>
<cost>
<COSTGROUP name="Group_3"/>
</cost>
<amounts>
<amount localamount="5000.00"/>
</amounts>
</invoice>
</invoices>
My XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:key name="Muenchian_Grouping"
match="/invoices/invoice"
use="concat(@buyer, '|', invoicenumbers/invoicenumber/@name)"/>
<xsl:key name="Muenchian_Grouping_by_costgroup"
match="/invoices/invoice"
use="concat(@buyer, '|', invoicenumbers/invoicenumber/@name, '|', cost/COSTGROUP/@name)"/>
<xsl:template match="/">
<Workbook>
<Worksheet ss:Name="Report">
<xsl:call-template name="ws_table"/>
</Worksheet>
</Workbook>
</xsl:template>
<xsl:template name="ws_table">
<Table>
<xsl:call-template name="columns"/>
<xsl:call-template name="columnHeader"/>
<xsl:apply-templates select="invoices/invoice[generate-id() = generate-id(key('Muenchian_Grouping',
concat(@buyer, '|', invoicenumbers/invoicenumber/@name))[1])]" mode="invoices"/>
</Table>
</xsl:template>
<xsl:template name="columns">
<Column ss:Width="269.25"/>
<Column ss:Width="218.25"/>
<Column ss:Width="291.75"/>
<Column ss:Width="276.75"/>
<Column ss:Width="276.75"/>
</xsl:template>
<xsl:template name="columnHeader">
<Row>
<!-- buyer -->
<Cell>
<Data ss:Type="String">buyer</Data>
</Cell>
<!-- invoicenumber -->
<Cell>
<Data ss:Type="String">invoicenumber</Data>
</Cell>
<!-- Group1_localamount -->
<Cell>
<Data ss:Type="String">Group1_localamount</Data>
</Cell>
<!-- Group1_localamount -->
<Cell>
<Data ss:Type="String">Group2_localamount</Data>
</Cell>
<!-- Group1_localamount -->
<Cell>
<Data ss:Type="String">Group3_localamount</Data>
</Cell>
</Row>
</xsl:template>
<xsl:template match="invoice" mode="invoices">
<xsl:variable name="Group1_data" select="key('Muenchian_Grouping_by_costgroup',
concat(@buyer, '|', invoicenumbers/invoicenumber/@name, '|', 'Group_1'))"/>
<xsl:variable name="Group2_data" select="key('Muenchian_Grouping_by_costgroup',
concat(@buyer, '|', invoicenumbers/invoicenumber/@name, '|', 'Group_2'))"/>
<xsl:variable name="Group3_data" select="key('Muenchian_Grouping_by_costgroup',
concat(@buyer, '|', invoicenumbers/invoicenumber/@name, '|', 'Group_3'))"/>
<Row>
<!-- buyer - when group1 is not exists -->
<Cell>
<Data ss:Type="String">
<xsl:value-of select="$Group1_data/@buyer | $Group2_data/@buyer | $Group3_data/@buyer"/>
</Data>
</Cell>
<!-- invoicenumber - when group1 is not exists -->
<Cell>
<Data ss:Type="String">
<xsl:value-of select="$Group1_data/invoicenumbers/invoicenumber/@name | $Group2_data/invoicenumbers/invoicenumber/@name | $Group3_data/invoicenumbers/invoicenumber/@name"/>
</Data>
</Cell>
<!-- Group1_localamount -->
<Cell>
<Data ss:Type="String">
<xsl:value-of select="$Group1_data/amounts/amount/@localamount"/>
</Data>
</Cell>
<!-- Group1_localamount -->
<Cell>
<Data ss:Type="String">
<xsl:value-of select="$Group2_data/amounts/amount/@localamount"/>
</Data>
</Cell>
<!-- Group1_localamount -->
<Cell>
<Data ss:Type="String">
<xsl:value-of select="$Group3_data/amounts/amount/@localamount"/>
</Data>
</Cell>
</Row>
</xsl:template>
</xsl:stylesheet>
So as you can see in the XML the "Company_1" has a duplicate value at "invoicenumber name="1234"" and at "invoicenumber name="5678"", and the question is how can i see both in the output excel file?
EDIT: Expected result: enter image description here
Upvotes: 0
Views: 89