【发布时间】:2015-10-23 19:05:02
【问题描述】:
在过去的一个小时里,我一直在用头撞墙,试图弄清楚为什么 if 不起作用,我需要一双新的眼睛来告诉我我在逻辑上遗漏了什么。 if 在第 25 行之后开始。它应该起作用,老实说,它遵循以下示例:http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=tryxsl_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>
【问题讨论】:
-
你需要一个更好的测试工具,它可以告诉你哪里出了问题。
-
@michael.hor257k 你推荐哪一个?
-
这取决于您的需求和平台。至少,使用像样的在线工具,例如xsltransform.net
-
@michael.hor257k 遵循了它所说的建议:xsl 错误:第 26 行第 33 列 XTSE0010 上的排序错误:xsl:if 元素不得包含 xsl:sort 元素
-
在您发布的样式表中,xsl:sort (正确地)是 xsl:for-each 的第一个孩子 - 所以您描述的问题不会发生。
标签: xml xslt if-statement logic