匹配元素XSL

时间:2011-07-30 16:25:35

标签: xml xslt

继承我的样式表

<xsl:stylesheet version='1.0' xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="movie"/>
<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>

  <table>
  <tr>
      <th>Rank</th>
      <th>Movie</th>
      <th>Votes</th>
      <th>%</th>
  </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="b2">
 <movie>A DAY AT THE RACES (1937)</movie>
 <movie>A SHOT IN THE DARK (1964)</movie>
 <movie>AMERICAN GRAFFITI (1973)</movie>
 <movie>BALL OF FIRE (1941)</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>SHAMPOO (1975)</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>
 <ballot id="b3">
 <movie>A NIGHT AT THE OPERA (1935)</movie>
 <movie>AIRPLANE! (1980)</movie>
 <movie>ARSENIC AND OLD LACE (1944)</movie>
 </ballot>
 </poll>

接下来我得到的错误可以有人给我一个它应该是什么样的例子。我知道这一定是愚蠢的事,但我画的是空白。

 Element must have a match attribute
 xsl:key

1 个答案:

答案 0 :(得分:0)

<xsl:key name="movie"/>

这是非法/无效的

<xsl:key>条指令必须包含matchuse属性。

类似

<xsl:key name="kMovieByName" match="movie" use='.'/>

此外,您的代码根本不使用key()功能,因此您只需从中删除<xsl:key>,错误就会消失。