Copied to clipboard

Flag this post as spam?

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


  • Isis 21 posts 42 karma points
    Aug 15, 2011 @ 15:12
    Isis
    0

    RSS Feed outputting data within <channel> but out of <item>

    Hello guys,

    So I finally managed to get an RSS feed outputting the items I wanted it to (it wasn't easy, and still isn't properly correct, but I can live with the caveats for the time being.)

    However, the feed spits out content seemingly from other areas of the site, image I have the following structure (I thought this could be down to page inheritance, maybe it was spitting out the content of an inherited master, but alas, I have set the master to 'none' for the NewsRssFeed page and it still gets outputed):

    Media
      News
        NewsItem1
        NewsItem2
        NewsItem3
    NewsRssFeed

    I use the following selector in my RSS XSLT:

    $currentPage/descendant::*

    And the output is similar to this:

    <channel>
      <title></title>
      <link></link>
      <pubDate/>
      <generator></generator>
      <description></description>
      <language>en</language>
      <item>...</item>
      <item>...</item>
      <item>...</item>
    A bunch of page content is written here!
    </channel>

    Here is the XSTL in full:

    <?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" xmlns:umbraco.CustomLibrary="urn:umbraco.CustomLibrary" xmlns:umbraco.contour="urn:umbraco.contour" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.CustomLibrary umbraco.contour ">
      <xsl:output method="xml" omit-xml-declaration="yes"/>
      <xsl:param name="currentPage"/>
      <!-- Input the documenttype you want here -->
      <xsl:variable name="documentTypeAlias" select="string('News')"/>  
      <!-- Update these variables to modify the feed -->
      <xsl:variable name="RSSNoItems" select="string('10')"/>
      <xsl:variable name="RSSTitle" select="string('')"/>
      <xsl:variable name="SiteURL" select="concat(' http://',string(umbraco.library:RequestServerVariables('HTTP_HOST')))"/>
      <xsl:variable name="RSSDescription" select="string('')"/>
      <!-- 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/descendant::*">
          <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/descendant::* [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="umbraco.library:NiceUrl(@id)"/>
            </link>
            <pubDate>
              <xsl:value-of select="umbraco.library:FormatDateTime(@createDate,'r')" />
            </pubDate>
            <guid>
              <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
            </guid>
            <content:encoded>
              <xsl:value-of select="concat('&lt;![CDATA[ ', ./data [@alias='bodyText'],']]&gt;')" disable-output-escaping="yes"/>
            </content:encoded>
          </item>
        </xsl:if>
      </xsl:template>
    </xsl:stylesheet>

    Perhaps the most peculiar part is that what is being outputted is very definitely on a page somewhere (I found some of the content on the About page) but it doesn't have this content in full, just a paragraph or so, and it starts with a number: maybe some keywords and DateTimes; below is an example:

    10R&amp;R - NewsWe're proud of our company, the people who work in it and the values and ethics we adhere to. Here's how we do business at R&amp;R - we hope you'll like what you see too.JOB,JOBS,RECRUITMENT,OPPORTUNITIES,ICE,CREAM,ICECREAM,SKINNY COW,FAB,MYFABLAND,KELLYS,KELLY'S,KELLYS OF CORNWALL,KELLY'S OF CORNWALL,TREATS,NESTLE,MARYLAND,THORNTONS,LYONS MAID, RIBENA, PRODUCTION,ENGINEERING,ELECTRICALAdministrator1114112010-08-09T00:00:00Coalition Minister visits R&R Ice Cream in 25th anniversary year.

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 15, 2011 @ 15:35
    Tom Fulton
    1

    I think it might be possible that your apply-templates select condition is selecting elements that don't match "node", and there is no template to handle them.

    What you might try is replacing "*" with "node" in your XPath:

    <xsl:apply-templates select="$currentPage/descendant::node [string(data [@alias='umbracoNaviHide']) != '1']">
              <xsl:sort select="@createDate" order="descending" />
            </xsl:apply-templates>

    Just a shot in the dark :)

    -Tom

  • Isis 21 posts 42 karma points
    Aug 16, 2011 @ 10:29
    Isis
    0

    Tom, I marked this is as solved yesterday but just thought I'd sign in to declare it, and say thanks.

     

    Grant

Please Sign in or register to post replies

Write your reply to:

Draft