Check if the data field has content - normalize-space XSL

Author:AnnJ
Last Updated:October 04, 2017 11:41 AM

This xsl snippet is used with data schema fields of text 1 and textarea, and maybe a few others..... But not lookups or links.

This test checks to see if the ListingTeaser is empty or not. If it is empty, the code nested in it will not be run. So the html will not show up on the website.   <xsl:if test="(.)!=''">

Adding normalize-space to the test is especially useful if the content author removed data from the data field, sometimes the database has some residual content. In those cases, the content author thinks the field is empty, but the html is still rendered display side. 

    <xsl:template match="ListingTeaser" mode="oneField">
        <xsl:param name="StyleNode" />
        <xsl:if test="normalize-space(.)!=''">
            <p class="shortTeaser">
                <xsl:value-of select="." disable-output-escaping="yes" />
            </p>
        </xsl:if>
    </xsl:template>

top