我正在尝试使用Saxon XSLT 2.0简单转换(使用Exchanger XML编辑器)从XML和XSL文档生成HTML文件,但是XML文件中的数据没有被提取。我假设我的XSL样式表中有错误,但我不知道在哪里。
我已经上传了创建完整HTML文档所需的所有4个文件(1个XSL,1个XML,1个CSS和1个PNG)... https://drive.google.com/open?id=0B9o30hEqwvyDSjRsbWlZVUpyNzA
这是我的XSL样式表(与上面链接中包含的样式表相同)...
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"
doctype-system="about:legacy-compat"
encoding="UTF-8"
indent="yes" />
<xsl:template match="/">
<html>
<head>
<title>Employment Report</title>
<link href="horizons.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
<header>
<img src="horizons.png" alt="Horizons TechNet" />
</header>
<h1>Employment Report</h1>
<xsl:for-each-group select="employee" group-by="gender">
<table id="summary">
<tr>
<th>Gender</th>
<td>
<xsl:value-of select="current-grouping-key()" />
</td>
</tr>
<tr>
<th>Employees</th>
<td>
<xsl:value-of select="count(current-group())" />
</td>
</tr>
<tr>
<th>Average Compensation</th>
<td>
<xsl:value-of select="avg(current-group()//salary+bonus+commission)"/>
</td>
</tr>
</table>
<table id="emptable">
<tr>
<th>ID</th>
<th>Department</th>
<th>Education Level</th>
<th>Total Compensation</th>
</tr>
<xsl:apply-templates select="employee">
<xsl:sort select="sum(salary+bonus+commission)" order="descending" data-type="number" />
</xsl:apply-templates>
</table>
</xsl:for-each-group>
</div>
</body>
</html>
</xsl:template>
<xsl:template name="employee">
<tr>
<td><xsl:value-of select="@empID" /></td>
<td><xsl:value-of select="department" /></td>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="edLevel" /></td>
<td><xsl:value-of select="sum(salary+bonus+commission)" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
使用<xsl:for-each-group select="//employee" group-by="gender">
作为开始。我想你想要<xsl:apply-templates select="current-group ()">
而不是<xsl:apply-templates select="employee">
此外,您在最后一个模板上有name
而不是match
属性,在某些地方您使用+
然后使用sum
,我想您要么想要使用sum
或+
汇总项目,但不能同时使用两者:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"
doctype-system="about:legacy-compat"
encoding="UTF-8"
indent="yes" />
<xsl:template match="/">
<html>
<head>
<title>Employment Report</title>
<link href="horizons.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
<header>
<img src="horizons.png" alt="Horizons TechNet" />
</header>
<h1>Employment Report</h1>
<xsl:for-each-group select="//employee" group-by="gender">
<table id="summary">
<tr>
<th>Gender</th>
<td>
<xsl:value-of select="current-grouping-key()" />
</td>
</tr>
<tr>
<th>Employees</th>
<td>
<xsl:value-of select="count(current-group())" />
</td>
</tr>
<tr>
<th>Average Compensation</th>
<td>
<xsl:value-of select="avg(current-group()/sum(salary | bonus |commission))"/>
</td>
</tr>
</table>
<table id="emptable">
<tr>
<th>ID</th>
<th>Department</th>
<th>Education Level</th>
<th>Total Compensation</th>
</tr>
<xsl:apply-templates select="current-group()">
<xsl:sort select="sum(salary | bonus | commission)" order="descending"/>
</xsl:apply-templates>
</table>
</xsl:for-each-group>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="employee">
<tr>
<td><xsl:value-of select="@empID" /></td>
<td><xsl:value-of select="department" /></td>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="edLevel" /></td>
<td><xsl:value-of select="sum(salary | bonus | commission)" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>