我按照说明进行操作,我的XML和XSL文件不起作用

时间:2019-04-25 03:40:59

标签: xml validation xslt

1。转到编辑器中的hbemployees.xsl文件。在打开样式表元素之后,直接创建部门关键字,使其与employee元素匹配,并使用Department元素作为关键字索引。该密钥的目的是按部门对员工进行分组。

  1. 直接在“ h1雇员报告”标题之后,插入一个for-each元素,该元素使用Muenchian分组通过以下位置路径来选择每个唯一部门:“ // employee [generate-id()= generate-id (键(“部门”,部门)[1])]” 然后按部门对结果进行排序。

  2. 每次通过for-each循环,将以下HTML代码写入结果文档:

    <table class="employeeList"> <caption>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>
    </tbody>
    </table>
    

其中department是department元素的值。

  1. 在您刚编写的HTML代码的tbody元素中,使用 部门关键字和部门元素的当前值,以便显示有关当前显示部门中每个员工的信息。按薪金元素的降序对应用的模板进行排序。

  2. 在根模板之后,直接插入一个与employee元素匹配的新模板。该模板的目的是写一个包含所选雇员信息的表行。让模板将以下HTML代码写入结果文档:

    <tr>
    <td>name</td> 
    <td>position</td> 
    <td>salary</td> 
    <td>phone</td>
    <td>gender</td>
    <td>marital status</td>
    <td>working status</td>
    </tr> 
    

    其中,姓名,职位,薪水,电话,性别,婚姻状况和工作状态是姓名,职位,薪水,电话,性别,martialStatus和workingStatus元素的值。格式化薪水,使其以货币显示。

我不确定为什么我的文件不起作用。

<?xml version="1.0" encoding="UTF-8" ?>
<!--
   New Perspectives on XML, 3rd Edition
   Tutorial 7
   Case Problem 1

   Harris and Barnes Style Sheet

   Filename:         hbemployees.xsl
   Supporting Files: hbemployees.xml
-->


<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:key name="departments" match="employee" use="department" />

   <xsl:variable name="hbemployessDoc" select="document('hbemployess.xml')" />

   <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" />

                  <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>

               </xsl:for-each>

             </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="193">
      <name>Fleming, Angela</name>
      <position>Inventory Ck</position>
      <phone>x31751</phone>
      <email>afleming30@example.com/harrisbarnes</email>
      <department>Sales</department>
      <salary>99000</salary>
      <gender>female</gender>
      <maritalStatus>married</maritalStatus>
      <workStatus>Full Time</workStatus>
   </employee>
</employees>

0 个答案:

没有答案