<?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/2007-01-15" exclude-result-prefixes="aws">
	<xsl:template match="aws:ItemSearchResponse/aws:Items">
	{"items": [
		<xsl:apply-templates select="aws:Item"/>
	]}
	</xsl:template>

	<xsl:template match="aws:Items/aws:Item">
		{
			"ASIN": "<xsl:value-of select="aws:ASIN" />",
			"url": "<xsl:value-of select="aws:DetailPageURL" />",
			"title": "<xsl:value-of select="aws:ItemAttributes/aws:Title" />",
			"images": {
				"small": "<xsl:value-of select="aws:SmallImage/aws:URL" />",
				"medium": "<xsl:value-of select="aws:MediumImage/aws:URL" />",
				"large": "<xsl:value-of select="aws:LargeImage/aws:URL" />"
			},
			"credits": [
				<xsl:call-template name="Credits"/>
			]
		}<xsl:if test="not(position() = last())">
			<xsl:text>, </xsl:text>
		</xsl:if>
	</xsl:template>

	<xsl:template name="Credits">
		<xsl:if test="aws:ItemAttributes/aws:Author">
			<xsl:for-each select="aws:ItemAttributes/aws:Author">"<xsl:value-of select="."/>"<xsl:if test="not(position() = last())">,
				</xsl:if>
			</xsl:for-each>
		</xsl:if>
		<xsl:if test="aws:ItemAttributes/aws:Artist">
			<xsl:for-each select="aws:ItemAttributes/aws:Artist">"<xsl:value-of select="."/>"<xsl:if test="not(position() = last())">,
				</xsl:if>
			</xsl:for-each>
		</xsl:if>
		<xsl:if test="aws:ItemAttributes/aws:Director">
			<xsl:for-each select="aws:ItemAttributes/aws:Director">"<xsl:value-of select="."/>"<xsl:if test="not(position() = last())">,
				</xsl:if>
			</xsl:for-each>
		</xsl:if>
		<xsl:if test="aws:ItemAttributes/aws:Composer">
			<xsl:for-each select="aws:ItemAttributes/aws:Composer">"<xsl:value-of select="."/>"<xsl:if test="not(position() = last())">,
				</xsl:if>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>

</xsl:stylesheet>