我正在尝试使用 XSLT 2.0 来汇总每个 Year/YearQtr 的产品 [Widgets] 的所有个人销售人员 [VOL],按他们的销售团队、部门分组。可能有多种产品类型,我在这里只保留一种类型来尝试简化代码。
- 我已经设法使用 for-each 来获取特定年份中 YearQtr 值的列表,但我无法弄清楚如何获取作为 SalesPerson/Performance 的子项出现的所有 Year 和 YearQtr 元素的不同列表.
- 我已经尝试过 currentgroup(),但看不到如何指定分组,以便我只能获得部门级别的总和,而不是每个销售人员的总和。
我正在使用的 XML 是:
<salesteam id="Team1">
<department id="dept1">
<salespeople>
<salesperson id="98765">
<performance>
<year id="2013">
<yearqtr id="1">
<yearMonth id="1">
<products>
<widgets>
<vol>5</vol>
<val>50000</val>
</widgets>
</products>
</yearMonth>
<yearMonth id="2">
<products>
<widgets>
<vol>10</vol>
<val>100000</val>
</widgets>
</products>
</yearMonth>
<yearMonth id="3">
<products>
<widgets>
<vol>15</vol>
<val>150000</val>
</widgets>
</products>
</yearMonth>
</yearqtr>
<yearqtr id="2">
<yearMonth id="4">
<products>
<widgets>
<vol>20</vol>
<val>200000</val>
</widgets>
</products>
</yearMonth>
<yearMonth id="5">
<products>
<widgets>
<vol>25</vol>
<val>250000</val>
</widgets>
</products>
</yearMonth>
<yearMonth id="6">
<products>
<widgets>
<vol>30</vol>
<val>300000</val>
</widgets>
</products>
</yearMonth>
</yearqtr>
</year>
</performance>
</salesperson>
<salesperson id="12345">
<performance>
<year id="2013">
<yearqtr id="1">
<yearMonth id="1">
<products>
<widgets>
<vol>5</vol>
<val>50000</val>
</widgets>
</products>
</yearMonth>
<yearMonth id="2">
<products>
<widgets>
<vol>10</vol>
<val>100000</val>
</widgets>
</products>
</yearMonth>
<yearMonth id="3">
<products>
<widgets>
<vol>15</vol>
<val>150000</val>
</widgets>
</products>
</yearMonth>
</yearqtr>
<yearqtr id="2">
<yearMonth id="4">
<products>
<widgets>
<vol>20</vol>
<val>200000</val>
</widgets>
</products>
</yearMonth>
<yearMonth id="5">
<products>
<widgets>
<vol>25</vol>
<val>250000</val>
</widgets>
</products>
</yearMonth>
<yearMonth id="6">
<products>
<widgets>
<vol>30</vol>
<val>300000</val>
</widgets>
</products>
</yearMonth>
</yearqtr>
</year>
</performance>
</salesperson>
</salespeople>
</department>
</salesteam>
我想要实现的是
<table>
<tbody>
<tr>
<th>2013Q1</th>
<th>2013Q2</th>
<th>2013Q3</th>
<th>2013Q4</th>
</tr>
<tr>
<td>30</td>
<td>75</td>
<td>0</td>
<td>0</td>
</tr>
</tbody>
</table>