仕事、学んでいること、興味のあることなどの「アウトプット」を書き出すブログ。心を高め、魂を磨くために、今日も一生懸命働く。
アマゾンのAPI(Amazon Web Service)を利用して、
このブログの更新を楽にするツールを作ってみました。
⇒XSLTスタイルシートを利用したAmazon Web Service
ツールの内容は、
ブログの記事でアマゾンの本などを紹介する時に、
本のシンプルな画像をフロートを使って右側に掲載するものです。
※ツール使用の例としては、この記事の下の方にある、
「10日でおぼえるXML入門教室 第2版」の画像が、
このツールを使ったものです。
このツールを作るまでは、
自分で画像をダウンロードして、、、
というような面倒な作業をしていたので、
少しだけブログの更新が楽になりました。
【ツールのメリット】
他のサービスは、なぜかテーブルレイアウトばかりで、
ソースも外観もシンプルじゃない。
フロートを使って、リンクも貼らない。
こんなシンプル感じが好きなのは、ぼくだけかな。
アマゾンAPIの使い方は、
調べてみたら、いろいろな用い方があるようです。
今回、とりあえずは、仕様を理解するためにも、
アマゾンから受け取るXMLの扱いには、XSLTスタイルシートを選択しました。
なぜなら、簡単そうだったからです。
実際、XSLTスタイルシートの理解は、
それほど難しくありません。
しかし、最初はPHPの勉強のために、
アマゾンAPIを利用して。。。と思っていたのですが、
XMLの処理に「XSLTスタイルシート」を選択したために、
まったくPHPを使わない。
というようなことになりました。笑
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2008-04-07">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="/">
<html lang="ja">
<head>
<title>XSLTスタイルシート</title>
</head>
<body>
<xsl:apply-templates select="aws:ItemSearchResponse/aws:Items/aws:Item"/>
</body>
</html>
</xsl:template>
<xsl:template match="aws:ItemSearchResponse/aws:Items/aws:Item">
<xsl:apply-templates select="aws:MediumImage"/>
<p>タイトル:
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="aws:DetailPageURL" />
</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="aws:ItemAttributes/aws:Title" />
</xsl:element>
<br />
著者:<xsl:value-of select="aws:ItemAttributes/aws:Author" />
</p>
<p>(1)画像をfloatで右側に移動(リンクなし)※そのまま貼り付けOK</p>
<textarea cols="100" rows="3">
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="aws:MediumImage/aws:URL" />
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select="aws:MediumImage/aws:Width" />
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="aws:MediumImage/aws:Height" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="aws:ItemAttributes/aws:Title" />
</xsl:attribute>
<xsl:attribute name="style">float:right;</xsl:attribute>
<xsl:attribute name="border">0</xsl:attribute>
</xsl:element>
</textarea>
<p>(2)画像をfloatで右側に移動(リンクなし)※別途CSS表記</p>
<textarea cols="100" rows="3">
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="aws:MediumImage/aws:URL" />
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select="aws:MediumImage/aws:Width" />
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="aws:MediumImage/aws:Height" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="aws:ItemAttributes/aws:Title" />
</xsl:attribute>
<xsl:attribute name="class">floright</xsl:attribute>
<xsl:attribute name="border">0</xsl:attribute>
</xsl:element>
</textarea>
<p>florightのスタイルシート※CSSファイルに記入してください</p>
<textarea cols="50" rows="2">.floright { float: right; }</textarea>
</xsl:template>
<xsl:template match="aws:MediumImage">
<p>
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="aws:URL" />
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select="aws:Width" />
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="aws:Height" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="../aws:ItemAttributes/aws:Title" />
</xsl:attribute>
</xsl:element>
</p>
</xsl:template>
</xsl:stylesheet>
「XSLTスタイルシート」を理解するのは、
それほど難しくない。
プログラミングというものではなく、
法則の理解だけで通用します。
そして、アマゾンウェブサービスの使い方も、
思っていたほど難しくはなかった。
次回からは、もう少し違った形にチャレンジします。
参考にさせて頂いたのは、
ありがとうございます。
<< コールドストーンクリーマリー(Cold Stone Creamery)に行ってきた。
PHPのDOMとXSL関数でアマゾンAPIのXMLを処理 >>
[ 起業日記のホームへ ]
仕事の成果や興味を持って体験したこと、また今学んでいることで自分なりにまとめられるようになったことなど、とにかくアウトプットを中心として書いていくブログです。
「1日16時間 起業日記」の意味は、WEBの世界で起業した管理人が、京セラの稲盛和夫さん、HONDAの本田宗一郎さんのように、年間5,000時間以上を数十年と働き続けた名経営者達に憧れて、せめて時間だけでも同じことをしよう!という意気込みを表現しています。
コメント