我一直在努力,顯示僱員的信息,並通過部門小組,並降序排序此分配XSL樣式表有問題。我正在使用for-each元素使用Muenchian分組來使用此位置路徑對每個唯一部門進行排序。該任務告訴我,每次通過for-each循環時,都會寫入「employeeList」表的代碼。 「部門」是部門元素的值。不知道爲什麼我的表和模板沒有出現在我的XSL文件,並Muenchian分組的
它還告訴我插入一個新模板「匹配」的員工元素。該模板應該寫入一個包含選定員工信息的表格行。下面是代碼:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="departments" match="employee" use="department" />
<xsl:output method="html"
doctype-system="about:legacy-compat"
encoding="UTF-8"
indent="yes" />
<xsl:template match="/">
<html>
<head>
<title>Employee Report</title>
<link href="hbstyles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
<header>
<img src="hblogo.png" alt="Harris and Barnes" />
</header>
<h1>Employee Report</h1>
<xsl:for-each select="//employee[generate-id()=generate-id(key('departments', department)[1])]">
<xsl:sort select="department" />
</xsl:for-each>
<table class="employeeList">
<caption><xsl:value-of select="department" /></caption>
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
<th>Phone</th>
<th>Gender</th>
<th>Marital Status</th>
<th>Work Status</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="key('departments', department)">
<xsl:sort select="salary" order="descending" />
</xsl:apply-templates>
</tbody>
</table>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="employee">
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="position" /></td>
<td><xsl:value-of select="format-number(salary, '$#,##0')" /></td>
<td><xsl:value-of select="phone" /></td>
<td><xsl:value-of select="gender" /></td>
<td><xsl:value-of select="maritalStatus" /></td>
<td>><xsl:value-of select="workingStatus" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>
XML:
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="hbemployees.xsl" ?>
<employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<employee empID="4">
<name>Heffner, Marian</name>
<position>Chief Operating Officer</position>
<phone>x10962</phone>
<email>[email protected]/harrisbarnes</email>
<department>Management</department>
<salary>262000</salary>
<gender>female</gender>
<maritalStatus>married</maritalStatus>
<workStatus>Full Time</workStatus>
</employee>
<employee empID="192">
<name>Murff, Nicolle</name>
<position>Mgr Software Client Supp</position>
<phone>x32524</phone>
<email>[email protected]/harrisbarnes</email>
<department>Sales</department>
<salary>137000</salary>
<gender>female</gender>
<maritalStatus>married</maritalStatus>
<workStatus>Full Time</workStatus>
</employee>
<employee empID="295">
<name>Vecchio, Art</name>
<position>Line Worker</position>
<phone>x12125</phone>
<email>[email protected]/harrisbarnes</email>
<department>Management</department>
<salary>83000</salary>
<gender>male</gender>
<maritalStatus>married</maritalStatus>
<workStatus>Part Time</workStatus>
</employee>
<employee empID="294">
<name>Lewis, Richard</name>
<position>Met Read/Coll</position>
<phone>x22131</phone>
<email>[email protected]/harrisbarnes</email>
<department>Production</department>
<salary>74500</salary>
<gender>male</gender>
<maritalStatus>married</maritalStatus>
<workStatus>Full Time</workStatus>
</employee>
<employee empID="293">
<name>White, William</name>
<position>Env Asst</position>
<phone>x03194</phone>
<email>[email protected]/harrisbarnes</email>
<department>Marketing</department>
<salary>53500</salary>
<gender>male</gender>
<maritalStatus>single</maritalStatus>
<workStatus>Contract</workStatus>
</employee>
<employee empID="292">
<name>Williams, John</name>
<position>Line Wrker A</position>
<phone>x06056</phone>
<email>[email protected]/harrisbarnes</email>
<department>Research</department>
<salary>70500</salary>
<gender>male</gender>
<maritalStatus>single</maritalStatus>
<workStatus>Full Time</workStatus>
</employee>
<employee empID="291">
<name>Clark, David</name>
<position>Sr Engineer</position>
<phone>x03551</phone>
<email>[email protected]/harrisbarnes</email>
<department>Production</department>
<salary>81000</salary>
<gender>male</gender>
<maritalStatus>married</maritalStatus>
<workStatus>Contract</workStatus>
</employee>
<employee empID="290">
<name>Sand, Robyn</name>
<position>Dsl Sys Rep</position>
<phone>x12823</phone>
<email>[email protected]/harrisbarnes</email>
<department>Research</department>
<salary>89000</salary>
<gender>female</gender>
<maritalStatus>married</maritalStatus>
<workStatus>Contract</workStatus>
</employee>
<employee empID="191">
<name>Michell, Eloise</name>
<position>Mgr Cap Rptg Dist</position>
<phone>x19826</phone>
<email>[email protected]/harrisbarnes</email>
<department>Sales</department>
<salary>188000</salary>
<gender>female</gender>
<maritalStatus>single</maritalStatus>
<workStatus>Full Time</workStatus>
</employee>
<employee empID="289">
<name>Blackshear, Homer</name>
<position>Line Wrker A</position>
<phone>x14845</phone>
<email>[email protected]/harrisbarnes</email>
<department>Sales</department>
<salary>83000</salary>
<gender>male</gender>
<maritalStatus>married</maritalStatus>
<workStatus>Full Time</workStatus>
</employee>
<employee empID="288">
<name>Trumbull, Monroe</name>
<position>Prog/Analyst</position>
<phone>x27132</phone>
<email>[email protected]/harrisbarnes</email>
<department>Sales</department>
<salary>51500</salary>
<gender>male</gender>
<maritalStatus>single</maritalStatus>
<workStatus>Full Time</workStatus>
</employee>
BTW它驗證,但是頁面呈現爲搗成泥一起文本和數字。謝謝。
你'的xsl:for-each'沒有做任何事情目前(它是空的);把東西在裏面,讓你得到的東西出來吧......還有在'格式number'一個語法錯誤,你使用過的,正確的吧..爲什麼是輸入XML那麼大??;剪短請(並且讓它成爲一個有效的XML)。 –
對不起,在我的編輯器中修復了格式編號問題,但沒有在這裏。謝謝。也縮短文件。只是想讓人們瞭解它。 – Pau808
「*頁面呈現爲搗成泥一起文本和數字*」不,那是不會發生什麼變化。頁面呈現爲只有標題行的空表格。 –