Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Nov 11, 2015 @ 21:50
    Steve
    0

    XSLT Sort by publicationDate with Time

    I am sorting news article documents, by publicationDate, but I would like them to also be sorted by the time within the publicationDate, so the most recently published articles, that are published on the same date, would be at the top of the list. Here is what I have currently, what additions, could make this work?

    <xsl:for-each select="$currentPage/descendant::NewsArticle[string(@id) != string($currentPage/featuredArticle) and string(umbracoNaviHide) != '1' and string(featureThisArticle) = '1' ]">
      <xsl:sort select="publicationDate" data-type="text" order="descending" />
    <!--    <xsl:sort select="publicationDate" order="descending" /> -->
      <xsl:if test="position() &lt; 8">
        <xsl:copy-of select="." />
      </xsl:if>
    </xsl:for-each>
    
  • Chriztian Steinmeier 2732 posts 8341 karma points MVP 5x admin c-trib
    Nov 11, 2015 @ 22:08
    Chriztian Steinmeier
    0

    Hi Steve,

    The <xsl:sort> you've specified should do that automatically — that is, if the publicationDate property is a standard DatePicker (or DatePicker with Time).

    Could you maybe show an example of five or six article's dates and how you'd like them to output?

    /Chriztian

  • Sebastian Dammark 552 posts 1292 karma points
    Nov 11, 2015 @ 22:12
    Sebastian Dammark
    0

    I would probably use a grouping method like Muenchian Grouping.

    http://www.jenitennison.com/xslt/grouping/muenchian.html

    And then group by day, sort by time.

  • Steve 472 posts 1216 karma points
    Nov 12, 2015 @ 13:37
    Steve
    0

    Chriztian,

    It is a standard DatePicker. Does it have to be DatePicker with Time to sort articles published on the same date in the order they were most recently published?

    If so, will changing this in the docType cause issues for all the previously published articles. We have around 900.

  • Steve 472 posts 1216 karma points
    Jan 06, 2016 @ 13:55
    Steve
    0

    I switched the data type on the "PublicationDate" property for my news articles from a DatePicker to DatePicker with Time and tried changing some of the publicationDates to be the same day with different times, but changing the time doesn't alter the position in the sort. Do I need to change something in my xslt to check for time as well?

  • Chriztian Steinmeier 2732 posts 8341 karma points MVP 5x admin c-trib
    Jan 06, 2016 @ 14:03
    Chriztian Steinmeier
    100

    Hi Steve,

    You really shouldn't have to change it, no...

    If you output the publicationDate - are they not sorted correctly?

    For example, try this:

    <xsl:for-each select="$currentPage//NewsArticle[featureThisArticle = 1][not(@id = $currentPage/featuredArticle) and not(umbracoNaviHide = 1)]">
        <xsl:sort select="publicationDate" data-type="text" order="descending" />
        <xsl:if test="position() &lt;= 20">
            <p><xsl:value-of select="concat(@nodeName, ': ', publicationDate)" /></p>
        </xsl:if>
    </xsl:for-each>
    

    /Chriztian

  • Steve 472 posts 1216 karma points
    Jan 06, 2016 @ 14:48
    Steve
    0

    Thanks Chriztian!

    Just changing the data type to "Date Picker with Time" within the DocType for the news articles and it worked. Of course, I had to assign a time to the news articles created previously to get them to sort by time of day, but it works non the less. I appreciate you help!

Please Sign in or register to post replies

Write your reply to:

Draft