Xml XSLT 1.0带键的多级分组

Xml XSLT 1.0带键的多级分组,xml,xslt,xslt-1.0,grouping,Xml,Xslt,Xslt 1.0,Grouping,我正在尝试从AWS分配文件生成报告。我已将相应的数据从CSV转换为XML,但不太清楚如何在XSLT1.0(.net)中执行键/分组 这是XML文件 <?xml version="1.0" encoding="utf-16"?> <AWS> <BusinessUnit> <Name>BBII Western</Name> <Office> <Name>

我正在尝试从AWS分配文件生成报告。我已将相应的数据从CSV转换为XML,但不太清楚如何在XSLT1.0(.net)中执行键/分组

这是XML文件

<?xml version="1.0" encoding="utf-16"?>
<AWS>
    <BusinessUnit>
        <Name>BBII Western</Name>
        <Office>
            <Name>Fairfield</Name>
            <Job>
                <JobNumber>OH4299</JobNumber>
                <Phase> 35</Phase>
                <CostCode> 74500</CostCode>
                <Costs>
                    <Cost>
                        <ProductName>AWS Storage Gateway</ProductName>
                        <UsageQuantity>558.6793022</UsageQuantity>
                        <TotalCost>16.760536</TotalCost>
                    </Cost>
                    <Cost>
                        <ProductName>AWS Storage Gateway</ProductName>
                        <UsageQuantity>0.99999986</UsageQuantity>
                        <TotalCost>124.999981</TotalCost>
                    </Cost>
                </Costs>
            </Job>
        </Office>
        <Office>
            <Name>Riconanda</Name>
            <Job>
                <JobNumber>4228</JobNumber>
                <Phase> 92</Phase>
                <CostCode> 92110</CostCode>
                <Costs>
                    <Cost>
                        <ProductName>AWS Storage Gateway</ProductName>
                        <UsageQuantity>63.92940319</UsageQuantity>
                        <TotalCost>1.9179</TotalCost>
                    </Cost>
                    <Cost>
                        <ProductName>AWS Storage Gateway</ProductName>
                        <UsageQuantity>0.99999986</UsageQuantity>
                        <TotalCost>124.999981</TotalCost>
                    </Cost>
                </Costs>
            </Job>
        </Office>
    </BusinessUnit>
    <BusinessUnit>
        <Name>None</Name>
        <Office>
            <Name>None</Name>
            <Job>
                <JobNumber>None</JobNumber>
                <Phase> </Phase>
                <CostCode> </CostCode>
                <Costs>
                    <Cost>
                        <ProductName>AWS Storage Gateway</ProductName>
                        <UsageQuantity>0.33271862</UsageQuantity>
                        <TotalCost>0.009982</TotalCost>
                    </Cost>
                    <Cost>
                        <ProductName>Amazon Elastic Compute Cloud</ProductName>
                        <UsageQuantity>1929.089098</UsageQuantity>
                        <TotalCost>183.26</TotalCost>
                    </Cost>
                    <Cost>
                        <ProductName>Amazon Elastic Compute Cloud</ProductName>
                        <UsageQuantity>4.99999976</UsageQuantity>
                        <TotalCost>0.5</TotalCost>
                    </Cost>
                </Costs>
            </Job>
        </Office>
    </BusinessUnit>
    <BusinessUnit>
        <Name>BBII Alternative Delivery</Name>
        <Office>
            <Name>Denver-Heery</Name>
            <Job>
                <JobNumber>199900</JobNumber>
                <Phase> 16</Phase>
                <CostCode> 74500</CostCode>
                <Costs>
                    <Cost>
                        <ProductName>AWS Storage Gateway</ProductName>
                        <UsageQuantity>131.2051444</UsageQuantity>
                        <TotalCost>3.936191</TotalCost>
                    </Cost>
                    <Cost>
                        <ProductName>AWS Storage Gateway</ProductName>
                        <UsageQuantity>1.00000017</UsageQuantity>
                        <TotalCost>125.000019</TotalCost>
                    </Cost>
                </Costs>
            </Job>
        </Office>
    </BusinessUnit>
    <BusinessUnit>
        <Name>Transit</Name>
        <Office>
            <Name>Denver Estimating</Name>
            <Job>
                <JobNumber>RAILOH</JobNumber>
                <Phase> N/A</Phase>
                <CostCode> 74500</CostCode>
                <Costs>
                    <Cost>
                        <ProductName>AWS Storage Gateway</ProductName>
                        <UsageQuantity>758.8392434</UsageQuantity>
                        <TotalCost>22.765391</TotalCost>
                    </Cost>
                    <Cost>
                        <ProductName>AWS Storage Gateway</ProductName>
                        <UsageQuantity>1.00000017</UsageQuantity>
                        <TotalCost>125.000019</TotalCost>
                    </Cost>
                </Costs>
            </Job>
        </Office>
    </BusinessUnit>
</AWS>

BBII西部
费尔菲尔德
OH4299
35
74500
AWS存储网关
558.6793022
16.760536
AWS存储网关
0.99999986
124.999981
利科南达
4228
92
92110
AWS存储网关
63.92940319
1.9179
AWS存储网关
0.99999986
124.999981
没有一个
没有一个
没有一个
AWS存储网关
0.33271862
0.009982
亚马逊弹性计算云
1929.089098
183.26
亚马逊弹性计算云
4.99999976
0.5
BBII替代交付
丹佛·希里
199900
16
74500
AWS存储网关
131.2051444
3.936191
AWS存储网关
1.00000017
125.000019
换乘
丹佛估计
莱罗
不适用
74500
AWS存储网关
758.8392434
22.765391
AWS存储网关
1.00000017
125.000019
我想做的是在业务单元级别,首先我要计算每个产品名称的UsageQuantity和TotalCost之和

然后对每个办公室和工作都这样做。这项工作不会很难,也不需要分组

我正在将其输出到HTML

对于BusinessUnit,我尝试了几个关键配置,但没有一个像我预期的那样有效

我尝试过(仅限业务部门级别):


桌子{
字体系列:Verdana;
字号:9pt;
边界塌陷:塌陷;
表布局:固定
}
th{
背景颜色:浅蓝色;
字体大小:粗体;
边框:1px纯黑;
}
第列标题{
文本对齐:居中
}
第四行标题{
文本对齐:右对齐;
右侧填充:4px;
}
运输署{
边框:1px纯黑;
}
td.num{
文本对齐:右对齐;
右paddin:4px;
}
业务单位:
产品
使用数量
成本
这就产生了:

    <html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style>
                    table {
                        font-family: Verdana;
                        font-size: 9pt;
                        border-collapse: collapse;
                        table-layout: fixed                 
                    }
                    th {
                        background-color: light-blue;
                        font-weight: bold;
                        border: 1px solid black;
                    }

                    th.columnHeader {
                        text-align: center
                    }
                    th.rowHeader {
                        text-align: right;
                        padding-right: 4px;
                    }

                    td {
                    border: 1px solid black;
                    }

                    td.num {
                        text-align: right;
                        paddin-right:4px;
                    }
                </style>
  </head>
  <body>
    <table>
      <tr>
        <th class="columnHeader">
                    Business Unit:
                </th>
        <td colspan="2">BBII Western</td>
      </tr>
      <tr>
        <th class="columnHeader">Product</th>
        <th class="columnHeader">Usage Qty</th>
        <th class="columnHeader">Cost</th>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">558.68</td>
        <td class="num">16.76</td>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">1.00</td>
        <td class="num">125.00</td>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">63.93</td>
        <td class="num">1.92</td>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">1.00</td>
        <td class="num">125.00</td>
      </tr>
    </table>
    <table>
      <tr>
        <th class="columnHeader">
                    Business Unit:
                </th>
        <td colspan="2">None</td>
      </tr>
      <tr>
        <th class="columnHeader">Product</th>
        <th class="columnHeader">Usage Qty</th>
        <th class="columnHeader">Cost</th>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">0.33</td>
        <td class="num">0.01</td>
      </tr>
      <tr>
        <th class="rowHeader">Amazon Elastic Compute Cloud</th>
        <td class="num">1,929.09</td>
        <td class="num">183.26</td>
      </tr>
      <tr>
        <th class="rowHeader">Amazon Elastic Compute Cloud</th>
        <td class="num">5.00</td>
        <td class="num">0.50</td>
      </tr>
    </table>
    <table>
      <tr>
        <th class="columnHeader">
                    Business Unit:
                </th>
        <td colspan="2">BBII Alternative Delivery</td>
      </tr>
      <tr>
        <th class="columnHeader">Product</th>
        <th class="columnHeader">Usage Qty</th>
        <th class="columnHeader">Cost</th>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">131.21</td>
        <td class="num">3.94</td>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">1.00</td>
        <td class="num">125.00</td>
      </tr>
    </table>
    <table>
      <tr>
        <th class="columnHeader">
                    Business Unit:
                </th>
        <td colspan="2">Transit</td>
      </tr>
      <tr>
        <th class="columnHeader">Product</th>
        <th class="columnHeader">Usage Qty</th>
        <th class="columnHeader">Cost</th>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">758.84</td>
        <td class="num">22.77</td>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">1.00</td>
        <td class="num">125.00</td>
      </tr>
    </table>
  </body>
</html>

桌子{
字体系列:Verdana;
字号:9pt;
边界塌陷:塌陷;
表布局:固定
}
th{
背景颜色:浅蓝色;
字体大小:粗体;
边框:1px纯黑;
}
第列标题{
文本对齐:居中
}
第四行标题{
文本对齐:右对齐;
右侧填充:4px;
}
运输署{
边框:1px纯黑;
}
td.num{
文本对齐:右对齐;
右paddin:4px;
    <html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style>
                    table {
                        font-family: Verdana;
                        font-size: 9pt;
                        border-collapse: collapse;
                        table-layout: fixed                 
                    }
                    th {
                        background-color: light-blue;
                        font-weight: bold;
                        border: 1px solid black;
                    }

                    th.columnHeader {
                        text-align: center
                    }
                    th.rowHeader {
                        text-align: right;
                        padding-right: 4px;
                    }

                    td {
                    border: 1px solid black;
                    }

                    td.num {
                        text-align: right;
                        paddin-right:4px;
                    }
                </style>
  </head>
  <body>
    <table>
      <tr>
        <th class="columnHeader">
                    Business Unit:
                </th>
        <td colspan="2">BBII Western</td>
      </tr>
      <tr>
        <th class="columnHeader">Product</th>
        <th class="columnHeader">Usage Qty</th>
        <th class="columnHeader">Cost</th>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">558.68</td>
        <td class="num">16.76</td>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">1.00</td>
        <td class="num">125.00</td>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">63.93</td>
        <td class="num">1.92</td>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">1.00</td>
        <td class="num">125.00</td>
      </tr>
    </table>
    <table>
      <tr>
        <th class="columnHeader">
                    Business Unit:
                </th>
        <td colspan="2">None</td>
      </tr>
      <tr>
        <th class="columnHeader">Product</th>
        <th class="columnHeader">Usage Qty</th>
        <th class="columnHeader">Cost</th>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">0.33</td>
        <td class="num">0.01</td>
      </tr>
      <tr>
        <th class="rowHeader">Amazon Elastic Compute Cloud</th>
        <td class="num">1,929.09</td>
        <td class="num">183.26</td>
      </tr>
      <tr>
        <th class="rowHeader">Amazon Elastic Compute Cloud</th>
        <td class="num">5.00</td>
        <td class="num">0.50</td>
      </tr>
    </table>
    <table>
      <tr>
        <th class="columnHeader">
                    Business Unit:
                </th>
        <td colspan="2">BBII Alternative Delivery</td>
      </tr>
      <tr>
        <th class="columnHeader">Product</th>
        <th class="columnHeader">Usage Qty</th>
        <th class="columnHeader">Cost</th>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">131.21</td>
        <td class="num">3.94</td>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">1.00</td>
        <td class="num">125.00</td>
      </tr>
    </table>
    <table>
      <tr>
        <th class="columnHeader">
                    Business Unit:
                </th>
        <td colspan="2">Transit</td>
      </tr>
      <tr>
        <th class="columnHeader">Product</th>
        <th class="columnHeader">Usage Qty</th>
        <th class="columnHeader">Cost</th>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">758.84</td>
        <td class="num">22.77</td>
      </tr>
      <tr>
        <th class="rowHeader">AWS Storage Gateway</th>
        <td class="num">1.00</td>
        <td class="num">125.00</td>
      </tr>
    </table>
  </body>
</html>
<xsl:key name="kProduct" 
    match="Cost" 
    use="concat(ancestor::BusinessUnit/Name, '#', ProductName)"/>
 <xsl:variable name="bu" select="." />
 <xsl:for-each 
            select="Office/Job/Costs/Cost[
            count(. | key('kProduct',concat($bu/Name, '#', ProductName))[1]) = 1]">
<xsl:variable name="this_pg" select="." />
<xsl:variable name="this_pgm" 
        select="key('kProduct',concat($bu/Name, '#', $this_pg/ProductName))" />
 <xsl:value-of select="format-number(sum($this_pgm/UsageQuantity),'##,##0.00')"/> 
<xsl:template match="BusinessUnit">

   <!-- .. table head -->
        <xsl:variable name="bu" select="." />
        <xsl:for-each 
            select="Office/Job/Costs/Cost[
            count(. | key('kProduct',concat($bu/Name, '#', ProductName))[1]) = 1]">
           <xsl:variable name="this_pg" select="." />
           <xsl:variable name="this_pgm" 
                  select="key('kProduct',concat($bu/Name, '#', $this_pg/ProductName))" />
            <tr>
                <th class="rowHeader">
                    <xsl:value-of select="ProductName"/>
                </th>
                <td class="num">
                    <xsl:value-of select="format-number(sum($this_pgm/UsageQuantity),'##,##0.00')"/>                  
                </td>
                <td class="num">
                    <xsl:value-of select="format-number(sum($this_pgm/TotalCost), '##,##0.00')"/>                 
                </td>
            </tr>           
        </xsl:for-each>
    <!-- table end -->
</xsl:template>