2016-05-07 80 views
0

我想使用Saxon XSLT 2.0簡單轉換(使用Exchanger XML編輯器)從XML和XSL文檔生成HTML文件,但XML文件中的數據沒有獲取已接。我假設我在我的XSL樣式表中有錯誤,但我不知道在哪裏。XSLT 2.0轉換不生成合適的html文檔

我已上傳的所有4個文件(1個XSL,1個XML,CSS 1和1 PNG),它們需要創建這裏的完整的HTML文檔... 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> 

回答

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

這幫了一下,謝謝。雖然大部分文件仍然沒有顯示。 – codeRed

+0

顯示xml中的所有信息,但未在html中格式化。此外,它是每個員工的所有信息,而不是xsl試圖檢索的選定信息。 – codeRed

+0

@codeRed,我做了一些更正,併發布了一個完整的樣式表,因爲我現在在我的桌面上,不再發布我的手機。 –