Copied to clipboard

Flag this post as spam?

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


  • Carlos 338 posts 472 karma points
    Jan 27, 2012 @ 20:42
    Carlos
    0

    convert XSLT number to string

    Probably an easy answer but I don't quite know the syntax.  

    I want to convert a false value on a check box in the admin section, which returns 0, to a string that outputs the string word "False" so I can use it on the front end.

    Anyone have any suggestions?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 27, 2012 @ 22:43
    Chriztian Steinmeier
    0

    Hi Carlos,

    There's (atleast) two ways to do this - use whichever you feel is right:

    <xsl:template match="/">
        <!-- Grab the value -->
        <xsl:variable name="checkboxValue" select="$currentPage/checkboxPropertyName" />
    
        <!-- Method 1 -->
        <xsl:value-of select="translate(string(boolean(number($checkboxValue))), 'ft', 'FT')" />
    
        <!-- Method 2: -->
        <xsl:choose>
            <xsl:when test="$checkboxValue = 1">
                <xsl:text>True</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>False</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    The one-liner is the technically correct one, but may be tricky to understand, the other one is fairly straight-forward, though verbose ...

    /Chriztian

     

  • Rodion Novoselov 694 posts 859 karma points
    Jan 30, 2012 @ 02:40
    Rodion Novoselov
    0

    Perhaps a bit more complecated still more righteous way could be even:


    <xsl:value-ofselect="umbraco.library:GetDictionaryItem(boolean(number($checkboxValue)))"/>

    and than to define True/False in the dictionary.

Please Sign in or register to post replies

Write your reply to:

Draft