我是Umbraco的新手,但在短時間內設法做了很多很酷的事情。我根本無法做的一件事就是RSS Feed!這似乎是最難做的事!我一直在努力幾天才能讓這個該死的東西工作,但它不會!Umbraco:創建RSS提要問題
好吧,這裏是我做了什麼,
我走進XSLT文件,創建一個新的RSS Feed文檔,然後添加URL到站點的部分,即新聞,其中包含新聞的文件。
您可以在下面查看我的代碼。
一旦我創建了這個XSLT,我進入文檔類型,創建一個新的,帶有新的母版頁,添加宏,然後在內容部分創建頁面。
當我這樣做,我得到以下錯誤:
ERROR:
This page contains the following errors:
error on line 3 at column 6: XML declaration allowed only at the start of the document
下面是向上翻頁的渲染的第一個錯誤。
有沒有人有任何想法我錯了?我查看了源代碼,看起來它並沒有循環通過News的目錄文件。
但是,當我將此宏添加到我的主頁時,它顯示錯誤,但是在查看源代碼時,我可以看到可愛的XML負載?
這裏發生了什麼問題?
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"><?xml version="1.0" encoding="UTF-8"?></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() <= $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('<![CDATA[ ', ./bodyText,']]>')" disable-output-escaping="yes"/>
</content:encoded>
</item>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
我建議你通過FeedVaidator運行你的feed輸出。您可能在XML聲明之前留出空白,這會導致您看到的錯誤。 http://feedvalidator.org/docs/error/WPBlankLine.html – Oppositional 2012-01-03 20:58:09
@Funky請接受有用的答案,或者提供有關如何解決它的答案(如果下面的答案沒有幫助你)..:D – 2013-04-17 05:29:23