Copied to clipboard

Flag this post as spam?

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


  • John C Scott 473 posts 1183 karma points
    May 13, 2013 @ 20:18
    John C Scott
    0

    count below an xpath

    thinking aloud here

    I have some nodes that look like this

    + catering 
    + + monday (mealDate = 01/06/2013)
    + + + lunch
    + + + dinner
    + + tueday (mealDate = 02/06/2013)
    + + + breakfast
    + + + lunch
    + + + dinner
    + + wednesday (mealDate = 03/06/2013)
    + + + breakfast
    + + + lunch

    where each "day" is a document type with the mealData property that uses the standard umbraco data picker

    and each meal beneath is a document type of "meal"

     

    i want to know the total number of meals that have happened until yesterday

    so if today was 2/6/13 the total would be 2

    and if today was 3/6/13 the total would be 5

    can't quite get my mind around how to write the xpath for this

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 13, 2013 @ 20:53
    Jan Skovgaard
    0

    Hi John

    What does your current code look like? And do you need to get the total of all meals or only the meals of each day?

    /Jan

  • John C Scott 473 posts 1183 karma points
    May 13, 2013 @ 21:05
    John C Scott
    0

    Currently this

          <xsl:value-of select="count($event/tegsCatering/tegsDay [dayDate='2013-04-02T00:00:00']/tegsMeal)"/>

    will give me the total number of meals under a specific date.

    So I am strruggling to think of a simple test for dayDate < today 

  • Dan 1288 posts 3921 karma points c-trib
    May 13, 2013 @ 21:11
    Dan
    101

    Hi John,

    You could use an umbraco XLST extension in your selector to compare dates:

    umbraco.library:DateDiff(date, $currentDate, 's') &lt; 0

    Where currentDate is something like this:

    <xsl:variable name="currentDate" select="umbraco.library:CurrentDate()"/>

    And date is your date property.

    Does this help?

  • John C Scott 473 posts 1183 karma points
    May 13, 2013 @ 21:18
    John C Scott
    0

    Perfect :)

    What I have working nicely as

    <xsl:value-of select="count($event/tegsCatering/tegsDay [umb:DateGreaterThanOrEqualToday(dayDate) = false]/tegsMeal)"/>

  • Dan 1288 posts 3921 karma points c-trib
    May 13, 2013 @ 21:25
    Dan
    0

    Happy days :)

    Checking that umb:DateGreaterThanOrEqualToday is false I think will include the meals today, so you may need to do some extra manipulation in there if you don't want todays meals included.  It's all in those extension methods though.

  • John C Scott 473 posts 1183 karma points
    May 13, 2013 @ 21:27
    John C Scott
    0

    I want up to yesterday, so I'm thinking if it excludes today and the future from the count that's what I want :)

  • Laurence Gillian 600 posts 1219 karma points
    May 14, 2013 @ 11:25
    Laurence Gillian
    0

    If you assume that your API creates the date folders in the correct order, you don't even need to sort by date.

    You just start at the date folder you want to go up to (e.g. current) and work around that.

    - - past (1)
    - - past (2)
    - - current = count(.\parent::*\child::day [position() &lt; current()\meal])
    - - future 

    That said doing it by date is probally more robust and easier to read in code.

    That XPATH isn't tested, it's just back of reciept nonsense

    /Lau

Please Sign in or register to post replies

Write your reply to:

Draft