我试图从一个 xml 文件中获取包含某些电影的数据,本周正在播放的所有电影,但它会打印出所有电影..我是新手< em> xml 和 xslt 所以,任何帮助将不胜感激!我的 xml 看起来像:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="movies.xsl"?>
<?xml-stylesheet type="text/css" href="movies.css"?>
<movies>
<movie>
<title> Title1 </title>
<actor> Actor1 </actor>
<genre> Genre1 </genre>
<dateOfPlaying>20160403</dateOfPlaying>
<duration> Duration1 </duration>
</movie>
<movie>
<title> Title2 </title>
<actor> Actor2 </actor>
<genre> Genre2 </genre>
<dateOfPlaying>20160420</dateOfPlaying>
<duration> Duration2 </duration>
</movie>
<movie>
<title> Title2 </title>
<actor> Actor2 </actor>
<genre> Genre2 </genre>
<dateOfPlaying>20160406</dateOfPlaying>
<duration>Duration3</duration>
</movie>
</movies>
和 xsl 文件:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<h2> Movies report </h2>
<table>
<xsl:for-each select="movies/movie">
<xsl:if test="number(dateOfPlaying) > 20160401 and number(dateOfPlaying) < 20160408">
<tr>
<td>
<xsl:value-of select="title"/>
</td>
<td>
<xsl:value-of select="actor"/>
</td>
<td>
<xsl:value-of select="genre"/>
</td>
<td>
<xsl:value-of select="dateOfPlaying"/>
</td>
<td>
<xsl:value-of select="duration"/>
</td>
<tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
你需要这个:
<xsl:if test="dateOfPlaying > 20160401 and dateOfPlaying < 20160408">
我在<tr>
将其更正为</xsl:if>
</tr>
以下是xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<h2> Movies report </h2>
<table>
<xsl:for-each select="movies/movie">
<xsl:if test="dateOfPlaying > 20160401 and dateOfPlaying < 20160408">
<tr>
<td>
<xsl:value-of select="title"/>
</td>
<td>
<xsl:value-of select="actor"/>
</td>
<td>
<xsl:value-of select="genre"/>
</td>
<td>
<xsl:value-of select="dateOfPlaying"/>
</td>
<td>
<xsl:value-of select="duration"/>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
输出如下:
电影报道
Title1 Actor1 Genre1 20160403 Duration1
Title2 Actor2 Genre2 20160406 20160430