2013-03-11 37 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>