我正在尝试生成 HTML 输出,它是以下层次结构中的表 - DIVISION、DESK、STRATEGY。我需要在 Division 列和 Desk 列上设置行跨度。一个部门可以有多个办公桌,一个办公桌可以有多种策略。
我正在使用键来按 Division,Desk 定义分组。它适用于 Division,但适用于 Desk。请指教。
xml代码:
<?xml version="1.0"?>
<ROWSET>
<ROW>
<DIVISION>Flow Credit</DIVISION>
<DESK>Europe Indices Net</DESK>
<ACCT_PNL> 0.18 MM USD</ACCT_PNL>
<ECO_PNL> 0.00 MM USD</ECO_PNL>
</ROW>
<ROW>
<DIVISION>Flow Credit</DIVISION>
<DESK>US CDS Trading</DESK>
<STRATEGY>Funk_A6M</STRATEGY>
<ACCT_PNL> -0.01 MM USD</ACCT_PNL>
<ECO_PNL> 0.00 MM USD</ECO_PNL>
</ROW>
<ROW>
<DIVISION>Flow Credit</DIVISION>
<DESK>US CDS Trading</DESK>
<STRATEGY>HYQUANTO</STRATEGY>
<ACCT_PNL> 0.01 MM USD</ACCT_PNL>
<ECO_PNL> 0.00 MM USD</ECO_PNL>
</ROW>
xslt:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="groups" match="/ROWSET/ROW" use="DIVISION"/>
<xsl:key name="groups2" match="/ROWSET/ROW" use="concat(DIVISION, '|', DESK)"/>
<xsl:template match="/ROWSET/ROW">
<xsl:apply-templates select="result[generate-id() = generate-id(key('groups', DIVISION)[1])]" mode="groups"/>
<xsl:apply-templates select="result[generate-id() = generate-id(key('groups2', concat(DIVISION, '|', DESK))[1])]" mode="groups2"/>
</xsl:template>
<xsl:template match="/ROWSET">
<h1>
<xsl:value-of select="DIVISION"/>
</h1>
<table id="{DIVISION}">
<tr class="heading">
<th scope="col">DIVISION</th>
<th scope="col">DESK</th>
<th scope="col">STRATEGY</th>
</tr>
<xsl:for-each select="key('groups', ROW/DIVISION)">
<tr>
<xsl:if test="position() = 1">
<td valign="center" bgcolor="#999999">
<xsl:attribute name="rowspan"> <xsl:value-of select="count(key('groups', DIVISION))"/></xsl:attribute>
<b>
<xsl:text/>
<xsl:value-of select="DIVISION"/>
</b>
</td>
</xsl:if>
<xsl:if test="position() = 1">
<td valign="center" bgcolor="#999999">
<xsl:attribute name="rowspan"> <xsl:value-of select="count(key('groups2', concat(DIVISION, '|',DESK)))"/></xsl:attribute>
<b>
<xsl:text/>
<xsl:value-of select="DESK"/>
</b>
</td>
</xsl:if>
<td>
<xsl:value-of select="STRATEGY"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>