C#中把RSS输出为HTML——开发自己的RSS Reader

先编写一个自己的xsl:dsclub.xsl
<?xml version="1.0" encoding="UTF-8" ?> 
<!-- Coding:DSclub -->
<xsl:stylesheet
     
version="1.0"
     xmlns:xsl
="http://www.w3.org/1999/XSL/Transform">
     
<xsl:output method="html" />
     
<xsl:template match="rss/channel">
     
<html>
          
<head>
               
<title><xsl:value-of select="title" /></title>
               
<style type="text/css"><![CDATA[
        body{text-align:center;}
                    .ChannelTitle
                    {
                         font:bolder 16px "Impact",serif;
                    }
                    .ArticleContent
                    {
                    }
                    .ArticleTitle
                    {
                         background-color:  #336699;
                         color:  #FFF;
                         font: bold 12px "Verdana",sans-serif;
                         padding: 5px;
                         border-top:1px solid #99CCFF;
             border-left:1px solid #99CCFF;
             border-bottom:1px solid #336699;
             border-right:1px solid #000;
                    }
                    .ArticleTitle a
            {
            color:#FFF;
            }
            .pubTime
            {
            margin-top:3px;
            display:block;
            font:normal 9px serif;
            }
                    .ArticleDescription
                    {
                         color:  #000;
                         font:normal 12px serif;
                         padding:10px;
             text-align:left;
             border:1px solid #000;
                    }
]]>
               
</style>
          
</head>     
          
<body>
               
<xsl:apply-templates select="title" />
               
<xsl:apply-templates select="item" />
          
</body>
     
</html>
     
</xsl:template>
     
<xsl:template match="title">
          
<div class="ChannelTitle">
               
<xsl:value-of select="text()" />
          
</div>
          
<br />
     
</xsl:template>
     
<xsl:template match="item">
          
<div class="ArticleContent">
               
<div class="ArticleTitle">
                    
<href="{link}"><xsl:value-of select="title" /></a>
               
<span class="pubTime">
                    
<xsl:value-of select="pubDate" />
               
</span>
               
</div>
               
<div class="ArticleDescription">
                    
<xsl:value-of select="description" disable-output-escaping="yes"/>
               
</div>
          
</div>
          
<br />
     
</xsl:template>
</xsl:stylesheet>


在aspx中
        public void TransXML(string strXMLURL)
        
{
            System.Xml.XPath.XPathDocument xdoc 
= new System.Xml.XPath.XPathDocument(strXMLURL);

            System.Xml.Xsl.XslTransform xslt 
= new System.Xml.Xsl.XslTransform();
            xslt.Load(Context.Server.MapPath(
"dsclub.xsl"));
            xslt.Transform(xdoc, 
null, Response.OutputStream, null);

        }

再调用这个方法:
            TransXML("http://www.cnblogs.com/dsclub/Rss.aspx");

运行这个aspx就OK了。
posted @ 2006-01-13 11:32  torome  阅读(420)  评论(0编辑  收藏  举报