0
我想要生成HTML輸出,它是以下層次結構中的表格 - 分區,桌面,策略。我需要在Division列和Desk列上設置rowspan。一個部門可以有多個辦公桌,一個辦公桌可以有多個策略。XSLT GROUP BY使用密鑰
我正在使用鍵來按照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>