Copied to clipboard

Flag this post as spam?

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


  • Christian Kragh 14 posts 34 karma points
    Sep 26, 2010 @ 21:55
    Christian Kragh
    0

    Sort rss feed problem

    Hey.

    I have a problem with my sorting of my RSS feed.

    I used this and it showing the news sort by create date and not by the field called 'eventDate'.

    Can anyone help me?

    Best regads

    Christian

     

    Here is my XSLT:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:rssdatehelper="urn:rssdatehelper"
      xmlns:dc="http://purl.org/dc/elements/1.1/"
      xmlns:content="http://purl.org/rss/1.0/modules/content/"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

      <xsl:output method="xml" omit-xml-declaration="yes"/>

      <xsl:param name="currentPage"/>

      <xsl:variable name="RSSNoItems" select="string('10')"/>
      <xsl:variable name="RSSTitle" select="string('UGB.dk nyheder')"/>
      <xsl:variable name="SiteURL" select="string('http://www.ugb.dk')"/>
      <xsl:variable name="RSSDescription" select="string('Nyheder fra UGB.dk')"/>
      <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::root" />
      <xsl:variable name="homeNode" select="$rootNode/Forside [@isDoc]" />

      <xsl:variable name="pubDate">
        <xsl:for-each select="$homeNode//Nyheder/* [@isDoc and umbraco.library:HasAccess(@id, @path)]">
          <xsl:sort select="@createDate" data-type="text" order="descending" />
          <xsl:if test="position() = 1">
            <xsl:value-of select="updateDate" />
          </xsl:if>
        </xsl:for-each>
      </xsl:variable>
    <xsl:template match="/"><xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/><xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</xsl:text>
    <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/">

          <channel>
            <title>
              <xsl:value-of select="$RSSTitle"/>
            </title>
            <link>
              <xsl:value-of select="$SiteURL"/>
            </link>
            <pubDate>
              <xsl:value-of select="$pubDate"/>
            </pubDate>
            <generator>umbraco</generator>
            <description>
              <xsl:value-of select="$RSSDescription"/>
            </description>
            <language>da</language>
            <xsl:apply-templates select="$homeNode//Nyheder/* [@isDoc and umbraco.library:HasAccess(@id, @path)]">
              <xsl:sort select="substring(umbraco.library:FormatDateTime(current()/eventDate, 'dd.MM.yy'),7,4)" order='descending'/>
              <xsl:sort select="substring(umbraco.library:FormatDateTime(current()/eventDate, 'dd.MM.yy'),4,2)" order='descending'/>
              <xsl:sort select="substring(umbraco.library:FormatDateTime(current()/eventDate, 'dd.MM.yy'),1,2)" order='descending'/>
              <xsl:sort select="@createDate" order='descending'/>
            </xsl:apply-templates>


          </channel>
        </rss>
      </xsl:template>
      <xsl:template match="*[@isDoc]">
        <xsl:if test="position() &lt;= $RSSNoItems">
          <item>
            <title><xsl:value-of select="@nodeName"/></title>
            <link><xsl:value-of select="$SiteURL"/> <xsl:value-of select="umbraco.library:NiceUrl(@id)"/></link>
            <pubDate><xsl:value-of select="umbraco.library:FormatDateTime(@createDate,'r')" /></pubDate>
            <guid><xsl:value-of select="$SiteURL"/> <xsl:value-of select="umbraco.library:NiceUrl(@id)"/></guid>
            <content:encoded><xsl:value-of select="concat('&lt;![CDATA[ ', current()/bodyText,']]&gt;')" disable-output-escaping="yes"/></content:encoded>
          </item>
        </xsl:if>
      </xsl:template>
    </xsl:stylesheet>

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 27, 2010 @ 08:14
    Sebastiaan Janssen
    0

    This looks pretty obvious: the sorts on date don't actually work, try outputting that formatDate you're doing and looking at the results. I would suggest you do just 1 formatDate to format it as yyyyMMdd so that you can actually sort them (you could include the time as well if you have multiple items per day).

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Sep 27, 2010 @ 09:56
    Chriztian Steinmeier
    0

    Hi Christian,

    Is the eventDate format the standard XMLDate format (as in @createDate, @updateDate etc.)?

    - Then you can just sort on that directly:

    <xsl:sort select="eventDate" data-type="text" order="descending" />

    /Chriztian

  • Christian Kragh 14 posts 34 karma points
    Sep 27, 2010 @ 12:10
    Christian Kragh
    0

    Great.

    It works with eventDate insted of current()/eventDate

    Christian

    p.s. I can't give you karma since my karma is under 70.

Please Sign in or register to post replies

Write your reply to:

Draft