首页 文章

不知道为什么我的表和模板没有出现在我的XSL文件中并且出现Muenchian分组问题

提问于
浏览
0

我一直致力于这个分配XSL样式表,它显示员工信息并按部门对其进行分组并按降序排序 . 我使用for-each元素,使用Muenchian分组通过使用此位置路径对每个唯一的部门进行排序 . 赋值告诉我,每次通过for-each循环,它都会写出“employeeList”表的代码 . “部门”是部门元素的 Value .

它还告诉我插入一个“匹配”employee元素的新模板 . 该模板应该写一个包含所选员工信息的表行 . 这是代码:

<?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>mheffner50@example.com/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>nmurff63@example.com/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>avecchio55@example.com/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>rlewis19@example.com/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>wwhite61@example.com/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>jwilliams31@example.com/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>dclark16@example.com/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>rsand25@example.com/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>emichell34@example.com/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>hblackshear74@example.com/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>mtrumbull49@example.com/harrisbarnes</email>
      <department>Sales</department>
      <salary>51500</salary>
      <gender>male</gender>
      <maritalStatus>single</maritalStatus>
      <workStatus>Full Time</workStatus>
   </employee>

BTW它验证但页面呈现为文本和数字 . 谢谢 .

1 回答

  • 1

    如果 - 看起来 - 你想要一个每个部门的表,你必须放置表 inside xsl:for-each 指令 .

    IOW,移动结束标记 </xsl:for-each> ,以便它在 </table> 之后立即出现 .

    还要注意:

    <td>><xsl:value-of select="workingStatus" /></td>
    

    返回一个只包含 > 字符的单元格,因为(1)在 <td> 之后你有一个额外的 > 和(2)输入中没有 workingStatus 元素 .

    还要确保按薪水排序时, xsl:sort 元素具有 data-type="number" 属性 . 否则,您将在$ 262,000之前看到$ 83,000(按字母顺序排列) .

相关问题