2016-02-25 84 views
0

我正在使用XSLT將IE11中的XML文件顯示爲HTML。 我看到的不是HTML,而是純文本。 這兩個文件都保存在同一個文件夾中。瀏覽器爲XML/XSLT顯示純文本而非HTML

我比較/在W3School

兩個文件是基於下面我XSL文件關閉的例子。

RuleDefinitions.xml:

<?xml-stylesheet type= "html/xsl" href= "RuleDescriptions.xsl"?> 
<rules> 
    <rule> 
     <term>FCFPriRegExp</term> 
     <title>ClassNameRegexp</title> 
     <description>This rule specifies the naming conventions for private final 
     class fields. The definition is done with a regexp (Regular 
     expression)</description> 
    </rule> 
    <rule> 
     <term>RegExpPrefixForMethodReturingBoolean</term> 
     <title>MethodReturningBoolean</title> 
     <description>This rule specifies the regexp for a method returning a 
     boolean value. In general a method returning a boolen is phrased like a 
     question and should normally comply to isEmpty(), hasMoreElements(), 
     areBlack(), ... Here you can specify a regexp which describes the name 
     for methods returning a boolean value.</description> 
    </rule> 

RuleDefinitions.xsl

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" 
     xlmns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns="http://www.w3.org/1999/xhtml"> 
<xsl:template match="/"> 
    <html xlns="http://www.w3.org/1999/xhtml"> 
     <head> 
      <title>Java Code Standard Rules</title> 
     </head> 
     <body> 
      <table border="1"> 
       <tr bgcolor="#9acd32"> 
        <th>Term</th> 
        <th>Title</th> 
        <th>Description</th> 
       </tr> 
       <xsl:for-each select="rules/rule"> 
       <tr> 
        <td><xsl:value-of select="term"/></td> 
        <td><xsl:value-of select="title"/></td> 
        <td><xsl:value-of select="description"/></td> 
       </tr> 
       </xsl:for-each> 
      </table> 
     </body> 
    </html> 
</xsl:template> 
</xsl:stylesheet> 

回答

0

有幾件事情你錯了展示的樣品中,雖然在第一種情況下它可能只是一個錯字你的問題。

首先,在您的XML示例中,由於缺少結束</rules>標記,所以您的XML格式不正確。

其次,可能更可能是原因,是您在「xsl」前綴的名稱空間聲明中拼錯了「xmlns」。

取而代之的是...

xlmns:xsl="http://www.w3.org/1999/XSL/Transform" 

它應該是這樣。

xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 

編輯:正如評論中提到的(謝謝你!)你也應該檢查你的文件名是否正確。該XML包含對「RuleDescriptions.xsl」的引用,但在您的問題中,您已將該文件標記爲「RuleDefinitions.xsl」

+0

並且xml中的href是錯誤的 – wero

+0

好點!我已經修改了我的答案。非常感謝您指出這一點! –

+0

謝謝,@TimC和wero, 文件名是拼寫錯誤,但代碼是複製粘貼的,雖然我沒有包含整個1000+行XML文件,所以「」就在那裏。 我很感激你的幫助。 – Zaxxon

相關問題