Reputation: 638
I want to hide "imageText" and the div IF string is empty. At the moment, this imageText overlays text onto an image with a background color (the text is specified in Umbraco).
I've already tried:
<xsl:if test = "imageText" != ''">
Could someone please help me accomplish this?
Here's my code:
<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>
Upvotes: 1
Views: 2889
Reputation: 4882
I would try something like this:
<!-- 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>
Upvotes: 0
Reputation: 122394
You need to condition on the value you would be passing to the with-param
, not the parameter name (which is only meaningful inside the called template). So wrap the div
element in a
<xsl:if test="string($bottomImageLeftText)">
This will include the div and its contents if the string value of $bottomImageLeftText
is non-empty - which includes the case where it contains only whitespace. If you want to treat whitespace-only the same as completely empty you can use
<xsl:if test="normalize-space($bottomImageLeftText)">
Upvotes: 0
Reputation: 101730
Is the text in an element called imageText
or is it in a variable called $bottomImageLeftText
? It seems like the latter, so please try this:
<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>
Upvotes: 1