根据参数动态编写img标签 [英] Dynamically write img tags depending on parameter

查看:75
本文介绍了根据参数动态编写img标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态写出一定数量的重复图像(例如星星)以反映评级。我的代码使用< xsl:if>但现在我正试图让它成为其他地方使用的模板。

原始代码:

I want to dynamically write out a certain number of repeated images (stars, for example) to reflect a rating.  I have code that is using <xsl:if> but now I'm trying to make it a template for use elsewhere. 

Original code:

<TD>
<xsl:if test="@Avg &lt; .5">No rating</xsl:if>
<xsl:if test="@Avg &gt;= .5 and @Avg &lt; 1">
   <IMG src="{$Img} border="0"/>
</xsl:if>



模板:


Template:

<xsl:template name="WriteStars">
  <xsl:param name="CurValue"/>
  <xsl:choose>
     <xsl:when test="$CurValue &lt; .5">No Rating
     </xsl:when>
     <xsl:when test="$CurValue &gt;=.5 and $CurValue &lt; 1">
         <IMG src="{$ImgName}" border="0"/>
     </xsl:when>
    </xsl:choose>
</xsl:template>



如何调用模板:


How template is called:

<xsl:call-template name="WriteStars">
     <xsl:with-param name="CurValue" select="@MyRating"/>
</xsl:call-template>


如果正在评估正确的xsl:when语句,我会得到"< IMG src"的文字输出= QUOT; {$ ImgName}"边界=" 0" />"而不是看到一个图像。

What happens is that the correct xsl:when statement is being evaluated but I get the literal output of "<IMG src="{$ImgName}" border="0"/>" instead of seeing an image. 

推荐答案



您尚未定义'ImgName'变量。如果你定义它,模板就可以正常工作了。





You have not defined the 'ImgName' variable. If you define it, the template is working fine.




这篇关于根据参数动态编写img标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆