簡體   English   中英

瀏覽器顯示純文本而不是XML / XML的HTML

[英]Browser Displays plain text not HTML for XML/XSLT

我正在使用XSLT通過IE11將XML文件顯示為HTML。 我看到的不是HTML,而是純文本。 這兩個文件都保存到同一文件夾中。

我已經將w3schools的示例與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>

您顯示的示例有幾處錯誤,盡管在第一種情況下,可能只是您所輸入問題的錯字。

首先,在您的XML示例中,您缺少</rules>標記,因此您的XML格式不正確。

其次,可能是更可能的原因是,您在名稱空間聲明中為“ xsl”前綴誤寫了“ xmlns”。

代替這個...

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

應該是這個

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

編輯:並且正如在評論中提到(謝謝wero!),您還應該檢查文件名是否正確。 XML包含對“ RuleDescriptions.xsl”的引用,但是在您的問題中,您已將該文件標記為“ RuleDefinitions.xsl”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM