XML文件没有关联的样式表

时间:2013-12-05 17:20:58

标签: xml xslt

当我在浏览器中使用.xml运行网页时,它只显示代码和以下语句:

此XML文件似乎没有与之关联的任何样式信息。文档树如下所示。

这是我的XML代码:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href=wonders.xsl" ?>

<seven_wonders>
    <wonder>    
        <name>Great Pyramid Of Giza</name>
        <location>Giza Necropolis, Egypt</location>
        <builder>Egyptians</builder>
        <constructed>2584-2561 BC</constructed>
    </wonder>
    <wonder>    
        <name>Hanging Gardens of Babylon</name>
        <location>Hillah, Babylon Province, Iraq or Nineveh, Nineveh Province, Iraq</location>
        <builder>Babylonians</builder>
        <constructed>c. 600 BC</constructed>
    </wonder>
    <wonder>    
        <name>Temple of Artemis at Ephesus</name>
        <location>Selcuk, Izmir Province, Turkey</location>
        <builder>Lydians, Greeks</builder>
        <constructed>c. 550 BC</constructed>
    </wonder>
    <wonder>    
        <name>Statue of Zeus at Olympia</name>
        <location>Olympia, Greece</location>
        <builder>Greeks</builder>
        <constructed>466-435 BC</constructed>
    </wonder>
    <wonder>    
        <name>Mausoleum at Halicarnassus</name>
        <location>Bodrum, Turkey</location>
        <builder>Carians, Greeks</builder>
        <constructed>351 BC</constructed>
    </wonder>
    <wonder>    
        <name>Colossus of Rhodes</name>
        <location>Rhodes, Greece</location>
        <builder>Greeks</builder>
        <constructed>292-280 BC</constructed>
    </wonder>
    <wonder>    
        <name>Lighthouse of Alexandria</name>
        <location>Alexandria, Egypt</location>
        <builder>Ptolemaic Egypt, Greeks</builder>
        <constructed>c. 280 BC</constructed>
    </wonder>                       
</seven_wonders>                                

这是我的.xsl文件

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="ISO-8859-1" indent="yes" standalone="yes" />

<xsl:template match="/">
<html>
   <body>
    <head>
       <title>Seven Wonders of the Ancient World</title>
    </head>
    <table border="2" cellpadding="8" cellspacing="3">
       <tr bgcolor="gray">
        <th><b>Name</b></th>
        <th><b>Location</b></th>
        <th><b>Builder</b></th>
        <th><b>Date of Construction</b></th>
       </tr>
       <xsl:for-each select="seven_wonders/wonder">
       <tr valign="top">
        <td><xsl:value-of select="name"/></td>
        <td><xsl:value-of select="location"/></td>
        <td><xsl:value-of select="builder"/></td>
        <td><xsl:value-of select="constructed"/></td>
       </tr>
       </xsl:for-each>
       <tr>
        <td><i>Resource</i></td>
        <td colspan="3"><a href="http://en.wikipedia.org/wiki/Seven_Wonders_of_the_Ancient_World">http://en.wikipedia.org/wiki/Seven_Wonders_of_the_Ancient_World</a></td>
       </tr>
    </table>
   </body>
</html>
</xsl:template>

</xsl:stylesheet>

我对这一切都比较新,所以如果有人能告诉我我做错了什么,我真的很感激!谢谢!

1 个答案:

答案 0 :(得分:1)

这是错误,在修复它之后,文档加载并转换得很好:

<xsl:output method="html" encoding="ISO-8859-1" indent="yes" standalone="yes" />

您需要method="html",否则IE认为这是XML并相应地格式化

Here's a specification,但你做得对。