Copied to clipboard

Flag this post as spam?

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


  • jonney.corner 13 posts 33 karma points
    May 16, 2013 @ 11:00
    jonney.corner
    0

    Creating an RSS feed

    Hello all, 

    I am wondering if someone can help me create an RSS feed for my website on Umbraco. I want the admin to be able to select which news they would like to go to the rss feed so our users can see these.

    I have not long started on Umbraco, so hence why i am looking for a bit of help step by step.

    I have created a Macro for the RSS feed. Looking to see if someone can provide a step by step guide on how to create one from scratch even if its an auto updating Feed 

     

    Thanks all

  • jonney.corner 13 posts 33 karma points
    May 16, 2013 @ 11:53
    jonney.corner
    0

    bump

  • jonney.corner 13 posts 33 karma points
    May 17, 2013 @ 14:58
    jonney.corner
    0

    Anyone please help? Thanks

  • Thomas Brinegar 84 posts 162 karma points
    May 17, 2013 @ 15:09
    Thomas Brinegar
    0

    Hi Jonney,

    I would start by creating an RSS DocType and and matching template.  The template should then call an XSLT macro that iterates through the entire content tree and output values within RSS formatted markup.

    Here is a sample RSS feed:

    http://static.userland.com/gems/backend/sampleRss.xml

    1. Calling a Macro from template:
    2. When writing the XSLT, you will mostly need to usestatements within anthat iterates on all pages.  A good template to pull this from is Umbraco's pre-packaged sitemap XSLT.
  • Thomas Brinegar 84 posts 162 karma points
    May 17, 2013 @ 15:28
    Thomas Brinegar
    0
    Here is something that I marked up real quick mimicking that same RSS link.  The pages will need to have a content data field attached to their docType to output the description in the RSS.  You may also want to consider wrapping a substring function to limit the number of characters output, otherwise you are going to get the entire content in the feed.  There are also ways to strip tags so fragments of markup are not output.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    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="maxLevelForSitemap" select="4"/>
    <xsl:template match="/">
    <xsl:text disable-output-escaping="yes"><![CDATA[<?xml version="1.0" encoding="ISO-8859-1" ?>]]></xsl:text>
    <rss version="0.91">
    <channel>
    <title>WriteTheWeb</title> 
    <link>http://writetheweb.com</link> ;
    <description>News for web users that write back</description> 
    <language>en-us</language> 
    <copyright>Copyright 2000, WriteTheWeb team.</copyright> 
    <managingEditor>[email protected]</managingEditor> 
    <webMaster>[email protected]</webMaster> 
    <image>
    <title>WriteTheWeb</title> 
    <url>http://writetheweb.com/images/mynetscape88.gif</url> ;
    <link>http://writetheweb.com</link> ;
    <width>88</width> 
    <height>31</height> 
    <description>News for web users that write back</description> 
    </image>
    <xsl:call-template name="drawNodes"> 
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>  
    </xsl:call-template>
    </channel>
    </rss>
    </xsl:template>

    <xsl:template name="drawNodes">
    <xsl:param name="parent"/> 
    <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]"> 
    <item>
    <title><xsl:value-of select="@nodeName" /></title>
    <link><xsl:value-of select="umbraco.library:NiceUrl(@id)" /></link>
    <description><xsl:value-of select="content" /></description>
    <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">   
    <xsl:call-template name="drawNodes">    
    <xsl:with-param name="parent" select="."/>    
    </xsl:call-template>  
    </xsl:if> 
    </item>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
  • jonney.corner 13 posts 33 karma points
    May 17, 2013 @ 15:41
    jonney.corner
    0

    Thats great thank you Tom!

    i am just having a problem now with the for each variable shown below, the function will not pass through this line of code

        <xsl:variable name="pubDate">
            <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1']">
                <xsl:sort select="@createDate" data-type="text" order="descending" />
                <xsl:if test="position() = 1">
                    <xsl:value-of select="@createDate" />
                </xsl:if>
            </xsl:for-each>
        </xsl:variable>

     

    have a feeling it something down to linking the items to the rss, because when i enter new data into a new page, it will not display on the rss

     

    Thanks.

  • Thomas Brinegar 84 posts 162 karma points
    May 17, 2013 @ 16:17
    Thomas Brinegar
    0

    I would check that the pages you are entering the data are published.  Also, did you setup an RSS DocType, Template, and create the page somewhere in the content tree?  If none of these are the case, it may be that your for-each is not properly retrieving the node region you are targeting.

  • jonney.corner 13 posts 33 karma points
    May 17, 2013 @ 16:23
    jonney.corner
    0

    They are all correct, DocTypes and everything are there and have been created.

    I think there is a problem with the node region, what would the target be to retrieve data from my news area? the structure of this on the content menu is:

    Home
    News
    News Item 1

     

    Everything under News is the newly added content. News Item 1, " " 2 etc.

    Thanks. 

  • Thomas Brinegar 84 posts 162 karma points
    May 17, 2013 @ 16:28
    Thomas Brinegar
    0

    If all your news assets are located within the parent News node,

    I would use:

    <xsl:for-eachselect="umbraco.library:GetXmlNodeById(1067)/*[@isDoc]">

    Where 1067 is the ID of the parent news page asset.  The /* should target all child nodes like a wildcard.

  • Thomas Brinegar 84 posts 162 karma points
    May 17, 2013 @ 17:11
    Thomas Brinegar
    0

    As an edit to what I coded up earlier, I found that placing the XML doctype on the page actually gets output to line 2 which throws an error in the browser.  I had to replace the line:

    <xsl:textdisable-output-escaping="yes"><![CDATA[<?xml version="1.0" encoding="ISO-8859-1"?>]]></xsl:text>

    With:

    <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>
  • jonney.corner 13 posts 33 karma points
    May 20, 2013 @ 11:06
    jonney.corner
    0

    I have tried searching for the content line on my code but i dont appear to have it. :/

    I have attached my XML code i got my my RSS feed below, i had this code from the sample folder on Umbraco.

    <?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"/>

      <!-- Update these variables to modify the feed -->
      <xsl:variable name="rssNoItems" select="string('10')"/>
      <xsl:variable name="rssTitle" select="string('My sample rss')"/>
      <xsl:variable name="siteURL" select="string('Add your url here')"/>
      <xsl:variable name="rssDescription" select="string('Add your description here')"/>

      <!-- 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="$currentPage/* [@isDoc]">
          <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: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="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
              <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[ ', ./bodyText,']]&gt;')" disable-output-escaping="yes"/>
            </content:encoded>
          </item>
        </xsl:if>
      </xsl:template>

    </xsl:stylesheet>

     

    The fields i have for my rss feeds are - rssTitle, rssDescription and pubDate, i need to find a way on how to link these fields to the RSS so it will update everytime i add a new news item under my news folder.

     

    Thanks for your help in this matter.

     

  • jonney.corner 13 posts 33 karma points
    May 23, 2013 @ 14:55
    jonney.corner
    0

    This matter has been resolved, thanks all for your responses.

Please Sign in or register to post replies

Write your reply to:

Draft