首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果在xlst不工作

如果在xlst不工作
EN

Stack Overflow用户
提问于 2015-10-23 19:05:02
回答 1查看 44关注 0票数 0

在过去的一个小时里,我一直把头撞在墙上,试图弄清楚为什么如果不起作用,我需要一双全新的眼睛来告诉我,我在逻辑上缺少了什么。if就在第25行之后开始。它应该工作,老实说,它遵循的例子是:if,但它什么也不做!

请看下面:

代码语言:javascript
复制
<?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>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-23 19:10:40

<xsl:if/>应该是一个</xsl:if>,因为它是一个结束标记,而不是自引用标记。

以下是修正后的代码:

代码语言:javascript
复制
<?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 &gt; 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>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33309681

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档