在过去的一个小时里,我一直把头撞在墙上,试图弄清楚为什么如果不起作用,我需要一双全新的眼睛来告诉我,我在逻辑上缺少了什么。if就在第25行之后开始。它应该工作,老实说,它遵循的例子是:if,但它什么也不做!
请看下面:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<!-- Background image -->
<body background="bgimage.jpg">
<h2 style="color:#47B2B2">My Movie Collection</h2>
<!-- set border, color, and padding-->
<table border="1" bgcolor="#0A1A1A" cellpadding="5">
<tr bgcolor="#1F4C4C">
<!-- Set order -->
<th>Title</th>
<th>Director</th>
<th>Year</th>
<th>Genre</th>
<th>ID</th>
</tr>
<xsl:for-each select="movies/movie">
<!-- Sort by title -->
<xsl:sort select="title"/>
<xsl:if test="year>2005">
<tr bgcolor="#3D9999">
<td>
<!-- Look for link, target to blank, the link text is the tittle pulled from xml -->
<a href="{link}" target="_blank"><xsl:value-of select="title"/></a>
</td>
<td>
<xsl:value-of select="director"/>
</td>
<td>
<xsl:value-of select="year"/>
</td>
<td>
<xsl:value-of select="genre"/>
</td>
<td>
<xsl:value-of select="movieID"/>
</td>
</tr>
<xsl:if/>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
发布于 2015-10-23 19:10:40
<xsl:if/>应该是一个</xsl:if>,因为它是一个结束标记,而不是自引用标记。
以下是修正后的代码:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<!-- Background image -->
<body background="bgimage.jpg">
<h2 style="color:#47B2B2">My Movie Collection</h2>
<!-- set border, color, and padding-->
<table border="1" bgcolor="#0A1A1A" cellpadding="5">
<tr bgcolor="#1F4C4C">
<!-- Set order -->
<th>Title</th>
<th>Director</th>
<th>Year</th>
<th>Genre</th>
<th>ID</th>
</tr>
<xsl:for-each select="movies/movie">
<!-- Sort by title -->
<xsl:sort select="title"/>
<xsl:if test="year > 2005">
<tr bgcolor="#3D9999">
<td>
<!-- Look for link, target to blank, the link text is the tittle pulled from xml -->
<a href="{link}" target="_blank"><xsl:value-of select="title"/></a>
</td>
<td>
<xsl:value-of select="director"/>
</td>
<td>
<xsl:value-of select="year"/>
</td>
<td>
<xsl:value-of select="genre"/>
</td>
<td>
<xsl:value-of select="movieID"/>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
https://stackoverflow.com/questions/33309681
复制相似问题