Copied to clipboard

Flag this post as spam?

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


  • fed 199 posts 70 karma points
    May 01, 2009 @ 16:58
    fed
    0

    XSLT Group / Order / Count

    I don't even know if this is possible, but I feel stuck, so any ideas or solutions are appreciated.

    I have a property called 'MemberId' on some of my pages.

    I now want to create a list over the MemberId's who have the most pages tagged with their ID, but I don't know where to start :) This is probably not doable with xslt.

    The goal of the list is to look something like this.
    [memberId] - [numberofpages]

    This is all I have got so far :)
    [code]

    [/code]

    This gives me a list sorted by MemberId, but somehow I want to group them and count the occurrences.

    Any ideas are appreciated.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    May 01, 2009 @ 20:50
    Dirk De Grave
    0

    Hi fed,

    Iterate the sorted list, don't process if current member'id is equal to last record's member id and for each member id in the list that you do process, create some juicy xpath expression to get the number of occurences.

    I'm sure this will work, not sure if this is the most elegant solution... but what is elegant in terms of xslt?

    Cheers,
    /Dirk


  • Tommy Poulsen 514 posts 708 karma points
    May 01, 2009 @ 21:05
    Tommy Poulsen
    0

    Hi fed, I tend to use id's and key's for this kind of grouping etc.
    It's a bit weird getting the grips of in the beginning, but once you get it it's extremely powerful - and normally outperformances other iterative solutions.

    In your case it would be something like this:

    [code]



    ()






    [/code]

    Hope this helped

    Tommy

    - see more on http://blackpoint.dk/umbraco-workbench.aspx?Snippet=/umbraco-workbench/xslt/grouping--distinct-values.aspx

  • fed 199 posts 70 karma points
    May 01, 2009 @ 22:26
    fed
    0

    Thanks a lot, worked like a charm.. Haven't gotten my head around how it works yet :) but atleast it works!

    Thanks..

  • Tommy Poulsen 514 posts 708 karma points
    May 01, 2009 @ 22:48
    Tommy Poulsen
    0

    Basically it is:

    * Define some special key/function used for grouping the nodes - in your case it's simply using the MemberId, but it could be more advanced. It's a bit similar to a hash-function. All nodes with the same key value defines a group.

    * Find the first node of every group. This is done by comparing unique node-id's (fetched by generate-id() with the first node-id of the group). This is the outer for-each

    * Iterate over all nodes in a group using the key() function for fetching all nodes with a specific value. The Key() function returns a node-set.

    Tommy


  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    May 02, 2009 @ 08:19
    Dirk De Grave
    0

    @tommyp: Great piece of xslt art! I have to bookmark this!

    Cheers,
    /Dirk

  • Tommy Poulsen 514 posts 708 karma points
    May 03, 2009 @ 21:40
    Tommy Poulsen
    0

    [quote=Dirk]@tommyp: Great piece of xslt art! I have to bookmark this!

    Cheers,
    /Dirk

    [/quote]

    Thanks Dirk, glad you liked it

    You can find the original on my blackpoint.dk site.

    Tommy

Please Sign in or register to post replies

Write your reply to:

Draft