Copied to clipboard

Flag this post as spam?

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


  • Craig Cronin 304 posts 503 karma points
    Apr 30, 2013 @ 23:16
    Craig Cronin
    0

    Data Grid XSLT Query

    I have a data grid that stores from - to date combinations.  I'm trying to bring this back into a variable so that i can work with the data


        <xsl:variable name="root" select="$currentPage/descendant::EventPage [@isDoc]" />    

      <xsl:variable name="events" select="$root [Exslt.ExsltDatesAndTimes:datetime(eventDates/items/item/fromDate) &lt; umbraco.library:CurrentDate()]" />

    Any help would be appreciated

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 01, 2013 @ 02:13
    Chriztian Steinmeier
    0

    Hi Craig,

    You should have a look at the DateGreaterThan extension - e.g.:

    <xsl:variable name="eventsRoot" select="$currentPage/descendant::EventPage[@isDoc]" />
    <xsl:variable name="today" select="umbraco.library:CurrentDate()" />
    
    <!-- (Only use events that have something in the fromDate field) -->
    <xsl:variable name="events" select="$eventsRoot//Event[normalize-space(eventDates/items/item/fromDate)]" />
    
    <xsl:variable name="eventsStartingBeforeToday" select="$events[umbraco.library:DateGreaterThan($today, eventDates/items/item/fromDate)]" />

    Alternatively, you can look for a matching extension in the uComponents Date extensions...

    /Chriztian

  • Craig Cronin 304 posts 503 karma points
    May 01, 2013 @ 13:38
    Craig Cronin
    0

    Hi Chriztian,


    Really appreciate, your feedback and help.  Will take a look at this later when i get home.  Also the date extensions option looks good.

    Thanks

  • Craig Cronin 304 posts 503 karma points
    May 03, 2013 @ 00:19
    Craig Cronin
    0

    Hi Chriztian,

    Sorry to bother you but I'm trying your code and it won't bring back results

    <xsl:variablename="events"select="$eventsRoot//Event[normalize-space(eventDates/items/item/fromDate)]"/>
    Should this be
    <xsl:variablename="events"select="$eventsRoot//EventPage[normalize-space(eventDates/items/item/fromDate)]"/>
    The only way i can get anything into copy-of is $eventsRoot/* ?
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 03, 2013 @ 00:27
    Chriztian Steinmeier
    0

    Hi Craig - no worries :-)

    I may just not have enough info about your setup - the way I'm guessing right now was this:

    Content
    - Somepage
    - EventsPage
      - Event
      - Event

    But the naming may just have me fooled - if all your event pages are of the EvenPage document type, then you should do this:

    <xsl:variable name="events" select="$currentPage//EventPage" />
    <xsl:variable name="today" select="umbraco.library:CurrentDate()" />
    
    <!-- (Only use events that have something in the fromDate field) -->
    <xsl:variable name="validevents" select="$events[normalize-space(eventDates/items/item/fromDate)]" />
    
    <xsl:variable name="eventsStartingBeforeToday" select="$validevents[umbraco.library:DateGreaterThan($today, eventDates/items/item/fromDate)]" />

    If that's not the case - could you maybe paste some of the copy-of output, so we can grok your structure?

    /Chriztian

  • Craig Cronin 304 posts 503 karma points
    May 03, 2013 @ 00:33
    Craig Cronin
    0

    Perfect and fantastic response :)

    Sorry just inquisitive, still really getting to grips with XSLT, but you have $currentPage//EventPage, why the double "/" ?

    This works though

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 03, 2013 @ 00:39
    Chriztian Steinmeier
    1

    The double slash is just shorthand for the descendant:: axis - If your EventPage documents are all children of $currentPage, you should of course use a single slash instead. The double slash is very inefficient because the processor searches *every* level below for matches.

    /Chriztian

  • Craig Cronin 304 posts 503 karma points
    May 03, 2013 @ 02:05
    Craig Cronin
    0

    Just for completion, i've got it at 1:00am in morning.

    <xsl:template match="/">

        <!-- (Only use events that have something in the fromDate field) -->
        <xsl:variable name="events" select="$currentPage//EventPage [normalize-space(eventDates/items/item/fromDate)]" />
        <xsl:variable name="fromDate" select="umbraco.library:CurrentDate()" />
        <xsl:variable name="toDate" select="GetDays:GetToDate()" />
      
        <xsl:variable name="validEvents" select="$events [(umbraco.library:DateGreaterThanOrEqual($fromDate, eventDates/items/item/fromDate) and umbraco.library:DateGreaterThanOrEqual(eventDates/items/item/toDate, $fromDate)) or
                                         (umbraco.library:DateGreaterThanOrEqual($toDate, eventDates/items/item/fromDate) and umbraco.library:DateGreaterThanOrEqual(eventDates/items/item/toDate, $toDate)) or
                                         (umbraco.library:DateGreaterThanOrEqual(eventDates/items/item/fromDate, $fromDate) and umbraco.library:DateGreaterThanOrEqual($toDate, eventDates/items/item/toDate)) or
                                         (umbraco.library:DateGreaterThanOrEqual($fromDate, eventDates/items/item/fromDate) and umbraco.library:DateGreaterThanOrEqual(eventDates/items/item/toDate, $toDate))]" />
      
        <xsl:copy-of select="$validEvents" />
      
    </xsl:template>

    <msxml:script language="C#" implements-prefix="GetDays">
        <msxml:using namespace="system" />
        public static DateTime GetToDate()
        {
            var date = DateTime.Parse(DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month).ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Year.ToString() + " 23:59:59");
            return date;
        }
    </msxml:script>

Please Sign in or register to post replies

Write your reply to:

Draft