2013-03-11 50 views
1

我想隐藏“imageText”,div IF字符串为空。此刻,此imageText将文本叠加到具有背景色的图像上(文本在Umbraco中指定)。XSLT隐藏元素IF字符串为空

我已经尝试过:

<xsl:if test = "imageText" != ''"> 

可能有人请帮助我做到这一点?

这里是我的代码:

<td width="300" height="114" valign="top"> 

    <div class="imageTitle"> 
    <xsl:call-template name="getText"> 
     <xsl:with-param name="imageText" select="$bottomImageLeftText" /> 
    </xsl:call-template> 
    </div> 

    </td> 

回答

1

就是在一个元素中的文本称为imageText或者是在一个名为$bottomImageLeftText变量?这似乎是后者,那么请试试这个:

<td width="300" height="114" valign="top"> 
    <xsl:if test="$bottomImageLeftText != ''"> 
    <div class="imageTitle"> 
     <xsl:call-template name="getText"> 
     <xsl:with-param name="imageText" select="$bottomImageLeftText" /> 
     </xsl:call-template> 
    </div> 
    </xsl:if> 
</td> 
+0

惊人!非常感谢你,它的作品非常漂亮:) – Madness 2013-03-11 13:51:56

0

你需要对你会传递给with-param值条件下,没有参数名称(这是唯一有意义的被叫模板)。所以包装在

<xsl:if test="string($bottomImageLeftText)"> 

这个div元素包括div和它的内容如果$bottomImageLeftText字符串值非空 - 包括它仅包含空格的情况。如果你要正确对待空白,只一样完全空的,你可以使用

<xsl:if test="normalize-space($bottomImageLeftText)"> 
0

我会尝试这样的:

<!-- Code which calls the getText template and passes the bottomImageLeftText variable --> 
<xsl:call-template name="getText"> 
    <xsl:with-param name="imageText" select="$bottomImageLeftText" /> 
</xsl:call-template> 

<!-- getText template which checks the param imageText for an empty string. --> 
    <xsl:template name="getText" > 
    <xsl:param name="imageText" /> 

    <xsl:if test="$imageText" > 
     <div class="imageTitle"> 
     <!-- your code, display image title --> 
     </div> 
     </xsl:if> 
    </xsl:template>