1

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>

3 Answers 3

1

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>
Sign up to request clarification or add additional context in comments.

Comments

0

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)">

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.