Copied to clipboard

Flag this post as spam?

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


  • Michael 22 posts 61 karma points
    Apr 16, 2015 @ 13:17
    Michael
    0

    Compare datetime in XSLT

    In my backend, I have a document type with a datetime field named "lecture time".

    then I use it in the XSLT like the follwoing picutre. but it said "String was not recognized as a valid DateTime".

    I think it is a datetime type and can be compared with anther datetime value.  Had someone encountered it? Should I convert the lecturetime to Datetime type? How can I fix it? Thank you in advanced.

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 16, 2015 @ 13:24
    Jan Skovgaard
    1

    Hi Michael

    Since you're looping over a bunch of values you probably need to ensure that you only do the date-check if the date in fact has been selected. I suspect there is at least one empty value, which is why you get this error.

    I assume that the "lectureTime" is setup to be of a datatype "Datepicker", right?

    /Jan

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 16, 2015 @ 22:41
    Chriztian Steinmeier
    1

    Hi Michael,

    Jan is right - this error is 99.999% certain to be caused by an empty value in the lectureTime property (or a bogus value if the property isn't set up as a DatePicker).

    You can safeguard by adding a predicate to the nodeselection, using the normalize-space() function to make sure the lectureTime has a value (and assuming it's a DatePicker it will be a valid one):

    <xsl:template match="/">
        <xsl:for-each select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)][normalize-space(lectureTime)]">
            <xsl:sort select="lectureTime" />
            <xsl:variable name="lecType" select="lectureType" />
            <xsl:if test="umbraco.library:DateGreaterThanOrEqualToday(lectureTime)">
                <!-- Do something -->
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    

    /Chriztian

  • Michael 22 posts 61 karma points
    Apr 17, 2015 @ 04:34
    Michael
    0

    Thank you very much! Jan and Chriztian!

    Thank you for taking out your time to anwser my question.

    It's very kind of you. I'm very gald I can fix my problem.

    I have checked the "lecture time" value of all of nodes, The values are all not empty.

    I use the normalize-space() function Chriztian suggested, that's so brilliant. It's working. ;)

    I think the form of lection time is not recognized by system. right?

    Anyway, Thank you very much again, I very like this place where I can feel warm!

Please Sign in or register to post replies

Write your reply to:

Draft