Copied to clipboard

Flag this post as spam?

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


  • Barry Fogarty 493 posts 1129 karma points
    Dec 18, 2012 @ 11:56
    Barry Fogarty
    0

    XPath reverse list order

    Hoping this is some easy karma for someone (@LeeKelleher??)

    I am trying to make an XPath checkbox list datatype that contains all nodes of type 'Person' - but in reverse oder.  (equally I could order by create date but don't think that is doable in XPath?)

    I have tried variations of 

    reverse(//Person) 

    but I am getting a syntax error - is that because the reverse function is only in XPath 2.0?

    Suggestions and workarounds most welcome, thanks

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 18, 2012 @ 12:01
    Chriztian Steinmeier
    0

    Hi Barry,

    Yeah, you can't do that in a single XPath (1.0) expression - that is something they'd need to add as a special "sort" feature or similar.

    /Chriztian

  • Barry Fogarty 493 posts 1129 karma points
    Dec 18, 2012 @ 12:19
    Barry Fogarty
    0

    Thanks Chriztian, thought that might be the case.

    As a workaround is there a way to compare a date property in the Person nodes to the current date?  So I could restrict the list based on a time period?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 18, 2012 @ 12:33
    Chriztian Steinmeier
    0

    Hi Barry,

    You could do that with a little hack - suppose you have a node somewhere with a currentDate property on it, that you knew would be kind of updated regularly.

    Then you could say:

    $currentPage//Person[translate(dateProperty, '-:T+', '') > translate(/root/somenodepath/currentDate, '-:T+', '')]

    Replace $currentPage with what's the optimal for your context, and likewise with /root/somenodepath/currentDate :-)

    (The trick involves converting the date strings to effectively numbers by stripping all non-digits, since you can't compare dates or strings in any meaningful way in XSLT 1.0)

    /Chriztian

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Dec 18, 2012 @ 13:06
    Lee Kelleher
    0

    Hi Barry,

    As far as I'm aware you can't sort the node-set within the XPath expression itself, (although Chriztian's suggestion looks very interesting!)

    Is this just for the XPath CheckBoxList data-type? It would be possible to change the sort order of the node-set after the XPath has done it's "thing".

    We could add an option in the settings, e.g. "Reverse sort order?"  But then that would only be sorted on the node's Id or Name, (not a custom property).

    If you think we should add it in, open a ticket on the issue tracker - we'll schedule it in: http://issues.umbraco.org/issues#newissue=yes

    Cheers, Lee.

  • Barry Fogarty 493 posts 1129 karma points
    Dec 18, 2012 @ 13:19
    Barry Fogarty
    0

    Hi Lee,  thanks for chipping in - Chriztian's workaround has worked for me in this instance so that is fine.  Not sure about adding extra options to the XPath CheckBoxList data-type, it would be handy to control the order of items but might also make it a bit more confusing generally.

    What would be cool though, when the concept of Container Document Types sees the light of day:

    http://our.umbraco.org/contribute/releases/4100/rfc/33203-Container-Document-Types

    To integrate a new (picker) data type with this somehow so the list of items can reflect the settings of its container.  Or another option, if there was a way to change the default order of child nodes from a parent (e.g. most recent first) - that the XPath CheckBoxList data-type would respect that order (I guess it would anyway)?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 18, 2012 @ 13:22
    Chriztian Steinmeier
    0

    @Lee: I could see some pretty cool scenarios if you could just enter an XPath to sort by, e.g. @createDate or count(*[@isDoc]) and then be able to tick DESC as the sort order...

    (pondering ...)

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft