Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Umbraco 137 posts 294 karma points
    Jul 25, 2012 @ 15:34
    Umbraco
    0

    How to test if a field is left empty?

    I have a document type with a textstring field that is left empty. Testing if the field is equal to an empty string doesn't work in an XSLT macro. I need to test if the field is false.

    xsl:if test="$node/field != ''" doesn't work.

    xsl:if test="$node/field" works.

    Strange thing is that in the live environment the first test actually works as well. The only difference is that the live environment runs 4.7.1 and the dev environment runs 4.7.1.1.

    Given that it seems to work inconsistently, what is the preferred way to check if a field is empty?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jul 25, 2012 @ 16:13
    Lee Kelleher
    1

    Hi Michiel,

    I usually go with a "normalize-space" check:

    <xsl:if test="normalize-space($node/field)">

    This will return true if the 'field' exists and is non-empty/non-whitespace.

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft