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