页面不显示电影我错过了什么

  • 本文关键字:错过了 电影 显示 xml xslt
  • 更新时间 :
  • 英文 :


这是我的XSL表

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="movie" match="movie" use="." /> 
<xsl:template match="/">
<html>
<head>
<title>Top American Comedies</title> 
<link href="comedy.css" rel="stylesheet" type="text/css" /> 
</head>
<body>
<h2>The Top American Comedy Films</h2> 
<p>Number of Ballots:162</p> 
<table>
<tr>
<th>Rank</th> 
<th>Movie</th> 
<th>Votes</th> 
<th>%</th> 
<xsl:for-each select="movie">
<tr>
<td>position</td> 
<td>movie</td> 
<td class="right" /> 
<td class="right" /> 
</tr>
</xsl:for-each>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

这是我的XML代码

<?xml-stylesheet type="text/xsl" href="comtxt.xsl" ?>
<poll>
<ballot id="b1">
<movie>A FISH CALLED WANDA (1988)</movie>
<movie>ADAM'S RIB (1949)</movie>
<movie>ANNIE HALL (1977)</movie>
<movie>BEING THERE (1979)</movie>
<movie>BORN YESTERDAY (1950)</movie>
 <movie>CITY LIGHTS (1931)</movie>
<movie>DR. STRANGELOVE (1964)</movie>
<movie>GOOD MORNING, VIETNAM (1987)</movie>
<movie>HIS GIRL FRIDAY (1940)</movie>
<movie>M*A*S*H (1970)</movie>
<movie>MOONSTRUCK (1987)</movie>
<movie>NATIONAL LAMPOON'S ANIMAL HOUSE (1978)</movie>
<movie>SILVER STREAK (1976)</movie>
<movie>SOME LIKE IT HOT (1959)</movie>
<movie>THE GENERAL (1927)</movie>
<movie>THE GRADUATE (1967)</movie>
<movie>THE ODD COUPLE (1968)</movie>
<movie>THE SEVEN YEAR ITCH (1955)</movie>
<movie>TO BE OR NOT TO BE (1942)</movie>
<movie>WHAT'S UP, DOC? (1972)</movie>
</ballot>    
<ballot id="b162">
<movie>A DAY AT THE RACES (1937)</movie>
<movie>ABBOTT AND COSTELLO MEET FRANKENSTEIN (1948)</movie>
<movie>AMERICAN GRAFFITI (1973)</movie>
<movie>BANANAS (1971)</movie>
<movie>BLAZING SADDLES (1974)</movie>
<movie>CADDYSHACK (1980)</movie>
<movie>DR. STRANGELOVE (1964)</movie>
<movie>GHOSTBUSTERS (1984)</movie>
<movie>HIS GIRL FRIDAY (1940)</movie>
<movie>IT'S A MAD MAD MAD MAD WORLD (1963)</movie>
<movie>MODERN TIMES (1936)</movie>
<movie>NATIONAL LAMPOON'S ANIMAL HOUSE (1978)</movie>
<movie>SHE DONE HIM WRONG (1933)</movie>
<movie>SOME LIKE IT HOT (1959)</movie>
<movie>THE AWFUL TRUTH (1937)</movie>
<movie>THE GRADUATE (1967)</movie>
<movie>THE ODD COUPLE (1968)</movie>
<movie>THE PRODUCERS (1968)</movie>
<movie>THIS IS SPINAL TAP (1984)</movie>
<movie>TOPPER (1937)</movie>
</ballot>
</poll>

如果能帮忙就太好了。我一直在这个工作一段时间,现在我不知道我错了。

首先,您还没有解释转换应该使用什么规则生成。也没有显示预期的正确输出。

一些观察:

  1. <xsl:key>指令没有在你的代码中使用,可以安全地删除

  2. 这显然是错误的: <xsl:for-each select="movie">。文档节点没有movie子节点,因此select属性中的XPath表达式不选择任何东西——因此<xsl:for-each>中的代码正好执行0次。

这是一个猜测,再次:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
  <html>
    <head>
     <title>Top American Comedies</title>
     <link href="comedy.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <h2>The Top American Comedy Films</h2>
        <p>Number of Ballots:162</p>
        <table>
            <tr>
                <th>Rank</th>
                <th>Movie</th>
                <th>Votes</th>
                <th>%</th>
                <xsl:for-each select="/*/*/movie">
                    <tr>
                        <td><xsl:value-of select="position()"/></td>
                        <td><xsl:value-of select="."/></td>
                        <td class="right" />
                        <td class="right" />
                    </tr>
                </xsl:for-each>
            </tr>
        </table>
   </body>
  </html>
 </xsl:template>
</xsl:stylesheet>

相关内容

最新更新