Copied to clipboard

Flag this post as spam?

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


  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Aug 18, 2010 @ 18:15
    Tim
    0

    Using Preceding in XSLT For Group By

    Hi,

    I'm using a simple preceding statement to get a unique list of category names from a list of pages, however its not working as I'd expect. I have some data with an alias of 'productGroup' assigned to some nodes. When I do the preceding check to do the group by, it appears to be picking up ALL pages in the entire section, not just the ones under the current page for some reason.

    So if I have:

    $currentPage/node/data [@alias = 'productGroup'] [not(.=preceding::node/data [@alias = 'productGroup'])]

    It checks not only the preceding nodes underneath the current page, but the other nodes in other sections as well. Does anyone have any ideas why its doing this?

  • Lee 1130 posts 3088 karma points
    Aug 18, 2010 @ 18:22
    Lee
    0

    I didn't even know you could do that! Learn something new everyday (Or in the case of XSLT every hour!)

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 18, 2010 @ 19:52
    Morten Bock
    0

    How about this:

    $currentPage/node/data [@alias = 'productGroup'][not(.=preceding::node[../@id = $currentPage/@id]/data [@alias = 'productGroup'])]
  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Aug 18, 2010 @ 22:03
    Tim
    0

    Thanks Morten, that did the trick!

    :)

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 18, 2010 @ 22:09
    Chriztian Steinmeier
    1

    Hi Tim,

    You should have a look at the difference between the preceding:: axis and the preceding-sibling:: axis - they yield very different results, and it seems you're using the first, when you actually mean to use the latter.

    So probably:

    $currentPage/node[data[@alias = 'productGroup']][not(. = preceding-sibling::node[data[@alias = 'productGroup']])]

    /Chriztian 

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 19, 2010 @ 08:20
    Morten Bock
    0

    Doh, why didn't I think of that?

Please Sign in or register to post replies

Write your reply to:

Draft