XSLT 2.0 转换未生成正确的 html 文档
XSLT 2.0 transformation not generating proper html document
我正在尝试使用 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 样式表(与上面 link 中包含的相同)...
<?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>
首先使用 <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>
我正在尝试使用 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 样式表(与上面 link 中包含的相同)...
<?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>
首先使用 <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>