Copied to clipboard

Flag this post as spam?

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


  • Tony Kiernan 278 posts 341 karma points
    Dec 06, 2010 @ 13:25
    Tony Kiernan
    0

    An equivalent to isNull?

    Using the following to pull back a list of events sub pages

    <xsl:for-each select="$currentPage/descendant::* [
    @isDoc and string(umbracoNaviHide) != '1'
    and umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:DateAdd(pageDate, 'd', eventDuration))
    ]">

    Is there any way to make the eventDuration have a default value of zero?  Similar to in T-SQL

    isNull(eventDuration, 0)

    I'd rather not be running a check from inside the 'loop'

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Dec 06, 2010 @ 13:58
    Morten Bock
    0

    Your could write your own extension method for it, where you pass eventDuration and return 0 if the input is empty or null.

  • Tony Kiernan 278 posts 341 karma points
    Dec 06, 2010 @ 14:56
    Tony Kiernan
    0

    Can I take that as a 'No' in answer to my question?

    Edit: That wasn't meant half as snippily as it sounds

  • Thomas Stock 40 posts 70 karma points
    Dec 06, 2010 @ 15:03
    Thomas Stock
    1

    Well, you could call the extension method in the for-each select, but you will indeed have to make it yourself.

    It's a very small amount of work tho.

    Just create a class with

      public static string WithDefault (string input, string default)
    {
    return string.IsNullOrEmpty(input) ? default : input;
    }

    Build and add dll in the bin folder.

    Then add a line to xsltExteions.config. See:

    http://en.wikibooks.org/wiki/Umbraco/Create_xslt_exstension_like_umbraco.Library_in_C

  • Tony Kiernan 278 posts 341 karma points
    Feb 09, 2011 @ 15:59
    Tony Kiernan
    0

    In the for-each loop, I'm adding a variable which I'm then testing assigning a value if

    MY_VALUE = '' or MY_VALUE = NaN

    Then using an if before each block of content

    Is there really no way to do this check in the fore-each select?

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Feb 09, 2011 @ 22:58
    Chriztian Steinmeier
    0

    Hi Tony,

    I guess you could do something like this:

    <xsl:decimal-format name="Nullify" infinity="0" NaN="0" />
    
    <xsl:template match="/">
        <xsl:for-each select="$currentPage/descendant::*
            [@isDoc]
            [not(umbracoNaviHide = 1)]
            [umbraco.library:DateGreaterThanOrEqualToday(
                umbraco.library:DateAdd(pageDate, 'd', format-number(eventDuration, '0', 'Nullify'))
            )]">
            <!-- Do stuff -->
        </xsl:for-each>
    </xsl:template>

    /Chriztian

  • Tony Kiernan 278 posts 341 karma points
    Feb 10, 2011 @ 10:00
    Tony Kiernan
    0

    Nice.  I've now learnt something new.

    Although, I've abandoned that approach as something in the next step made it easier for me to go back and change how I was doing stuff

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies