<?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/2005-07-26">
<xsl:output method="text" media-type="text/javascript" encoding="UTF-8"/>
	<xsl:param name="Total" select="aws:ItemSearchResponse/aws:Items/aws:TotalResults" />
	<xsl:param name="keyword" select="aws:ItemSearchResponse/aws:OperationRequest/aws:Arguments/aws:Argument[contains(@Name,'Keywords')]/@Value"/>
	<xsl:param name="mode" select="aws:ItemSearchResponse/aws:OperationRequest/aws:Arguments/aws:Argument[@Name='SearchIndex']/@Value"/>
	<xsl:param name="offset" select="aws:ItemSearchResponse/aws:OperationRequest/aws:Arguments/aws:Argument[@Name='ItemPage']/@Value"/>
	<xsl:param name="t" select="aws:ItemSearchResponse/aws:OperationRequest/aws:Arguments/aws:Argument[@Name = 'AssociateTag']/@Value" />
<xsl:template match="/">
<xsl:variable name="query">
<xsl:value-of select="$mode"/>_<xsl:value-of select="$keyword"/>_<xsl:value-of select="$offset"/>
</xsl:variable>
AWS3["<xsl:value-of select="$query"/>"] = {
 total : <xsl:choose>
  <xsl:when test="$Total != ''"><xsl:value-of select="$Total"/></xsl:when>
  <xsl:otherwise>0</xsl:otherwise>
 </xsl:choose>
 ,asid : "<xsl:value-of select="$t"/>"
 ,items:[
	<xsl:apply-templates select="aws:ItemSearchResponse/aws:Items/aws:Item"/>
	"end"
 ]
};
if(AWS3["<xsl:value-of select="$query"/>_onload"]){
 AWS3["<xsl:value-of select="$query"/>_onload"](AWS3["<xsl:value-of select="$query"/>"])
}
</xsl:template>
<!-- 商品検索結果の生成 -->
<xsl:template match="aws:Item">
{
  asin  : "<xsl:value-of select="aws:ASIN"/>"
 ,title : "<xsl:value-of select="translate(aws:ItemAttributes/aws:Title,'&quot;&#x0A;','” ')"/>"
<!-- ,ImageUrl   : "<xsl:value-of select="ImageUrlMedium"/>"-->

<!-- 著者 -->
,creator: <xsl:choose>
		<xsl:when test="aws:ItemAttributes/aws:Author">
		["<xsl:value-of select="aws:ItemAttributes/aws:Author"/>"]
		</xsl:when>
		<xsl:otherwise>
			[]
		</xsl:otherwise>
	</xsl:choose>

<!-- 製造業者 -->
<xsl:choose>
	<xsl:when test="aws:ItemAttributes/aws:Manufacturer">
	,Manufacturer: "<xsl:value-of select="aws:ItemAttributes/aws:Manufacturer"/>"
	</xsl:when>
	<xsl:otherwise></xsl:otherwise>
</xsl:choose>

<!-- 価格情報 -->
<xsl:call-template name="OurPrice">
	<xsl:with-param name="OurPrice" select="substring(OurPrice, 2)"/>
	<xsl:with-param name="ListPrice" select="substring(ListPrice, 2)"/>
	<xsl:with-param name="UsedPrice" select="substring(UsedPrice, 2)"/>
</xsl:call-template>

<!-- 発売日 -->
	<xsl:choose>
	<xsl:when test="aws:ItemAttributes/aws:PublicationDate">
	,pubDate : "<xsl:value-of select="aws:ItemAttributes/aws:PublicationDate"/>"
	</xsl:when>
	<xsl:otherwise>
	</xsl:otherwise>
</xsl:choose>

<!-- 売り上げランクがあれば表示 -->
<xsl:choose>
	<xsl:when test="aws:SalesRank">
	,rank:<xsl:value-of select="translate(aws:SalesRank/text(),',','')"/>
	</xsl:when>
	<xsl:otherwise></xsl:otherwise>
</xsl:choose>

<!-- ゲーム機種、メディア -->
<xsl:choose>
	<xsl:when test="aws:ItemAttributes/aws:Binding">
	,Media : "<xsl:value-of select="aws:ItemAttributes/aws:Binding"/>"
	</xsl:when>
	<xsl:otherwise></xsl:otherwise>
</xsl:choose>

<!-- 在庫状況 -->
<xsl:choose>
	<xsl:when test="Availability = 'このページは在庫状況に応じて更新されますので、購入をお考えの方は定期的にご覧ください。'">
		,isExist : false
	</xsl:when>
	<xsl:otherwise>
		,isExist : true
		,stat: "<xsl:value-of select="Availability"/>"
	</xsl:otherwise>
</xsl:choose>

<!-- アダルトフラグ -->
<xsl:if test="Features/Feature = 'アダルト'">
	,isAdult : true
</xsl:if>

<!-- 評価 -->
<xsl:if test="Reviews/AvgCustomerRating">
	,rate : <xsl:value-of select="Reviews/AvgCustomerRating/text()" />
</xsl:if>

<!-- レビュー -->
,reviews:[<xsl:apply-templates select="Reviews"/>]
},
</xsl:template>
<!-- /商品検索結果の生成 -->



<!-- 価格情報の生成 -->
<xsl:template name="OurPrice">
	<xsl:param name="OurPrice"  select="'1.00'"/>
	<xsl:param name="ListPrice" select="'1.00'"/>
	<xsl:param name="UsedPrice"/>
	<xsl:choose>
		<xsl:when test="$OurPrice != ''">
		,OurPrice:<xsl:value-of select="translate($OurPrice,',','')"/>
		</xsl:when>
		<xsl:otherwise>
		</xsl:otherwise>
	</xsl:choose>
	<!-- 定価があれば -->
	<xsl:choose>
		<xsl:when test="$ListPrice != ''">
		,ListPrice:<xsl:value-of select="translate($ListPrice,',','')"/>
		</xsl:when>
		<xsl:otherwise>
		</xsl:otherwise>
	</xsl:choose>

	<!-- 中古があれば -->
	<xsl:if test="$UsedPrice">
		,UsedPrice:<xsl:value-of select="translate($UsedPrice,',','')"/>
	</xsl:if>
</xsl:template>



<!-- 輸入品表示 -->
<xsl:template match="Features">
	<xsl:for-each select="Feature">
		<xsl:choose>
		<xsl:when test="text() = 'from US'">
		,fromUS: true
		</xsl:when>
		<xsl:when test="text() = 'from UK'">
		,fromUK: true
		</xsl:when>
		<xsl:when test="text() = 'Import'">
		,Import: true
		</xsl:when>
		</xsl:choose>
	</xsl:for-each>
</xsl:template>



<!-- 出演タレント、著者表示 -->
<xsl:template match="Starring | Authors">
	<xsl:for-each select="Actor | Author">
		<xsl:choose>
			<xsl:when test="not(position() = last())">
				"<xsl:value-of select="."/>"<xsl:text>,</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				"<xsl:value-of select="."/>"
			</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each>
	<xsl:if test="Actor">
	</xsl:if>
</xsl:template>

<!-- レビュータイトルの表示 -->
<xsl:template match="Reviews">
<xsl:for-each select="CustomerReview">
 {description:"<xsl:value-of select="Summary"/>",rate:<xsl:value-of select="Rating"/>
  ,comment : "<xsl:value-of select="translate(Comment,'&quot;','”')"/>"
 }<xsl:choose>
	<xsl:when test="not(position() = last())">,</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
