<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="text" media-type="text/javascript" encoding="UTF-8" />
	<xsl:template match="/" >
		resultBookValues = InitBookValues ;
		<xsl:choose>
			<xsl:when test="ProductInfo/Details[.!='']">
				<xsl:apply-templates select="ProductInfo/Details" />
				if ( resultBookValues["ListPrice"] != "" ) {
					resultBookValues["_PriceString_"] = resultBookValues["ListPrice"] ;
				}
				else {
					resultBookValues["_PriceString_"] = "OPEN" ;
					if ( resultBookValues["OurPrice"] != "" ) {
						resultBookValues["_PriceString_"] += "(Amazon:" + resultBookValues["OurPrice"] + ")" ;
					}
					else if ( resultBookValues["UsedPrice"] != "" ) {
						resultBookValues["_PriceString_"] += "(Used:" + resultBookValues["UsedPrice"] + ")" ;
					}
				}
				rcGetBookData = "OK" ;
			</xsl:when>
			<xsl:otherwise>
				rcGetBookData = 'NoResult' ;
			</xsl:otherwise>
		</xsl:choose>
		callBackAwsXls() ;
	</xsl:template>
	<xsl:template match="Details">
		resultBookValues["url"] = "<xsl:value-of select="@url" />" ;
		<xsl:for-each select="./*">
			<xsl:choose>
				<xsl:when test="name(.)='Authors'">
					<xsl:apply-templates select="." />
				</xsl:when>
				<xsl:when test="name(.)='Artists'">
					<xsl:apply-templates select="." />
				</xsl:when>
				<xsl:when test="name(.)='Tracks'">
					<xsl:apply-templates select="." />
				</xsl:when>
				<xsl:when test="count(child::*)=0">
					if ( resultBookValues["<xsl:value-of select="name(.)" />"] == "" ) {
						resultBookValues["<xsl:value-of select="name(.)" />"] = "<xsl:value-of select="." />" ;
					}
				</xsl:when>
				<xsl:otherwise>
					/* Ignored	*/
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="Authors">
		if ( resultBookValues["Authors"] == "" ) {
			resultBookValues["Authors"] = "<xsl:for-each select="./Author"><xsl:value-of select="." /><xsl:if test="not(position() = last())">,&#x20;</xsl:if></xsl:for-each>" ;
		}
	</xsl:template>
	<xsl:template match="Artists">
		if ( resultBookValues["Artists"] == "" ) {
			resultBookValues["Artists"] = "<xsl:for-each select="./Artist"><xsl:value-of select="." /><xsl:if test="not(position() = last())">,&#x20;</xsl:if></xsl:for-each>" ;
		}
	</xsl:template>
	<xsl:template match="Tracks">
		if ( resultBookValues["Tracks"] == "" ) {
			resultBookValues["Tracks"] = "<xsl:for-each select="./Track"><xsl:number value="position()" format="1." />&#x26;nbsp;<xsl:value-of select="." /><xsl:if test="not(position() = last())">&#x3c;br /&#x3e;</xsl:if></xsl:for-each>" ;
		}
	</xsl:template>
</xsl:stylesheet>

