Html 如何将XML和XSLT文件加载到浏览器中

Html 如何将XML和XSLT文件加载到浏览器中,html,xml,xslt,Html,Xml,Xslt,我已经创建了一个XML和XSL文件,作为HTML加载到网页上。由于某种原因,这是行不通的。。数据未显示在web浏览器上的表中 下面是我的代码,有什么我遗漏的吗?请帮忙 XML文件代码: <?xml version="1.0"?> <?xml-stylesheet href="skymovies.xsl" type="text/xsl"?> <collection> <film> <title>Happy Gilmore<

我已经创建了一个XML和XSL文件,作为HTML加载到网页上。由于某种原因,这是行不通的。。数据未显示在web浏览器上的表中

下面是我的代码,有什么我遗漏的吗?请帮忙

XML文件代码:

<?xml version="1.0"?>
<?xml-stylesheet href="skymovies.xsl" type="text/xsl"?>
<collection>
  <film>
    <title>Happy Gilmore</title>
    <year>1991</year>
    <genre>Comedy</genre>
  </film>
  <film>
    <title>Rango</title>
    <year>1991</year>
    <genre>Comedy</genre>
  </film>
  <film>
    <title>Happy Gilmore</title>
    <year>1991</year>
    <genre>Comedy</genre>
  </film>
  </movie>
</collection>
<?xml version="1.0" encoding="IS0-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/collection">
    <html>
    <body>
      <table border="1">
        <tr>
          <th>Title</th>
          <th>Year</th>
          <th>Genre</th>
        </tr>

        <xsl:for-each select="film">
         <xsl:value-of select="title" /></td>
         <xsl:value-of select="year" /></td>
         <xsl:value-of select="genre" /></td>
        </xsl:for-each>
      </table>
    </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

快乐吉尔摩
1991
喜剧片
兰戈
1991
喜剧片
快乐吉尔摩
1991
喜剧片
XSLT文件代码:

<?xml version="1.0"?>
<?xml-stylesheet href="skymovies.xsl" type="text/xsl"?>
<collection>
  <film>
    <title>Happy Gilmore</title>
    <year>1991</year>
    <genre>Comedy</genre>
  </film>
  <film>
    <title>Rango</title>
    <year>1991</year>
    <genre>Comedy</genre>
  </film>
  <film>
    <title>Happy Gilmore</title>
    <year>1991</year>
    <genre>Comedy</genre>
  </film>
  </movie>
</collection>
<?xml version="1.0" encoding="IS0-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/collection">
    <html>
    <body>
      <table border="1">
        <tr>
          <th>Title</th>
          <th>Year</th>
          <th>Genre</th>
        </tr>

        <xsl:for-each select="film">
         <xsl:value-of select="title" /></td>
         <xsl:value-of select="year" /></td>
         <xsl:value-of select="genre" /></td>
        </xsl:for-each>
      </table>
    </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

标题
年
体裁

我做错什么了吗?请帮助?

您的XML无效。XML中有一个
,它没有开始标记。尝试使用以下XML:

<?xml version="1.0"?>
<?xml-stylesheet href="skymovies.xsl" type="text/xsl"?>
<collection>
  <film>
    <title>Happy Gilmore</title>
    <year>1991</year>
    <genre>Comedy</genre>
  </film>
  <film>
    <title>Rango</title>
    <year>1991</year>
    <genre>Comedy</genre>
  </film>
  <film>
    <title>Happy Gilmore</title>
    <year>1991</year>
    <genre>Comedy</genre>
  </film>
</collection>

快乐吉尔摩
1991
喜剧片
兰戈
1991
喜剧片
快乐吉尔摩
1991
喜剧片

您的XSLT也无效:您有从未打开的关闭标签。您还忘记为每部影片创建一行。它应该看起来像:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/collection">
    <html>
    <body>
      <table border="1">
        <tr>
          <th>Title</th>
          <th>Year</th>
          <th>Genre</th>
        </tr>
        <xsl:for-each select="film">
        <tr>
           <td><xsl:value-of select="title" /></td>
           <td><xsl:value-of select="year" /></td>
           <td><xsl:value-of select="genre" /></td>
         </tr>
        </xsl:for-each>
      </table>
    </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

标题
年
体裁

您好,谢谢您的回复。。但这似乎也不起作用。为了澄清这一点,我在InternetExplorer中通过双击.xml文件来运行它。这是运行这些文件的正确方法吗?不用担心,先生,您提供的解决方案现在正在运行!非常感谢。上帝保佑!一旦这些文件开始工作,通过在浏览器中单击来运行这些文件就可以了,但正如您所发现的,这并不是一个非常友好的调试环境。如果你是那种有时会犯错误的人,那么你会发现在Stylus Studio或oXygen等工具中开发XSLT代码会更有效率。@MichaelKay请将你的评论发到OP上。非常感谢。上帝保佑