用于c# . net SyndicationFeed的XSLT到XHTML
本文关键字:XSLT XHTML SyndicationFeed net 用于 | 更新日期: 2023-09-27 18:04:07
我正在使用. net SyndicationFeed类创建一个RSS提要供使用,但是我需要将XSLT样式表链接到生成的XML,以便为web浏览器设置结果的样式。我还没能找到一个简单的方法来做这件事。
在生成提要之后,我最好是将<?xml-stylesheet ... ?>
标记插入到生成的XML中,还是有更优雅的解决方案?提前感谢,我真的很感谢你的帮助。除了直接修改生成的XML,我还没有找到更好的解决方案。
我不认为将xml-stylesheet
处理指令写入与编写SyndicationFeed相同的XmlWriter有任何问题,例如示例代码
SyndicationFeed feed = new SyndicationFeed("Test Feed", "This is a test feed", new Uri("http://http://example.com/testfeed"), "TestFeedID", DateTime.Now);
SyndicationItem item = new SyndicationItem("Test Item", "This is the content for Test Item", new Uri("http://example.com/ItemOne"), "TestItemID", DateTime.Now);
List<SyndicationItem> items = new List<SyndicationItem>();
items.Add(item);
feed.Items = items;
using (XmlWriter xw = XmlWriter.Create(Console.Out, new XmlWriterSettings() { Indent = true }))
{
xw.WriteStartDocument();
xw.WriteProcessingInstruction("xml-stylesheet", "type='"text/xsl'" href='"sheet.xsl'"");
Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(feed);
atomFormatter.WriteTo(xw);
xw.Close();
}
写道<?xml-stylesheet type="text/xsl" href="sheet.xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">Test Feed</title>
<subtitle type="text">This is a test feed</subtitle>
<id>TestFeedID</id>
<updated>2011-08-02T13:19:12+02:00</updated>
<link rel="alternate" href="http://http//example.com/testfeed" />
<entry>
<id>TestItemID</id>
<title type="text">Test Item</title>
<updated>2011-08-02T13:19:12+02:00</updated>
<link rel="alternate" href="http://example.com/ItemOne" />
<content type="text">This is the content for Test Item</content>
</entry>
</feed>