改了一个转换RSS的通用XSLT

从CustomReader的目录中找到老长一个.xsl文件,让我给缩短了。

试了一下。起码对各版本RSS支持都还不错:)

<?xml version="1.0" encoding="UTF-8"?>
<!-- RSS/ATOM/RDF tranformation stylesheet (c) 2005 CustomReader.com  -->

<xsl:stylesheet
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
 xmlns:feed="http://purl.org/atom/ns#"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:purl="http://purl.org/rss/1.0/"
 xmlns:rss="http://purl.org/net/rss1.1#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 exclude-result-prefixes="xsl feed rdf rss dc"
>

<xsl:output
 method="html"
 encoding="UTF-8"
 media-type="text/xml"
 indent="yes"
 omit-xml-declaration="no"
/>

<xsl:template match="/rss/channel | /rss:Channel | /feed:feed | /rdf:RDF">
 <div>
   <h2>
    <xsl:element name="a">
     <xsl:attribute name="href">
      <xsl:value-of select="link | rss:link | feed:link/@href | purl:channel/purl:link"/>
     </xsl:attribute>
     <xsl:value-of select="title | feed:title | rss:title | purl:channel/purl:title"/>
    </xsl:element>
   </h2><ul>

   <xsl:for-each select="item | rss:items/rss:item | feed:entry | purl:item">
    <li>
     <a>
      <xsl:attribute name="href">
       <xsl:value-of select="link | rss:link | feed:link/@href | purl:link"/>
      </xsl:attribute>
      <xsl:attribute name="title">
       <xsl:value-of select="description | rss:description | feed:content | purl:description" disable-output-escaping="yes"/>
      </xsl:attribute>
      <xsl:value-of select="title | rss:title | feed:title | purl:title" disable-output-escaping="yes"/>
     </a>
    </li>
   </xsl:for-each>
 </ul></div>
</xsl:template>

</xsl:stylesheet>

转载于:https://www.cnblogs.com/civ3/archive/2005/09/08/232551.html

猜你喜欢

转载自blog.csdn.net/weixin_34341117/article/details/93571498