Copied to clipboard

Flag this post as spam?

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


  • prl 32 posts 54 karma points
    May 03, 2010 @ 13:04
    prl
    0

    RSS Feeds

     

    Hello,

    I'm creating an RSS feed for my Umbraco site but I'm having a problem here. I have several Doc Types, but Iwant only 3 of them to show up in the RSS Feeds, all the rest should be ignored. How can I achieve that? Here's the code I have right now:

    <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" xmlns:Designit.VideoEmbed="urn:Designit.VideoEmbed" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Designit.VideoEmbed ">
    
      <xsl:output method="xml" omit-xml-declaration="yes"/>
    
      <xsl:param name="currentPage"/>
    
      <!-- Update these variables to modify the feed -->
    
      <xsl:variable name="RSSNoItems" select="string('50')"/>
      <xsl:variable name="RSSTitle" select="RSSTitle"/>
      <xsl:variable name="SiteURL" select="SiteURL"/>
      <xsl:variable name="RSSDescription" select="RSSDescription"/>
    
      <xsl:variable name="rootTextpageNode" select="$currentPage/ancestor-or-self::node [@level = 1 and @nodeTypeAlias = 'Homepage']" />
    
      <!-- This gets all news and events and orders by updateDate to use for the pubDate in RSS feed -->
      <xsl:variable name="pubDate">
        <xsl:for-each select="$rootTextpageNode//node">
          <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="/">
    
        <!-- change the mimetype for the current page to xml -->
        <!-- <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/> -->
        <xsl:value-of select="umbraco.library:ChangeContentType('application/rss+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>en</language>
    
            <xsl:apply-templates select="$rootTextpageNode//node [string(data [@alias='umbracoNaviHide']) != '1']">
              <xsl:sort select="@createDate" order="descending" />
            </xsl:apply-templates>
          </channel>
        </rss>
    
      </xsl:template>
    
      <xsl:template match="node">
        <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[ ', ./data [@alias='Title'],']]&gt;')" disable-output-escaping="yes"/>
          <xsl:value-of select="concat('&lt;![CDATA[ ', ./data [@alias='Text'],']]&gt;')" disable-output-escaping="yes"/>
            </content:encoded>
          </item>
        </xsl:if>
      </xsl:template>
    
    </xsl:stylesheet>

     

    Thanks in advance.

     

  • Tobias Neugebauer 52 posts 93 karma points
    May 03, 2010 @ 13:15
    Tobias Neugebauer
    1

    Hi,

    try filtering your DocTypes before applying the template like this:

    <xsl:apply-templates select="$rootTextpageNode//node [string(data [@alias='umbracoNaviHide']) != '1' and (@nodeTypeAlias='YOURDOCTYPE1' or @nodeTypeAlias='YOURDOCTYPE2' or @nodeTypeAlias='YOURDOCTYPE3') ]">

    think this should work for you

    Toby

  • prl 32 posts 54 karma points
    May 04, 2010 @ 19:02
    prl
    0

    I've got another question.. 

    I moved my project to a staging environment and my RSS Feeds stopped working. The generated XML is different for the same XSLT. Here's what I get when I view the source of the feed:

    Local:

    <?xml version="1.0" encoding="utf-8"?>
    <rss version="2.0" 
         xmlns:atom="http://www.w3.org/2005/Atom" 
         xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" 
         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/" 
         xmlns:rssdatehelper="urn:rssdatehelper">
      <channel xmlns:cfi="http://www.microsoft.com/schemas/rss/core/2005/internal" cfi:lastdownloaderror="None">
        <title cf:type="text">TITLE</title>
        <link>http://localhost:50222/</link>;
        <generator>umbraco</generator>
        <description cf:type="text">DESCRIPTION</description>
        <language>en</language>
        <item>
          <title xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" cf:type="text">ArticleTitle</title>
          <link>http://localhost:50222/ArticleLink.aspx</link>;
          <pubDate>Wed, 14 Apr 2010 18:15:41 GMT</pubDate>
          <atom:published xmlns:atom="http://www.w3.org/2005/Atom">2010-04-14T18:15:41Z</atom:published>
          <atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-04-14T18:15:41Z</atom:updated>
          <guid>http://localhost:50222/ArticleLink.aspx</guid>;
          <description xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" cf:type="html">
            &lt;p&gt;TESTTESTTEST&lt;/p&gt;
          </description>
          <cfi:id>9</cfi:id>
          <cfi:effectiveId>3447083198</cfi:effectiveId>
          <cfi:read>true</cfi:read>
          <cfi:downloadurl>http://localhost:50222/rss.aspx</cfi:downloadurl>;
          <cfi:lastdownloadtime>2010-05-04T16:15:51.185Z</cfi:lastdownloadtime>
        </item>
        (...)
      </channel>
    </rss>

     

    Stage:

    <?xml version="1.0" encoding="UTF-8"?>
    <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/" 
         xmlns:rssdatehelper="urn:rssdatehelper">
      <channel>
        <title>TITLE</title>
        <link> LINK</link>
        <pubDate></pubDate>
        <generator>umbraco</generator>
        <description>DESCRIPTION</description>
        <language>en</language>
        <item>
          <title>ArticleTitle</title>
          <link> ArticleLink</link>
          <pubDate>Wed, 28 Apr 2010 12:27:53 GMT</pubDate>
          <guid> ArticleLink</guid>
          <content:encoded>
            <![CDATA[ 
    <p>TESTTESTTEST</p>
    ]]>
          </content:encoded>
        </item>
        (...)
      </channel>
    </rss>

     

    What's my problem here? Can't figure this one out..

    Thanks.

  • prl 32 posts 54 karma points
    May 04, 2010 @ 19:11
    prl
    0

    Correction: the feeds didn't stop working, but they aren't well formed. The content's there.

  • 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