Copied to clipboard

Flag this post as spam?

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


  • Tom Cowling 144 posts 343 karma points
    Jun 25, 2014 @ 16:27
    Tom Cowling
    0

    Tweaking the default RSS feed

    I'm using the built in RSS feed for 6.2.1.

     

    It works fine if I stick all my news items as child nodes of the RSS feed, but I'd like it to store the RSS page at the same level as the news item.

    Home
     -News
        -RSS Feed
        -News item1
        -News item 2
        -News item 3

    So my question is this:

    How do I get the xslt to look for all nodes at the same level as itself and add them to the feed?

    I've done this on another site, but all my select statements seem to be drawing a blank.. I thought the following would work as it did on a previous site, but I don't kow why:

    <xsl:for-each select="$currentPage/parent::node/node [string(data [@alias='showinrss']) != '0']">

    The showinrss code is a tick box to tell the feed not to show itself in the list.

     

    Thanks in advance,

     

    Tom

     

     

    Full code below:

    <?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:Examine="urn:Examine"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Examine ">


    <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('200')"/>
    <xsl:variable name="RSSTitle" select="string($currentPage/feedTitle)"/>
    <xsl:variable name="SiteURL" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))"/>
    <xsl:variable name="RSSDescription" select="string($currentPage/feedDescription)"/>
    <xsl:variable name="RSSPicture" select="string('/media/1003/logo.jpg')"/>


    <!-- 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>
    <description>
    <xsl:value-of select="$RSSDescription"/>
    </description>
    <language>en</language>
    <image>
    <title>
    <xsl:value-of select="$RSSTitle"/>
    </title>
    <link>
    <xsl:value-of select="$SiteURL"/>
    </link>
    <url>
    <xsl:value-of select="$RSSPicture"/>
    </url>
    <width>144</width>
    <height>100</height>
    </image>


    <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 Cowling 144 posts 343 karma points
    Jun 25, 2014 @ 16:49
    Tom Cowling
    100

    Sorted it!

    The xsl template I used instead:

    <xsl:apply-templates select="$currentPage/parent::*[@isDoc]/* [@isDoc and string(umbracoNaviHide) != '1' and string(hidefromrss) != '1']">

     

    Thanks to this thread - http://our.umbraco.org/forum/developers/xslt/15918-Getting-nodes-on-the-same-level-including-the-nodes-above-$currentPage

     

Please Sign in or register to post replies

Write your reply to:

Draft