Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 712 posts 1189 karma points
    Sep 14, 2012 @ 01:18
    Bo Damgaard Mortensen
    0

    Sorting by time (hours:minutes)

    Hi all,

    I'm running my head against the wall on this one. I have a collection of nodes which has two dropdowns for selecting a time: hour and minute. When rendering my nodes, I need to sort them based on this selection. Thing is, that the hours can start with a leading zero, i.e.: 02:15, 04:05 etc.

    I've tried the following:

    <xsl:for-each select="$artists">
            <xsl:sort select="substring(Hours,1,2)" order="descending" data-type="number" /> 
            <xsl:sort select="substring(Minutes,1,2)" order="descending" data-type="number" />
    </xsl:for-each>

    Which outputs my selection like this:

    22:15
    05:30
    02:15

    Is there any way to achieve this in XSLT, or do I have to clean my hands and write an extension to do it? ;-)

    Any hint on this is greatly appreciated!

    Thanks in advance.

    - Bo

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Sep 14, 2012 @ 01:30
    Chriztian Steinmeier
    0

    Hi Bo,

    Sort them as text like this:

    xsl:sort select="concat(Hours, Minutes)"

    (Posting from mobile, taking no chances with code :-)

    /Chriztian

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    Sep 14, 2012 @ 01:38
    Bo Damgaard Mortensen
    0

    Hi Chriztian,

    Thanks for your input and fast reply :-)

    I've tried to sort it like you wrote, but it gives me this output:

    02:15
    05:30
    22:15 

    and with order="descending" it gives me this:

    22:15
    05:30
    02:15 

    I think it's fairly logic that it sorts it like this, but it's the leading zero that causes the trouble. At least to my understanding :-)

    Thanks again!

    - Bo

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Sep 14, 2012 @ 01:44
    Chriztian Steinmeier
    0

    Ok, I don't think I understand what you want as output then?

    Are they not sorted correct? (Assuming all times are on same date)

    /Chriztian

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    Sep 14, 2012 @ 01:54
    Bo Damgaard Mortensen
    0

    Oh hell.. I think it's getting late ;-)

    Of course, it sorts it the way it should. It's just that the time is loosely coupled (in fact, not coupled at all) to a certain date (it's a festival site), so the admin is basically able to pick whatever time he wants on a "day". I'll have to give them the ability to drag 'n drop-sorting on my datatype then :-) Seems to be the only way to get around this.

    The "problem" is, that a day on a festival isn't nessecary from 00.00 to 00.00 as an artist can perform on "Wedensday 01.30" thus no particular date involved here.

    It's quite ambigous :-D and the only real way to sort them is on the datatype.

    Thanks again!

    - Bo

     

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Sep 14, 2012 @ 08:04
    Chriztian Steinmeier
    0

    Oh - I was wondering whether it was something like that :-)

    Well, wouldn't you be able to automatically "assign" all times from, say, 00:00 to 07:59 or so (actually — musicians don't even wake up before noon, anyway, right? :-), to "belong" to the following date, sorting-wise, thus making them sort correct?

    I'm just thinking it's a pain to implement drag 'n drop sorting for something that an editor would almost expect to sort by itself...

    As long as there's a clear description for the editor, I'd say that could work... e.g. something like "Days go from 08:00 to 05:00 the following night".

    Anyways, was just thinking out loud :-) 

    /Chriztian

     

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    Sep 14, 2012 @ 10:30
    Bo Damgaard Mortensen
    0

    Hi Chriztian,

    I hear what you're saying about assigning all times to a date (and yes, musicians are lazy chaps! ;-)) Thing is, they want it to be as "open", flexible and loosely coupled as possible when making the program. Got a screenshot for you of my structure and datatype (don't mind the design of it though, it's not done yet :-D):

    Having it like this, they are completely free to make the program, like they want, without limitations. Sorting it, however, is quite a challenge :-) But I think you are right, they would expect it to be auto-sorted when output on the page, so I have to figure out a way to do that.

    If anyone got an idea of how to sort this, please let me know ;-)

    Thanks again!

    - Bo

  • 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