所以我有一个 xml 文档,它在决赛桌中不包含完整的叉积,但我需要 xslt 为我放入空白。如果你运行这个 xslt,你可以看到 GCM 应该在 ABC 下。我知道我必须计算结果然后添加一个空白,但我被卡住了。
<root>
<Cell>
<place>BRM</place>
<test>DMC</test>
<Score>70</Score>
<Colour>#008000</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup> Process Plant</testgroup>
</Cell>
<Cell>
<place>GCM</place>
<test>DMC</test>
<Score>76</Score>
<Colour>#008000</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup> Process Plant</testgroup>
</Cell>
<Cell>
<place>GRM</place>
<test>DMC</test>
<Score>72</Score>
<Colour>#008000</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup> Process Plant</testgroup>
</Cell>
<Cell>
<place>NPM</place>
<test>DMC</test>
<Score>80</Score>
<Colour>#008000</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup> Process Plant</testgroup>
</Cell>
<Cell>
<place>PDM</place>
<test>DMC</test>
<Score>88</Score>
<Colour>#008000</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup> Process Plant</testgroup>
</Cell>
<Cell>
<place>PTM</place>
<test>DMC</test>
<Score>58</Score>
<Colour>#FFA100</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup> Process Plant</testgroup>
</Cell>
<Cell>
<place>SRM</place>
<test>DMC</test>
<Score>62</Score>
<Colour>#FFA100</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup> Process Plant</testgroup>
</Cell>
<Cell>
<place>SWC</place>
<test>DMC</test>
<Score>85</Score>
<Colour>#008000</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup> Process Plant</testgroup>
</Cell>
<Cell>
<place>RVS</place>
<test>DMC</test>
<Score>84</Score>
<Colour>#008000</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup> Process Plant</testgroup>
</Cell>
<Cell>
<place>BWM</place>
<test>SUR</test>
<Score>66</Score>
<Colour>#FFA100</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup>Survey</testgroup>
</Cell>
<Cell>
<place>PDM</place>
<test>SUR</test>
<Score>85</Score>
<Colour>#008000</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup>Survey</testgroup>
</Cell>
<Cell>
<place>SRM</place>
<test>SUR</test>
<Score>41</Score>
<Colour>#FFA100</Colour>
<GenerateDate>2012-04-04 12:46:41</GenerateDate>
<testgroup>Survey</testgroup>
</Cell>
</root>
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="html" indent="yes"/>
<xsl:key name="muench" match="/root/Cell/place" use="."/>
<xsl:key name="test-key" match="/root/Cell/test" use="."/>
<xsl:template match="/">
<html>
<head>
<title>ABC test Report</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body >
<div >
<header>
<h2 >
test group - <xsl:value-of select="/root/Cell/testgroup"/>
</h2>
</header>
<div class="content">
<table >
<thead>
<tr>
<th >Place</th>
<xsl:for-each select="/root/Cell/test[generate-id() = generate-id(key('test-key',.)[1])]">
<th >
<xsl:value-of select="."/>
</th>
</xsl:for-each>
</tr>
</thead>
<tbody>
<xsl:for-each select="/root/Cell/place[generate-id() = generate-id(key('muench',.)[1])]">
<xsl:call-template name="pivot">
<xsl:with-param name="place" select="."/>
</xsl:call-template>
</xsl:for-each>
</tbody>
</table>
</div>
<footer >
<p></p>
</footer>
</div>
</body>
</html>
</xsl:template>
<xsl:template name="pivot">
<xsl:param name="place"/>
<tr>
<td >
<xsl:value-of select="$place"/>
</td>
<xsl:for-each select="/root/Cell/test[generate-id() = generate-id(key('test-key',.)[1])]">
<xsl:for-each select="/root/Cell[place=$place and test=.]">
<xsl:choose>
<xsl:when test="count(.)=1">
<td>
<xsl:attribute name="style">
background-color:<xsl:value-of select="Colour"/>;
</xsl:attribute>
<xsl:value-of select="Score"/>%
</td>
</xsl:when>
<xsl:otherwise>
<td>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
我想要的输出
<html>
<table border="1">
<thead>
<th>Place</th>
<th>DMC</th>
<th>SUR</th>
</thead>
<tbody>
<tr>
<td>BRM</td>
<td> 70</td>
<td> </td>
</tr>
<tr>
<td>BWM</td>
<td> </td>
<td> 66</td>
</tr>
<tr>
<td>GCM</td>
<td> 76</td>
<td> </td>
</tr>
<tr>
<td>GRM</td>
<td> 72</td>
<td> </td>
</tr>
<tr>
<td>NPM</td>
<td> 80</td>
<td> </td>
</tr>
<tr>
<td>PDM</td>
<td> 88</td>
<td> 85</td>
</tr>
<tr>
<td>PTM</td>
<td> 58</td>
<td> </td>
</tr>
<tr>
<td>RVS</td>
<td> 84</td>
<td> </td>
</tr>
<tr>
<td>SRM</td>
<td> 62</td>
<td> 41</td>
</tr>
<tr>
<td>SWC</td>
<td> 85</td>
<td> </td>
</tr>
</tbody>
</table>
</html>