Java:将RSS提要转换为HTML
我目前正在做一个java项目,在那里我得到一个包含RSS提要的url,需要将RSS提要转换成HTML。因此,我做了一些研究,并设法将其转换为XML,以便使用XSLT将其转换为HTML。但是,该过程需要一个XSL文件,我不知道如何获取/创建该文件。我将如何着手解决这个问题?我无法硬编码,因为资源url可能会更改站点上的事件/新闻,从而影响我的输出 RSS源有两种格式:和-根据您想要/需要处理哪种类型,您将需要不同的XSLT 这是一个非常简单的XSLT,可将RSS 2.0提要转换为HTML页面:Java:将RSS提要转换为HTML,java,xml,xslt,rss,Java,Xml,Xslt,Rss,我目前正在做一个java项目,在那里我得到一个包含RSS提要的url,需要将RSS提要转换成HTML。因此,我做了一些研究,并设法将其转换为XML,以便使用XSLT将其转换为HTML。但是,该过程需要一个XSL文件,我不知道如何获取/创建该文件。我将如何着手解决这个问题?我无法硬编码,因为资源url可能会更改站点上的事件/新闻,从而影响我的输出 RSS源有两种格式:和-根据您想要/需要处理哪种类型,您将需要不同的XSLT 这是一个非常简单的XSLT,可将RSS 2.0提要转换为HTML页面: &
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="text()"></xsl:template>
<xsl:template match="item">
<h2>
<a href="{link}">
<xsl:value-of select="title"/>
</a>
</h2>
<p>
<xsl:value-of select="description" disable-output-escaping="yes"/>
</p>
</xsl:template>
<xsl:template match="/rss/channel">
<html>
<head>
<title>
<xsl:value-of select="title"/>
</title>
</head>
</html>
<body>
<h1>
<a href="{link}">
<xsl:value-of select="title"/>
</a>
</h1>
<xsl:apply-templates/>
</body>
</xsl:template>
</xsl:stylesheet>
…这对于ATOM提要也是一样的:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://www.w3.org/2005/Atom">
<xsl:output method="html" indent="yes"/>
<xsl:template match="text()"></xsl:template>
<xsl:template match="atom:entry">
<h2>
<a href="{atom:link/@href}">
<xsl:value-of select="atom:title"/>
</a>
</h2>
<p>
<xsl:value-of select="atom:summary"/>
</p>
</xsl:template>
<xsl:template match="/atom:feed">
<html>
<head>
<title>
<xsl:value-of select="atom:title"/>
</title>
</head>
</html>
<body>
<h1>
<a href="{atom:link/@href}">
<xsl:value-of select="atom:title"/>
</a>
</h1>
<xsl:apply-templates/>
</body>
</xsl:template>
</xsl:stylesheet>
RSS源有两种格式:和-根据您想要/需要处理哪种类型,您将需要不同的XSLT
这是一个非常简单的XSLT,可将RSS 2.0提要转换为HTML页面:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="text()"></xsl:template>
<xsl:template match="item">
<h2>
<a href="{link}">
<xsl:value-of select="title"/>
</a>
</h2>
<p>
<xsl:value-of select="description" disable-output-escaping="yes"/>
</p>
</xsl:template>
<xsl:template match="/rss/channel">
<html>
<head>
<title>
<xsl:value-of select="title"/>
</title>
</head>
</html>
<body>
<h1>
<a href="{link}">
<xsl:value-of select="title"/>
</a>
</h1>
<xsl:apply-templates/>
</body>
</xsl:template>
</xsl:stylesheet>
…这对于ATOM提要也是一样的:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://www.w3.org/2005/Atom">
<xsl:output method="html" indent="yes"/>
<xsl:template match="text()"></xsl:template>
<xsl:template match="atom:entry">
<h2>
<a href="{atom:link/@href}">
<xsl:value-of select="atom:title"/>
</a>
</h2>
<p>
<xsl:value-of select="atom:summary"/>
</p>
</xsl:template>
<xsl:template match="/atom:feed">
<html>
<head>
<title>
<xsl:value-of select="atom:title"/>
</title>
</head>
</html>
<body>
<h1>
<a href="{atom:link/@href}">
<xsl:value-of select="atom:title"/>
</a>
</h1>
<xsl:apply-templates/>
</body>
</xsl:template>
</xsl:stylesheet>
非常感谢,这真的很有帮助。我仍然有点不确定如何为这个RSS提要创建自己的XSL文件。如何包含诸如pubDate等属性。?来自计算机科学的事件:其他事件Aukkand.A.Nz最新的事件来自计算机科学:其他事件Ennz THU 9月11日上午0:00 00 NZST 3913星期三,2013年9月11日11:35:37 + 1200奥克兰大学其他研究生研究生事件?来听听我们的工作人员谈论是什么激发了他们的灵感和激情——他们的研究。2013年9月11日]]>2013年9月11日星期三13:00:00+1200 2013年9月25日星期三14:00:00+1200非常感谢,这真的很有帮助。我仍然有点不确定如何为这个RSS提要创建自己的XSL文件。如何包含诸如pubDate等属性。?来自计算机科学的事件:其他事件Aukkand.A.Nz最新的事件来自计算机科学:其他事件Ennz THU 9月11日上午0:00 00 NZST 3913星期三,2013年9月11日11:35:37 + 1200奥克兰大学其他研究生研究生事件?来听听我们的工作人员谈论是什么激发了他们的灵感和激情——他们的研究。2013年9月11日]]>2013年9月11日星期三13:00:00+1200 2013年9月25日星期三14:00:00+1200