在我的网站上生成RSS源时,在拾取我的XSL表时遇到一些麻烦。
我正在通过VB中的代码执行此操作,但是当生成RSS时,它们都会在一行中完成。
我做错了什么?
Public Sub RssFeed(ByVal cxt As HttpContext)
Dim outString As String = ""
cxt.Response.Clear()
cxt.Response.ContentType = "application/rss+xml"
cxt.Response.ContentEncoding = System.Text.Encoding.UTF8
Using xw As New XmlTextWriter(cxt.Response.OutputStream, Text.Encoding.UTF8)
xw.WriteStartDocument()
'processing instruction to style the rss
Dim PIText As String = "type=""text/xsl"" href=""Styles/rss.xsl"""
xw.WriteProcessingInstruction("xml-stylesheet", PIText)
xw.WriteStartElement("rss")
xw.WriteAttributeString("version", "2.0")
xw.WriteAttributeString("xmlns", "atom", Nothing, "http://www.w3.org/2005/Atom")
'channel contains all the RSS feed details
xw.WriteStartElement("channel")
xw.WriteStartElement("atom:link")
xw.WriteAttributeString("stuff")
xw.WriteEndElement()
xw.WriteElementString("title")
xw.WriteElementString("link")
xw.WriteElementString("description")
xw.WriteElementString("language", "en-gb")
xw.WriteStartElement("category")
xw.WriteAttributeString("domain")
xw.WriteString("Event Log")
xw.WriteEndElement()
'db connection stuff
编辑2
在网络标签下通过Chrome检查元素时,类型为“text / plain” - 因此它无法将文件管理器识别为RSS / XML。
我更新了上面的代码以包含行cxt.Response.ClearHeaders()
,但这并没有改变浏览器解释文件的方式。
编辑2
这里要求的是我正在使用的简化XSLT表。
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">
<xsl:output method="html" />
<xsl:variable name="title" select="/rss/channel/title"/>
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" href="/rss.css" type="text/css"/>
</head>
<xsl:apply-templates select="rss/channel"/>
</html>
</xsl:template>
<xsl:template match="channel">
<body>
<h2>heading</h2>
<h6>small heading</h6>
<table border ="1">
<tr>
<td bgcolor="#7DCC3D">Title</td>
<td bgcolor="#333366">Link</td>
<td bgcolor="#7DCC3D">Description</td>
<td bgcolor="#333366">Published</td>
</tr>
<xsl:for-each select="rss/channel/item">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="link"/></td>
<td><xsl:value-of select="description"/></td>
<td><xsl:value-of select="pubDate"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
我认为这与IIS有关;如果从rss+
中删除cxt.Response.ContentType = "application/rss+xml"
,则会呈现XSLT。
我会在发现问题时调查问题原因并更新我的答案。