Html 使用xslt从xml创建两个表,并基于它创建一个小于整数值的节点属性
我创建了一个xml文件,其中包含我最喜欢的15部电影,这些电影有几个属性。xml文件如下所示:Html 使用xslt从xml创建两个表,并基于它创建一个小于整数值的节点属性,html,xml,xslt,xpath,Html,Xml,Xslt,Xpath,我创建了一个xml文件,其中包含我最喜欢的15部电影,这些电影有几个属性。xml文件如下所示: <?xml version="1.0" encoding="utf-8" ?> <?xml-stylesheet href="movies.xslt" type="text/xsl" ?> <AllMovies> <movie id="01"> <title>Wizard of Oz</title> <
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="movies.xslt" type="text/xsl" ?>
<AllMovies>
<movie id="01">
<title>Wizard of Oz</title>
<director>King Vidor</director>
<year>1939</year>
<genre>
<g1>Classics, </g1>
<g2>Sci-Fi, </g2>
<g3>Fantasy</g3>
</genre>
<link>https://www.rottentomatoes.com/m/the_wizard_of_oz_1939/</link>
</movie>
<movie id="02">
<title>The Third Man</title>
<director>Carol Reed</director>
<year>1949</year>
<genre>
<g1>Classics, </g1>
<g2>Mystery, </g2>
<g3>Suspense</g3>
</genre>
<link>https://www.rottentomatoes.com/m/the-third-man/</link>
</movie>
<movie id="03">
<title>Citizen Kane</title>
<director>Orson Welles</director>
<year>1941</year>
<genre>
<g1>Classics, </g1>
<g2>Drama, </g2>
<g3>Mystery, </g3>
<g4>Suspense</g4>
</genre>
<link>https://www.rottentomatoes.com/m/citizen_kane/</link>
</movie>
<movie id="04">
<title>The Godfather</title>
<director>Francis Ford Coppola</director>
<year>1972</year>
<genre>
<g1>Suspense, </g1>
<g2>Drama</g2>
</genre>
<link>https://www.rottentomatoes.com/m/godfather/</link>
</movie>
<movie id="05">
<title>Inside Out</title>
<director>Pete Docter</director>
<year>2015</year>
<genre>
<g1>Comedy, </g1>
<g2>Animation, </g2>
<g3>Children</g3>
</genre>
<link>https://www.rottentomatoes.com/m/inside_out_2015/</link>
</movie>
<movie id="06">
<title>E.T. The Extra-Terrestrial</title>
<director>Steven Spielberg</director>
<year>1982</year>
<genre>
<g1>Sci-Fi, </g1>
<g2>Children, </g2>
<g3>Fantasy</g3>
</genre>
<link>https://www.rottentomatoes.com/m/et_the_extraterrestrial/</link>
</movie>
<movie id="07">
<title>Toy Story 3</title>
<director>Lee Unkrich</director>
<year>2010</year>
<genre>
<g1>Animation, </g1>
<g2>Comedy, </g2>
<g3>Children, </g3>
<g4>Sci-Fi</g4>
</genre>
<link>https://www.rottentomatoes.com/m/toy_story_3/</link>
</movie>
<movie id="08">
<title>Selma</title>
<director>Ava DuVernay</director>
<year>2015</year>
<genre>
<g1>Biopic, </g1>
<g2>History</g2>
</genre>
<link>https://www.rottentomatoes.com/m/selma/</link>
</movie>
<movie id="09">
<title>Zootopia</title>
<director>Bryon Howard</director>
<year>2016</year>
<genre>
<g1>Animation, </g1>
<g2>Comedy, </g2>
<g3>Action, </g3>
<g4>Adventure</g4>
</genre>
<link>https://www.rottentomatoes.com/m/zootopia/</link>
</movie>
<movie id="10">
<title>Taxi Driver</title>
<director>Martin Scorsese</director>
<year>1976</year>
<genre>
<g1>Drama, </g1>
<g2>Mystery, </g2>
<g3>Suspense</g3>
</genre>
<link>https://www.rottentomatoes.com/m/taxi_driver/</link>
</movie>
<movie id="11">
<title>The Dark Knight</title>
<director>Christopher Nolan</director>
<year>2008</year>
<genre>
<g1>Action, </g1>
<g2>Crime, </g2>
<g3>Drama</g3>
</genre>
<link>https://www.rottentomatoes.com/m/the_dark_knight</link>
</movie>
<movie id="12">
<title>The Girl with The Dragon Tattoo</title>
<director>David Fincher</director>
<year>2011</year>
<genre>
<g1>Drama, </g1>
<g2>Mystery, </g2>
<g3>Suspense</g3>
</genre>
<link>https://www.rottentomatoes.com/m/the_girl_with_the_dragon_tattoo/</link>
</movie>
<movie id="13">
<title>The Last King of Scotland</title>
<director>Kevin Macdonald</director>
<year>2006</year>
<genre>
<g1>Drama, </g1>
<g2>Thriller</g2>
</genre>
</movie>
<movie id="14">
<title>The Hurt Locker</title>
<director>Kathryn Gigelow</director>
<year>2009</year>
<genre>
<g1>Action, </g1>
<g2>Adventure, </g2>
<g3>Drama</g3>
</genre>
</movie>
<movie id="15">
<title>Aliens</title>
<director>James Cameron</director>
<year>1986</year>
<genre>
<g1>Horror, </g1>
<g2>Thriller, </g2>
<g3>Adventure, </g3>
<g4>Sci-Fi</g4>
</genre>
</movie>
</AllMovies>
此图像是不带if语句的输出,其中所有信息显示在一个表中:
提前感谢您的帮助。您需要在年
上移动条件,该条件用于检查与顶级文档节点相关的年
元素,以作为实际xsl:apply templates
select子句的一部分
i、 e而不是这个
<xsl:if test="year < 2005">
<xsl:apply-templates select="AllMovies/movie">
<xsl:sort select="title" order="ascending"/>
</xsl:apply-templates>
</xsl:if>
这样做
<xsl:apply-templates select="AllMovies/movie[year < 2005]">
<xsl:sort select="title" order="ascending"/>
</xsl:apply-templates>
请注意,对于另一个模板,您将需要执行=
,而不仅仅是
,您还需要在年
上移动条件,该条件检查与顶级文档节点相关的年
元素,以作为实际xsl:apply templates
选择子句的一部分
i、 e而不是这个
<xsl:if test="year < 2005">
<xsl:apply-templates select="AllMovies/movie">
<xsl:sort select="title" order="ascending"/>
</xsl:apply-templates>
</xsl:if>
这样做
<xsl:apply-templates select="AllMovies/movie[year < 2005]">
<xsl:sort select="title" order="ascending"/>
</xsl:apply-templates>
请注意,对于另一个模板,您将需要执行=
,而不仅仅是
,如果您想要有两个单独的表,那么您的主模板应该按照以下几行进行结构:
<xsl:template match="/AllMovies">
<html>
<head>
<title>Assignment 1</title>
<style>
/*removed for brevity*/
</style>
</head>
<body>
<xsl:variable name="header">
<tr id="headers">
<th id="id">ID</th>
<th id="title">Title</th>
<th id="director">Director</th>
<th id="year">Year</th>
<th id="genre">Genre</th>
<th id="link">Link</th>
</tr>
</xsl:variable>
<h1>Before 2005</h1>
<table>
<xsl:copy-of select="$header"/>
<xsl:apply-templates select="movie[year < 2005] ">
<xsl:sort select="title" order="ascending"/>
</xsl:apply-templates>
</table>
<h1>2005 and later</h1>
<table>
<xsl:copy-of select="$header"/>
<xsl:apply-templates select="movie[year >= 2005] ">
<xsl:sort select="title" order="ascending"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
任务1
/*为简洁起见,请删除*/
身份证件
标题
经理
年
体裁
链接
2005年以前
2005年及以后
如果您想要有两个单独的表,那么您的主模板应该按照以下几行进行结构:
<xsl:template match="/AllMovies">
<html>
<head>
<title>Assignment 1</title>
<style>
/*removed for brevity*/
</style>
</head>
<body>
<xsl:variable name="header">
<tr id="headers">
<th id="id">ID</th>
<th id="title">Title</th>
<th id="director">Director</th>
<th id="year">Year</th>
<th id="genre">Genre</th>
<th id="link">Link</th>
</tr>
</xsl:variable>
<h1>Before 2005</h1>
<table>
<xsl:copy-of select="$header"/>
<xsl:apply-templates select="movie[year < 2005] ">
<xsl:sort select="title" order="ascending"/>
</xsl:apply-templates>
</table>
<h1>2005 and later</h1>
<table>
<xsl:copy-of select="$header"/>
<xsl:apply-templates select="movie[year >= 2005] ">
<xsl:sort select="title" order="ascending"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
任务1
/*为简洁起见,请删除*/
身份证件
标题
经理
年
体裁
链接
2005年以前
2005年及以后
谢谢你,Michael,你的解决方案奏效了,但我不得不将“电影[2005年]”更改为完全合格的“所有电影/电影[年…”位置。你可能错过了我的
。谢谢你,Michael,你的解决方案奏效了,但我不得不将“电影[2005年]”更改为完全合格的“所有电影/电影[年…”位置。你可能错过了我的
。真正有趣的是,我是如何用各种方法接近解决方案的,但一直没有完全实现。谢谢你,蒂姆,你帮了我大忙。真正有趣的是,我是如何用各种方法接近解决方案的,但一直没有实现。谢谢你,蒂姆,谢谢你我们帮了大忙。