Copied to clipboard

Flag this post as spam?

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


  • Louis 37 posts 59 karma points
    Jan 03, 2012 @ 16:25
    Louis
    0

    Create an RSS Feed problems

    Hi all,

     

    I am pretty new to Umbraco but have managed to do alot of cool things in a short space of time. One thing that I simply cannot do is the RSS Feed! This seems to be the most difficult thing to do! I have been trying for days to get this damn thing working but it wont!

     

    Ok, here's what i have done,

     

    I went into XSLT Files, created a new RSS Feed document, then added the URL to the section in the site, i.e. News, which contains news files. 

     

    Please view my code down below.

     

    Once I have created this XSLT, I go into the document types, create a new one, with a new master page, add the macro in, then create the page in the Content section.

    When I do this I Get the following error:

     

     

    ERROR:

     

    This page contains the following errors:

     

    error on line 3 at column 6: XML declaration allowed only at the start of the document

    Below is a rendering of the page up to the first error.

     

     

    Does anyone have any idea where I am going wrong? I have looked at the source and it looks like it's not looping through the directory files of News.

    However.....when I add this macro to my home page, it errors, but when looking at the source I can see a load of lovely XML!???

     

    What's going on?!?!?

     

     

    Thanks

     

    Louis

     

     

     

     

     

     

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

     

      <!-- 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('http://localhost:58281/news.aspx')"/>

      <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>

     

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 03, 2012 @ 16:30
    Tom Fulton
    1

    Hi Louis,

    In your template that contains your macro, make sure there is no whitespace before the macro.  Some browsers have a problem with whitespace before the XML declaration.  Ex:

    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"><umbraco:Macro Alias="YourMacro" runat="server" /></asp:Content>

    Hope this helps,
    Tom

  • Louis 37 posts 59 karma points
    Jan 03, 2012 @ 16:38
    Louis
    1

    Cool, that sort of worked, I get the following code which is XML but does not list all the files in my directory:

    <rss 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" version="2.0">
    <channel>
    <title>My sample rss</title>
    <pubDate/>
    <generator>umbraco</generator>
    <description>Add your description here</description>
    <language>en</language>
    </channel>
    </rss>
    Any suggestions?
    Thanks
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 03, 2012 @ 16:42
    Tom Fulton
    0

    Hmm, looking at the code it should work.

    Where are you calling this template from & how?  Perhaps you're calling it from a page that has no children?

    You should probably call it from your news page, ie /news.aspx?altTemplate=YourTemplateAlias

    -Tom

  • Louis 37 posts 59 karma points
    Jan 03, 2012 @ 17:00
    Louis
    0

     

    I have created a page under tha News Section which houses all the news files,

    so the structure looks like:

    News

    >> news item 1

    >> news item 2

    >> news item 3

    >> rss

     

     

    The RSS page is a seperate type of document which contains the macro, but when I include the macro inside the News Page, it renders the xml.

    I'm confused as to how to get this working, why would it work in the news page but not in a seperate page? Surely you would want to view your rss in a seperate page?

     

    Thanks

     

  • Louis 37 posts 59 karma points
    Jan 03, 2012 @ 17:02
    Louis
    0

    Oh, i am calling it by typing the url in the browser, RSS.aspx

  • Louis 37 posts 59 karma points
    Jan 03, 2012 @ 17:16
    Louis
    0

    YES!! it worked!!!! Thank you so much!!!! You have no idea how mental this has been driving me!!!!!

    I did the following, deleted the spaces as you said then called the rss feed as you specified:

     

    http://localhost:58281/news.aspx?altTemplate=NewsRSSFeed

    Thanks!!!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 03, 2012 @ 17:18
    Tom Fulton
    0

    Ok, if you're calling it from it's own document type, you'll want to modify the XPath to select your news items.  Right now it's set to select all subpages under the current document (RSS.aspx), and I'm guessing there is none there.

    So you can change the apply-templates line to select your news items instead:

    <xsl:apply-templates select="$currentPage/ancestor-or-self::YourHomepageAlias [@isDoc]/YourNewsPageAlias [@isDoc]/* [@isDoc and string(umbracoNaviHide) != '1']">

    Change YourHomepageAlias and YourNewsPageAlias to the aliases if your doctypes.

    Also, sometimes people don't create a separate doctype for their RSS feed and call it via an altTemplate instead - that way it applies to whatever page it's called from.  But this should work as well :)

    -Tom

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 03, 2012 @ 17:18
    Tom Fulton
    0

    Ah..too late, glad you got it.  If you want to use altTemplate instead you no longer need your RSS doctype :)

Please Sign in or register to post replies

Write your reply to:

Draft