发布RSS源的问题

时间:2012-08-04 10:29:27

标签: rss umbraco

我无法从我的Umbraco网站发布RSS Feed。我找到了this Umbraco.TV视频,并尝试按照那里的说明使用XSLT选择器来选择给定类型的所有节点,如下所示:

umbraco.library.GetXmlAll()/node [@nodeTypeAlias='Alias]/node

正在消化here,但这不起作用。显然the schema has changed或其他什么。如果这不起作用,我会寻找一个插件来做这种事情,并且惊讶地发现只有2个插件,它们都没有任何文档,似乎都没有工作(first plugin,{{ 3}})。

所以,一劳永逸,我想有一个明确的答案 - 如何在Umbraco中发布RSS提要?

1 个答案:

答案 0 :(得分:0)

这是我们用于新闻项RSS的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="/macro/RSSNoItems"/>
  <xsl:variable name="RSSTitle" select="/macro/RSSTitle"/>
  <xsl:variable name="SiteURL" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))"/>
  <xsl:variable name="RSSDescription" select="/macro/RSSDescription"/>
  <xsl:variable name="source" select="/macro/source"/>

  <!-- 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="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
      <xsl:sort select="./newsDate" order="descending" />
      <xsl:if test="position() = 1">
        <xsl:value-of select="./newsDate" />
      </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 v4</generator>
        <description>
          <xsl:value-of select="$RSSDescription"/>
        </description>
        <language>en</language>

  <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']"> 
  <xsl:sort select="./newsDate" order="descending" />
      <xsl:if test="position() &lt;= $RSSNoItems"> 
    <xsl:call-template name="RSSitem">
                    <xsl:with-param name="node" select="current()"/>
                </xsl:call-template> 
      </xsl:if> 
  </xsl:for-each> 
      </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(./newsDate,'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:template name="RSSitem">
        <xsl:param name="node"/>
        <item>
            <title>
                <xsl:value-of select="$node/@nodeName"/>
            </title>
            <link>
                <xsl:value-of select="$SiteURL"/><xsl:value-of select="umbraco.library:NiceUrl($node/@id)"/>
            </link>
            <pubDate>
                <xsl:value-of select="umbraco.library:FormatDateTime(./newsDate,'r')"/>
            </pubDate>
            <dc:creator><xsl:value-of select="@writerName"/></dc:creator>
            <xsl:for-each select="umbraco.library:Split($node/categories, ',')/value">
                <xsl:sort data-type="text" order="ascending"/>
                <category>
                    <xsl:value-of select="current()"/>
                </category>               
            </xsl:for-each>
            <guid>
                <xsl:value-of select="$SiteURL"/><xsl:value-of select="umbraco.library:NiceUrl($node/@id)"/>
            </guid>
            <description>
                <xsl:value-of select="concat('&lt;![CDATA[ ', $node/summary,']]&gt;')" disable-output-escaping="yes"/>
            </description>
            <content:encoded>
                <xsl:value-of select="concat('&lt;![CDATA[ ', $node/bodyText,']]&gt;')" disable-output-escaping="yes"/>
            </content:encoded>
        </item>       
    </xsl:template> 

</xsl:stylesheet>