私は現在、RSS フィードを含む URL を取得する Java プロジェクトを行っており、その RSS フィードを HTML に変換する必要があります。ということで、ちょっと調べてみたらなんとかXMLに変換できたので、XSLTでHTMLに変換できます。ただし、そのプロセスには XSL ファイルが必要であり、取得/作成する方法がわかりません。この問題を試みるにはどうすればよいですか?リソースの URL によってサイトのイベントやニュースが変更され、結果として出力に影響する可能性があるため、ハード コードすることはできません。
質問する
2106 次
1 に答える
1
RSS フィードには、 RSS 2.0とATOMの 2 つの形式があります。どちらの種類を処理する必要があるかによって、異なる XSLT が必要になります。
これは、RSS 2.0 フィードを HTML ページに変換する非常に単純な XSLT です。
<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>
于 2013-09-10T13:15:52.840 に答える