Copied to clipboard

Flag this post as spam?

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


  • JC.dk 12 posts 20 karma points
    Mar 04, 2009 @ 11:25
    JC.dk
    0

    Sorting in groups of years.

    Hey guys, i am totally new to umbraco and XSL, but hope someone here can tell me how i go about this.

    I have many news items, that get liste after date, what i like is getting them group in years so the output looks like this

    ---------2009---------
    news items
    news items
    news items
    news items
    ---------2008---------
    news items
    news items
    --------2007-----------
    news items
    news items

    and os on.....

    am i doing this with "if" or "sort"? here is my simpel code so far:



    Hope someone can point me the right way :-)

  • Petr Snobelt 923 posts 1535 karma points
    Mar 04, 2009 @ 16:34
    Petr Snobelt
    0

    It sorts alphabetically,
    try look here http://www.xml.com/pub/a/2002/07/03/transform.html?page=2

    in short





    Petr

  • JC.dk 12 posts 20 karma points
    Mar 05, 2009 @ 14:02
    JC.dk
    0

    Great ty.. :-) i can use that code to get the year out.

    Now i just need to finde out how to put the "Year


    " before the year start of a new year..

    something like..

    [code]

    [/code]
    but how do i use variable and chance them in XSL

  • Petr Snobelt 923 posts 1535 karma points
    Mar 05, 2009 @ 18:02
    Petr Snobelt
    0

    You should use following-sibling axes

    something like (from head, not testted)

    test="substring(data [@alias = 'mydate'],7,4) != following-sibling::node/substring(data [@alias = 'mydate'],7,4)">


  • JC.dk 12 posts 20 karma points
    Mar 06, 2009 @ 12:17
    JC.dk
    0

    Thanks Petr

    I can see the idée behinde you answer, but the syntax dont work, i cant finde out to do it right, havde search for some hours now, and cant finde anything on whats wrong,

    when i put this line in, umbraco cant save:

    following-sibling::node/substring(data [@alias = 'mydate'],1,4)"

    i dont get any errors just "Xslt file could not be saved"

  • Petr Snobelt 923 posts 1535 karma points
    Mar 06, 2009 @ 13:25
    Petr Snobelt
    0

    Idea is simple check if next item has same year, if not write year

    of course, substring is in bad place try this
    <>
    test="substring(data [@alias = 'mydate'],7,4) != substring(following-sibling::node/data [@alias = 'mydate'],7,4)">

  • JC.dk 12 posts 20 karma points
    Mar 06, 2009 @ 14:06
    JC.dk
    0

    Thank you again Petr for takeing the time to help me :-)

    The syntax worked, but it look at bit funny the result, after doing some debuging i finde out that following-sibling dont care about my sort, it just look at the next node, is there any way to make it use my sort?

  • Petr Snobelt 923 posts 1535 karma points
    Mar 06, 2009 @ 15:34
    Petr Snobelt
    0

    Hi, I'm not sure about sort and xpath axes, so let's try something different - position()

    First add all nodes to variable

    change

  • JC.dk 12 posts 20 karma points
    Mar 09, 2009 @ 17:38
    JC.dk
    0

    After a long time trying to get code working, it looks the same as last time, i think it dont use my sort. :(

    Ty Petr. for all the help, even if we did not get threre o:)


    I think is really werid that this i something so hard to do in XSL, if i was just able to save a variable.......

  • Petr Snobelt 923 posts 1535 karma points
    Mar 10, 2009 @ 08:21
    Petr Snobelt
    0

    Hi, it should work, it test actual node with next node, it should be placed after processing actual node.

    But if you have problem working with xslt, you can use c#, where you can save variable
    http://www.umbraco.org/4634

    Petr

  • Petr Snobelt 923 posts 1535 karma points
    Mar 12, 2009 @ 08:33
    Petr Snobelt
    0

    Or take look at this post, there is a solution
    http://forum.umbraco.org/yafpostst8654XSLT-count-distinct-values.aspx?find=unread

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Mar 12, 2009 @ 10:33
    Casey Neehouse
    0

    Using the following-sibling method is a bit taxing on the process, but works fine for small datasets. If you are working with a larger site with a lot of nodes, consider looking into the muncheon (key) method.

    Case

  • Tommy Poulsen 514 posts 708 karma points
    Mar 12, 2009 @ 10:45
  • JC.dk 12 posts 20 karma points
    Mar 12, 2009 @ 13:36
    JC.dk
    0

    Thanks alot guys.. :d/

    the blackpoint.dk did the trick, just as i neede - it was really easy to use for a newbi like me...

    Take care

  • 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