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