Xml XSLT 1.0分组和汇总项目-获取每个级别的房间项目列表
每层都有一个房间列表。Xml XSLT 1.0分组和汇总项目-获取每个级别的房间项目列表,xml,xslt,sum,grouping,xslt-1.0,Xml,Xslt,Sum,Grouping,Xslt 1.0,每层都有一个房间列表。 每个房间都有一个事件列表。 事件包含对物品及其在房间中数量的引用。 一篇文章有代码和成本 我如何才能获得每一级别的文章列表,按代码分组,以合计数量/成本 XML: 这是到目前为止我的XSL: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" encoding="utf-8" indent=
每个房间都有一个事件列表。
事件包含对物品及其在房间中数量的引用。
一篇文章有代码和成本 我如何才能获得每一级别的文章列表,按代码分组,以合计数量/成本 XML:
这是到目前为止我的XSL:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" encoding="utf-8" indent="no"/>
<xsl:key name="articles" match="article" use="@id"/>
<xsl:key name="room" match="room" use="@id"/>
<xsl:key name="room-occurrences" match="occurrence" use="../../@id"/>
<xsl:key name="level-rooms" match="level-room" use="../@id"/>
<xsl:template match="/">
<html>
<body>
<h2>Items per level</h2>
<table border="1">
<tr>
<td>Level</td>
<td>Article</td>
<td>Cost</td>
<td>Qty</td>
<td>Total</td>
</tr>
<xsl:for-each select="/planning/level">
<tr>
<td><xsl:value-of select="@name"/></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<xsl:for-each select="key('room-occurrences', key('level-rooms', @id)/@room-ref)">
<xsl:sort select="key('articles', @article-ref)/@code" order="ascending"/>
<tr>
<td></td>
<td><xsl:value-of select="key('articles', @article-ref)/@code"/></td>
<td><xsl:value-of select="key('articles', @article-ref)/@cost"/></td>
<td><xsl:value-of select="@qty"/></td>
<td><xsl:value-of select="@qty * key('articles', @article-ref)/@cost"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
每个级别的项目
数量
文章
费用
数量
全部的
这是我得到的结果HTML:
+---------+------+-----+-------+
| Article | Cost | Qty | Total |
+---------+------+-----+-------+
| Level 1 |
+------------------------------+
| B20 | 12 | 4 | 48 |
+---------+------+-----+-------+
| C12 | 20 | 3 | 60 |
+---------+------+-----+-------+
| C12 | 20 | 1 | 20 |
+---------+------+-----+-------+
| C12 | 20 | 2 | 40 |
+---------+------+-----+-------+
| L10 | 10 | 2 | 20 |
+---------+------+-----+-------+
| L10 | 10 | 2 | 20 |
+---------+------+-----+-------+
| TA2 | 5 | 2 | 10 |
+---------+------+-----+-------+
| TA2 | 5 | 4 | 20 |
+---------+------+-----+-------+
| TA2 | 5 | 1 | 5 |
+---------+------+-----+-------+
| Level 2 |
+------------------------------+
| B20 | 12 | 5 | 60 |
+---------+------+-----+-------+
| C12 | 20 | 2 | 40 |
+---------+------+-----+-------+
| T1 | 31 | 3 | 93 |
+---------+------+-----+-------+
| T1 | 31 | 2 | 62 |
+---------+------+-----+-------+
+---------+------+-----+-------+
|物品|成本|数量|总计|
+---------+------+-----+-------+
|一级|
+------------------------------+
|B20 | 12 | 4 | 48 |
+---------+------+-----+-------+
|C12 | 20 | 3 | 60 |
+---------+------+-----+-------+
|C12 | 20 | 1 | 20 |
+---------+------+-----+-------+
|C12 | 20 | 2 | 40 |
+---------+------+-----+-------+
|L10 | 10 | 2 | 20 |
+---------+------+-----+-------+
|L10 | 10 | 2 | 20 |
+---------+------+-----+-------+
|TA2 | 5 | 2 | 10 |
+---------+------+-----+-------+
|TA2 | 5 | 4 | 20 |
+---------+------+-----+-------+
|TA2 | 5 | 1 | 5 |
+---------+------+-----+-------+
|二级|
+------------------------------+
|B20 | 12 | 5 | 60 |
+---------+------+-----+-------+
|C12 | 20 | 2 | 40 |
+---------+------+-----+-------+
|T1 | 31 | 3 | 93 |
+---------+------+-----+-------+
|T1 | 31 | 2 | 62 |
+---------+------+-----+-------+
但我想按代码对文章进行分组,如下所示:
+---------+------+-----+-------+
| Article | Cost | Qty | Total |
+---------+------+-----+-------+
| Level 1 |
+------------------------------+
| B20 | 12 | 4 | 48 |
+---------+------+-----+-------+
| C12 | 20 | 6 | 120 |
+---------+------+-----+-------+
| L10 | 10 | 4 | 40 |
+---------+------+-----+-------+
| TA2 | 5 | 7 | 35 |
+---------+------+-----+-------+
| Level 2 |
+------------------------------+
| B20 | 12 | 5 | 60 |
+---------+------+-----+-------+
| C12 | 20 | 2 | 40 |
+---------+------+-----+-------+
| T1 | 31 | 5 | 155 |
+---------+------+-----+-------+
+---------+------+-----+-------+
|物品|成本|数量|总计|
+---------+------+-----+-------+
|一级|
+------------------------------+
|B20 | 12 | 4 | 48|
+---------+------+-----+-------+
|C12 | 20 | 6 | 120|
+---------+------+-----+-------+
|L10 | 10 | 4 | 40|
+---------+------+-----+-------+
|TA2 | 5 | 7 | 35|
+---------+------+-----+-------+
|二级|
+------------------------------+
|B20 | 12 | 5 | 60|
+---------+------+-----+-------+
|C12 | 20 | 2 | 40|
+---------+------+-----+-------+
|T1 | 31 | 5 | 155|
+---------+------+-----+-------+
由于您有不同的
文章
元素,我认为一种方法是使用您设置的键简单地选择它们(尽管我通过尽可能简单地使用子元素缩短了这一点),然后处理引用的文章
,回顾数量之和:
<xsl:key name="articles" match="article" use="@id"/>
<xsl:key name="room" match="room" use="@id"/>
<xsl:template match="/">
<html>
<body>
<h2>Items per level</h2>
<table border="1">
<tr>
<td>Level</td>
<td>Article</td>
<td>Cost</td>
<td>Qty</td>
<td>Total</td>
</tr>
<xsl:for-each select="/planning/level">
<tr>
<td><xsl:value-of select="@name"/></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<xsl:variable name="level-occs" select="key('room', level-room/@room-ref)/occurrence-list/occurrence"/>
<xsl:for-each select="key('articles', $level-occs/@article-ref)">
<xsl:sort select="@code" order="ascending"/>
<xsl:variable name="qty" select="sum($level-occs[@article-ref = current()/@id]/@qty)"/>
<tr>
<td></td>
<td><xsl:value-of select="@code"/></td>
<td><xsl:value-of select="@cost"/></td>
<td><xsl:value-of select="$qty"/></td>
<td><xsl:value-of select="$qty * @cost"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
每个级别的项目
数量
文章
费用
数量
全部的
<xsl:key name="articles" match="article" use="@id"/>
<xsl:key name="room" match="room" use="@id"/>
<xsl:template match="/">
<html>
<body>
<h2>Items per level</h2>
<table border="1">
<tr>
<td>Level</td>
<td>Article</td>
<td>Cost</td>
<td>Qty</td>
<td>Total</td>
</tr>
<xsl:for-each select="/planning/level">
<tr>
<td><xsl:value-of select="@name"/></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<xsl:variable name="level-occs" select="key('room', level-room/@room-ref)/occurrence-list/occurrence"/>
<xsl:for-each select="key('articles', $level-occs/@article-ref)">
<xsl:sort select="@code" order="ascending"/>
<xsl:variable name="qty" select="sum($level-occs[@article-ref = current()/@id]/@qty)"/>
<tr>
<td></td>
<td><xsl:value-of select="@code"/></td>
<td><xsl:value-of select="@cost"/></td>
<td><xsl:value-of select="$qty"/></td>
<td><xsl:value-of select="$qty * @cost"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>