zoukankan      html  css  js  c++  java
  • RSS News Module的应用

    记得之前老有人在论坛上问:到底RSS News模块如何使用,为啥总有一些Html的Tags呈现在页面,使得页面极为不美观,也不和谐,在这之前先要明白RSS其实是XML格式文件,具有自己element(即相对应的节点),类似下图:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <rss version="2.0">
      
    <channel>
        
    <title>Moreover Technologies - Human resources news - of 1054 returned</title>
        
    <link>http://www.moreover.com/rss</link>
        
    <description>Moreover Technologies - Human resources news - More than 340 categories of real-time RSS news feeds.</description>
        
    <language>en-us</language>
        
    <image>
          
    <title>Moreover Technologies</title>
          
    <url>http://i.moreover.com/pics/rss.gif</url>
          
    <link>http://www.moreover.com/rss</link>
          
    <width>144</width>
          
    <height>16</height>
          
    <description>Moreover Technologies - Real-time RSS news feeds harvested from more than 11,000 sources</description>
        
    </image>
        
    <item>
          
    <title>Defining the heart of international relocation training (part II) </title>
          
    <link>http://c.moreover.com/click/here.pl?r472994608</link>
          
    <description>The greatest source of growth for most organisations is international, and therefore dollars spent on training for international success go farther than training dollars spent on anything else.</description>
          
    <guid>http://c.moreover.com/click/here.pl?r472994608</guid>
          
    <pubDate>Thu, 23 Feb 2006 22:20:00 GMT</pubDate>
          
    <source url="http://p.moreover.com/page?s=Expatica%20HR&amp;o=rss002">Expatica HR</source>
        
    </item>
    .
      
    </channel>
    </rss>


    而所以出现提到的问题是由于RSS News Module默认使用自带的News Feed Style Sheet(似乎可以翻译为样式单,但觉得有些别扭,所以就直接用英文了)的缘故RSS91.xsl,其源代码如下:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>
    <xsl:param name="TITLE"/>

    <xsl:template match="rss">
      
    <!-- Do not show channel image -->
      
    <xsl:for-each select="channel/item">
        
    <br>

        
    <strong><href="{link}" target="_main"><xsl:value-of select="title"/></a></strong><br></br>

        
    <!-- only display markup for description if it's present -->
        
    <xsl:value-of select="description"/>

        
    </br>
        
    <br></br>
      
    </xsl:for-each>
    </xsl:template>

    <xsl:template match="description">
      
    <br>
        
    <xsl:value-of select="."/>
      
    </br>
    </xsl:template>

    </xsl:stylesheet>

    仔细一看你会发现该style sheet是对应 RSS的版本是1.0(<xsl:stylesheet version="1.0".....),如果你所填入的RSS Source是RSS 2.0的话,所最终呈现的就不是格式化的RSS,其中有些RSS Source对应的XML文件的内容就可能是混乱的,而其实XSL转换文件即News Feed Style Sheet就是解决之道,只是这是我们需要修改默认的RSS91.xsl,你可以复制该全部内容到新文件里,然后命名为新的XSL转换文件(后缀.xsl),继而通过上传到DNN,如下图:

    1)    点击 Upload New File
    2)    上传新的XSL文件
    3)    更新
    下边来谈论具体该如何修改默认的XSl文件,最简单的办法就是允许出现Html格式的内容,即将原来的
        
        <xsl:value-of select="description"/>
    变为:

    <xsl:value-of disable-output-escaping="yes" select="description"/>

    这样就可以正确呈现带有Html Tags的RSS文件内容。
    更多的就是你还可以决定你需要呈现那些内容,比如你希望有日期,那你可以加入一个element:

    <xsl:value-of select="pubDate"/>

    在此增加一个类似的XSL文件作为参考:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>

    <xsl:template match="rss/channel"> 
    <xsl:variable name="link" select="link"/>
      
    <xsl:variable name="description" select="description"/>
      
    <xsl:variable name="image" select="image/url"/>
      
    <xsl:variable name="idesc" select="image/description"/>
      
    <xsl:variable name="ilink" select="image/link"/>
      
    <xsl:variable name="iwide" select="image/width"/>
      
    <xsl:variable name="ihigh" select="image/height"/>
    <div class="head">
     
    <xsl:if test="$image">
        
    <href="{$ilink}" title="{$idesc}"><xsl:value-of select="ilink" /></a>
        
    <img src="{$image}" height="{$ihigh}" width="{$iwide}" style="float: left; margin: 2px; border: 0px;"/>
     
    </xsl:if> 
     
    <font size="-2"><xsl:value-of select="description"/><br/>
         
    <href="{$link}"><xsl:value-of select="title" /></a><br/>
     
    <xsl:value-of select="webMaster"/><br/>
     
    <xsl:value-of select="copyright"/></font>
     
    <hr/>
    </div>
      
    <xsl:apply-templates select="item"/>
    </xsl:template>

    <xsl:template match="item">
      
    <xsl:variable name="item_link" select="link"/>
      
    <xsl:variable name="item_title" select="description"/>
      
    <div class="subHead" style="500px;">
        
    <href="{$item_link}"><xsl:value-of select="title" disable-output-escaping="yes"/></a></div>
        
    <div style="500px;">
     
    <xsl:value-of select="description" disable-output-escaping="yes"/><br/></div>

     (
    <xsl:value-of select="pubDate"/>)<br/> <hr/>
     
    </xsl:template>

    </xsl:stylesheet>


     

  • 相关阅读:
    Regexp:教程
    Regexp:目录
    笔记-C#:C# 方法、属性杂项-01
    Regexp:正则表达式应用——实例应用
    正则表达式:百科
    Regexp:template
    AngularJS:参考手册
    命令目录
    java实现连续数的公倍数
    java实现连续数的公倍数
  • 原文地址:https://www.cnblogs.com/sunwangji/p/337226.html
Copyright © 2011-2022 走看看