RSS配信の件数指定
Posted: 2007年3月12日(月) 12:22
こんにちは。RSS配信をやってみたのですが、登録しているすべてのニュースが配信されてしまします。これを5件のみ、と指定したいのですが、やり方がよくわかりません。
質問フォーラムを検索してみたところ、デザイン定義ファイルに、
<xsl:for-each select="rss:item">
<xsl:if test="position()<=5">
この中に記事の出力処理を書く
</xsl:if>
</xsl:for-each>
を貼り付ければOK、と書いてありました。デザイン定義ファイルは、具体的には以下のどこを貼りかえればよろしいのでしょうか?
よろしくお願いいたします。
------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:sy = "http://purl.org/rss/1.0/modules/syndication/"
xmlns:dc = "http://purl.org/dc/elements/1.1/"
xmlns:xh = "http://www.w3.org/1999/xhtml"
xmlns = "http://purl.org/rss/1.0/" >
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="no" indent="no" />
<xsl:variable name="baseUrl" select="'http://www.xxx.net/RSS/'" />
<xsl:variable name="index" select="concat($baseUrl, 'testindex.php')" />
<xsl:variable name="rdfphp" select="concat($baseUrl, 'topnewsrss.php')" />
<xsl:variable name="entryphp" select="concat($baseUrl, 'topnewsentry.php')" />
<xsl:variable name="title" select="'RSSテスト'" />
<xsl:variable name="description" select="'RSSテストです。'" />
<xsl:variable name="subject" select="'お知らせ'" />
<xsl:template match="/entrylist">
<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xml:lang="ja">
<channel rdf:about="{$index}">
<title><xsl:value-of select="$title" /></title>
<link><xsl:value-of select="$index" /></link>
<description><xsl:value-of select="$description" /></description>
<items>
<rdf:Seq>
<xsl:for-each select="entry">
<rdf:li rdf:resource="{$entryphp}{@href}"/>
</xsl:for-each>
</rdf:Seq>
</items>
</channel>
<xsl:for-each select="entry">
<item rdf:about="{$entryphp}{@href}">
<title><xsl:value-of select="title" /></title>
<link><xsl:value-of select="concat($entryphp,@href)" /></link>
<description><xsl:value-of select="description" /></description>
<dc:date><xsl:value-of select="@year" />-<xsl:value-of select="@month" />-<xsl:value-of select="@day" />T<xsl:value-of select="@hour" />:<xsl:value-of select="@minute" />:<xsl:value-of select="@second" />+09:00</dc:date>
<dc:subject><xsl:value-of select="$subject" /></dc:subject>
</item>
</xsl:for-each>
</rdf:RDF>
</xsl:template>
</xsl:stylesheet>
------------------------------------------------------
質問フォーラムを検索してみたところ、デザイン定義ファイルに、
<xsl:for-each select="rss:item">
<xsl:if test="position()<=5">
この中に記事の出力処理を書く
</xsl:if>
</xsl:for-each>
を貼り付ければOK、と書いてありました。デザイン定義ファイルは、具体的には以下のどこを貼りかえればよろしいのでしょうか?
よろしくお願いいたします。
------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:sy = "http://purl.org/rss/1.0/modules/syndication/"
xmlns:dc = "http://purl.org/dc/elements/1.1/"
xmlns:xh = "http://www.w3.org/1999/xhtml"
xmlns = "http://purl.org/rss/1.0/" >
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="no" indent="no" />
<xsl:variable name="baseUrl" select="'http://www.xxx.net/RSS/'" />
<xsl:variable name="index" select="concat($baseUrl, 'testindex.php')" />
<xsl:variable name="rdfphp" select="concat($baseUrl, 'topnewsrss.php')" />
<xsl:variable name="entryphp" select="concat($baseUrl, 'topnewsentry.php')" />
<xsl:variable name="title" select="'RSSテスト'" />
<xsl:variable name="description" select="'RSSテストです。'" />
<xsl:variable name="subject" select="'お知らせ'" />
<xsl:template match="/entrylist">
<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xml:lang="ja">
<channel rdf:about="{$index}">
<title><xsl:value-of select="$title" /></title>
<link><xsl:value-of select="$index" /></link>
<description><xsl:value-of select="$description" /></description>
<items>
<rdf:Seq>
<xsl:for-each select="entry">
<rdf:li rdf:resource="{$entryphp}{@href}"/>
</xsl:for-each>
</rdf:Seq>
</items>
</channel>
<xsl:for-each select="entry">
<item rdf:about="{$entryphp}{@href}">
<title><xsl:value-of select="title" /></title>
<link><xsl:value-of select="concat($entryphp,@href)" /></link>
<description><xsl:value-of select="description" /></description>
<dc:date><xsl:value-of select="@year" />-<xsl:value-of select="@month" />-<xsl:value-of select="@day" />T<xsl:value-of select="@hour" />:<xsl:value-of select="@minute" />:<xsl:value-of select="@second" />+09:00</dc:date>
<dc:subject><xsl:value-of select="$subject" /></dc:subject>
</item>
</xsl:for-each>
</rdf:RDF>
</xsl:template>
</xsl:stylesheet>
------------------------------------------------------