<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet  version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:hon="urn:hon"
     xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2007-02-22"
>

  <hon:AmazonAccessKey>0KM461ZPKCYB1JA0MX02</hon:AmazonAccessKey>
  <hon:AmazonAssociateID>www1unetsunej-22</hon:AmazonAssociateID>

  <xsl:output method="xml" encoding="UTF-8" media-type="text/html"/>

  <xsl:variable name="title">hon.jp - RESTサービスの利用例(amazon：ISBN表示)</xsl:variable>

  <xsl:template match="/">
    <html>
      <head>
        <meta http-equiv="Content-type"  content="text/html; charset=UTF-8" ></meta>
        <title><xsl:value-of select="$title"/></title>
        <style type="text/css">
         .header   { background-color:darkkhaki; text-align:right; }
         .footer   { background-color:darkkhaki; text-align:right; }
         .title    { font-size:large; font-weight:bold; }
         .main     { background-color:lightyellow; }
         .item     { background-color:skyblue; margin-top:1em; }
         .results  { background-color:lightblue; margin-top:1em; }
         .number   { text-align:right; }
         .error    { color:red; }
         th        { background-color:mediumturquoise; }
         td th     { background-color:cyan; }
         td        { background-color:aquamarine; }
         td td     { background-color:lightcyan; }
        </style>
      </head>
      <body>
        <xsl:call-template name="header"/>
        <xsl:call-template name="body"/>
        <xsl:call-template name="footer"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="body">
    <div class="main">
      <div class="title"><xsl:value-of select="$title"/></div>
      <xsl:apply-templates />
    </div>
  </xsl:template>

  <xsl:template match="aws:ItemLookupResponse">
      <xsl:call-template name="OperationRequest"/>
      <xsl:call-template name="Items"/>
  </xsl:template>

  <xsl:template name="OperationRequest">
  </xsl:template>

  <xsl:template name="Items">
    <xsl:choose>
      <xsl:when test="aws:Items/aws:Request/aws:IsValid='True'">
        <xsl:choose>
          <xsl:when test="aws:Items/aws:Request/aws:Errors/aws:Error">
            <span class="error">
              <xsl:text>要求エラー：【</xsl:text>
              <xsl:value-of select="aws:Items/aws:Request/aws:Errors/aws:Error/aws:Code"/>
              <xsl:text>】</xsl:text>
              <xsl:value-of select="aws:Items/aws:Request/aws:Errors/aws:Error/aws:Message"/>
            </span>
          </xsl:when>
          <xsl:otherwise>
            <div class="results">
              <xsl:apply-templates select="aws:Items/aws:Request"/>
              <xsl:apply-templates select="aws:Items/aws:Item"/>
            </div>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>要求エラー</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="aws:Request">
  </xsl:template>

  <xsl:template match="aws:Item">
    <div class="item">
      <div>
        <table>
          <tr>
            <th>タイトル</th>
            <td colspan="5"><xsl:value-of select="aws:ItemAttributes/aws:Title"/></td>
            <th rowspan="3">
              <div>
                <a href="{aws:DetailPageURL}">アマゾン<br />詳細表示</a>
              </div>
              <xsl:if test="aws:SmallImage/aws:URL">
                <div>
                  <a href="{aws:DetailPageURL}" title="アマゾン詳細表示">
                    <img src="{aws:SmallImage/aws:URL}"/>
                  </a>
                </div>
              </xsl:if>
            </th>
            <xsl:if test="aws:MediumImage/aws:URL">
              <th rowspan="3">
                <a href="{aws:LargeImage/aws:URL}" title="表紙の大きな写真を表示">
                  <img src="{aws:MediumImage/aws:URL}"/>
                </a>
              </th>
            </xsl:if>
          </tr>
          <tr>
            <th>著者</th>
            <td>
              <xsl:value-of select="aws:ItemAttributes/aws:Creator"/>
              <xsl:value-of select="aws:ItemAttributes/aws:Creator/@Role"/>
            </td>
              <th>発行日</th>
              <td><xsl:value-of select="aws:ItemAttributes/aws:PublicationDate"/></td>
              <th>価格</th>
              <td><xsl:value-of select="aws:ItemAttributes/aws:ListPrice/aws:FormattedPrice"/></td>
          </tr>
          <tr>
              <th>出版社</th>
              <td><xsl:value-of select="aws:ItemAttributes/aws:Publisher"/></td>
            <th>ISBN</th>
            <td>
              <xsl:value-of select="aws:ASIN"/>
            </td>
              <th>ページ数</th>
              <td class="number"><xsl:value-of select="aws:ItemAttributes/aws:NumberOfPages"/></td>
          </tr>
        </table>
      </div>
    </div>
  </xsl:template>

  <xsl:template name="header">
    <div class="header">
      <span>
        <xsl:text>このページは，</xsl:text>
        <a href="http://www.amazon.com/gp/aws/landing.html">Amazon E-Commerceサービス</a>
        <xsl:text>を利用しています。</xsl:text>
      </span>
    </div>
  </xsl:template>

  <xsl:template name="footer">
    <div class="footer">
      <span>
        <xsl:text>このページは，</xsl:text>
        <a href="http://www.amazon.com/gp/aws/landing.html">Amazon E-Commerceサービス</a>
        <xsl:text>を利用しています。</xsl:text>
      </span>
    </div>
  </xsl:template>

</xsl:stylesheet>
