« Mac De PL/SQL RSS Reader #31 (XSLT編 #3) | トップページ | Mac De PL/SQL RSS Reader #33 (XSLT編 #5) »

2007年4月 1日 (日) / Author : Hiroshi Sekiguchi.

Mac De PL/SQL RSS Reader #32 (XSLT編 #4)

つづきです。

XSLTスタイルシートに関して細かく解説するつもりはありませんが、少しだけ解説しておくと。

RSS 0.91/RSS 0.92/ RDF(RSS)1.0ATOM 0.3 / ATOM 1.0の FEEDからタイトルと元ネタへのリンク、各エントリ毎の要約とリンク、そして、存在してれば、[エントリの作成日]を抜き出してHTMLへ変換している。
尚、OTN-JRSS2.0で配信されているが 各エントリには、<pubDate>要素や、<dc:date>要素は存在せず、拡張された<jf:creationDate>要素に作成日を持っているようなので、<jf:creationDate>要素を処理している。

XSLTについては、@ITの記事などや、検索すれば沢山ヒットするので理解できる範囲かと。。。
(難しいことはやってないですから。)
http://www.atmarkit.co.jp/fxml/tanpatsu/xslt/xslt04.html
http://www.atmarkit.co.jp/fxml/tanpatsu/xslt/xslt10.html

尚、DBMS_XSLPROCESSORパッケージなどは、
http://otndnld.oracle.co.jp/document/products/oracle10g/102/doc_cd/appdev.102/B19245-01/d_xslpro.htmを参照のこと。

簡単な解説はこれぐらいにして、以下、XSLTスタイルシートのソース。
#1時間くらいで作ったものなので、バグが無いとは言えません。あしからず。
#ちなみに、私が読んでいるFEEDでは特に問題は発生していません。

但し、こんな問題もあり2月に入ってからDTDが開けないエラーが発生している。大抵、他の形式でも配布しているからRSS0.91使わなきゃいいだけかも。。

尚、今回作成したXSLTスタイルシートとPL/SQLのソースコードは、こちらからダウンロードできます。 source.zip (3.9K)

<?xml version="1.0" encoding="utf-8"?>
<!-- ===================================================================
rss2html.xsl : 2007/3/26 - Mac De Oracle
https://discus-hamburg.cocolog-nifty.com/mac_de_oracle/
==================================================================== -->
<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:rss10="http://purl.org/rss/1.0/"
xmlns:atom03="http://purl.org/atom/ns#"
xmlns:atom10="http://www.w3.org/2005/Atom"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:jf="http://www.jivesoftware.com/xmlns/jiveforums/rss"
>


<xsl:output method="html" encoding="utf-8" />
<xsl:template match="/">
<table border="0" cellpadding="0" cellspacing="2">
<tr>
<th>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:apply-templates select="//rdf:RDF/rss10:channel/rss10:link"/>
<xsl:apply-templates select="//atom03:feed/atom03:link/@href"/>
<xsl:apply-templates select="//atom10:feed/atom10:link/@href"/>
<xsl:apply-templates select="//rss/channel/link"/>
</xsl:attribute>
<xsl:apply-templates select="//rdf:RDF/rss10:channel/rss10:title"/>
<xsl:apply-templates select="//atom03:feed/atom03:title"/>
<xsl:apply-templates select="//atom10:feed/atom10:title"/>
<xsl:apply-templates select="//rss/channel/title"/>
</xsl:element>
</th>
</tr>
<xsl:apply-templates select="//rdf:RDF/rss10:item" mode="normal"/>
<xsl:apply-templates select="//atom03:feed/atom03:entry" mode="normal"/>
<xsl:apply-templates select="//atom10:feed/atom10:entry" mode="normal"/>
<xsl:apply-templates select="//rss/channel/item" mode="normal"/>
</table>
</xsl:template>


<!-- RDF/RSS1.0 template -->
<xsl:template match="rss10:item" mode="normal">
<tr>
<td valign="top">
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="rss10:link"/></xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="rss10:link"/></xsl:attribute>
<xsl:attribute name="style">color:#FF0000</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="concat(rss10:title, ' - 続きを読む...')" />
</xsl:element>
<xsl:choose>
<xsl:when test="dc:date">
<xsl:value-of select="concat(' - ', substring-before(dc:date,'T'))"/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</td>
</tr>
</xsl:template>

<xsl:template match="//rdf:RDF/rss10:channel/rss10:title">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="//rdf:RDF/rss10:channel/rss10:link">
<xsl:value-of select="."/>
</xsl:template>


<!-- ATOM 1.0 template -->
<xsl:template match="//atom10:feed/atom10:entry" mode="normal">
<tr>
<td valign="top">
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="atom10:link/@href"/></xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="atom10:summary"/></xsl:attribute>
<xsl:attribute name="style">color:#FF0000</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="concat(atom10:title,' - 続きを読む...')"/>
</xsl:element>
<xsl:choose>
<xsl:when test="atom10:published">
<xsl:value-of select="concat(' - ',substring-before(atom10:published,'T'))"/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</td>
</tr>
</xsl:template>

<xsl:template match="//atom10:feed/atom10:title">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="//atom10:feed/atom10:link/@href">
<xsl:if test="../@rel = 'alternate'">
<xsl:if test="../@type = 'text/html'">
<xsl:value-of select="."/>
</xsl:if>
</xsl:if>
</xsl:template>


<!-- ATOM 0.3 template -->
<xsl:template match="//atom03:feed/atom03:entry" mode="normal">
<tr>
<td valign="top">
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="atom03:link/@href"/></xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="atom03:summary"/></xsl:attribute>
<xsl:attribute name="style">color:#FF0000</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="concat(atom03:title, ' - 続きを読む...')"/>
</xsl:element>
<xsl:choose>
<xsl:when test="atom03:issued">
<xsl:value-of select="concat(' - ', substring-before(atom03:issued, 'T'))"/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</td>
</tr>
</xsl:template>

<xsl:template match="//atom03:feed/atom03:title">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="//atom03:feed/atom03:link/@href">
<xsl:if test="../@rel = 'alternate'">
<xsl:if test="../@type = 'text/html'">
<xsl:value-of select="."/>
</xsl:if>
</xsl:if>
</xsl:template>


<!-- RSS 0.91/0.92/2.0 template -->
<xsl:template match="//rss/channel/item" mode="normal">
<tr>
<td valign="top">
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="link"/></xsl:attribute>
<xsl:attribute name="style">color:#FF0000</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="concat(title, ' - 続きを読む...')"/>
</xsl:element>
<xsl:choose>
<xsl:when test="pubDate">
<xsl:value-of
select="concat(
' - ',
substring(
substring-before(jf:creationDate, ':'),
1,
string-length(substring-before(jf:creationDate, ':'))-3
)
)"
/>
</xsl:when>
<xsl:when test="dc:date">
<xsl:value-of select="concat(' - ', substring-before(dc:date, 'T'))"/>
</xsl:when>
<xsl:otherwise>
<!-- for OTN rss -->
<xsl:if test="jf:creationDate">
<xsl:value-of
select="concat(
' - ',
substring(
substring-before(jf:creationDate, ':'),
1,
string-length(substring-before(jf:creationDate, ':'))-3
)
)"
/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:template>

<xsl:template match="//rss/channel/title">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="//rss/channel/link">
<xsl:value-of select="."/>
</xsl:template>

</xsl:stylesheet>

長くなるので、PL/SQLのソースは次回。




このサンプルは OTN-Jの CodeTipsでも公開しています。

(1/3) http://otn.oracle.co.jp/otn_pl/otn_tool/code_detail?n_code_id=2135
(2/3) http://otn.oracle.co.jp/otn_pl/otn_tool/code_detail?n_code_id=2137
(3/3) http://otn.oracle.co.jp/otn_pl/otn_tool/code_detail?n_code_id=2138

| |

トラックバック


この記事へのトラックバック一覧です: Mac De PL/SQL RSS Reader #32 (XSLT編 #4):

コメント

コメントを書く