Amazon E-Commerce Service (ECS) provides an XSLT (Extensible Stylesheet Language Transformation) service to ensure that even novice developers can produce rich content without complex parsing or programming. ECS provides XSLT for XML over HTTP (REST) requests only.
XSL is an XML-based language for transforming XML tags into either HTML or an alternate set of XML tags. To use the ECS XSLT service, you must provide an XSL style sheet with your request and ECS will return data formatted according to that style sheet rather than the ECS default XML tags.
For security reasons, Amazon Web Services use a different set of domains for processing XSLT requests. Requests sent to the standard domains (for example, http://webservices.amazon.com) are re-directed to a different domain. If your Web client does not support re-directs, send XSLT requests directly to one of the following domains:
List of XSLT Service URLs
| Locale | URL |
|---|---|
| US | xml-us.amznxslt.com |
| DE | xml-de.amznxslt.com |
| FR | xml-fr.amznxslt.com |
| CA | xml-ca.amznxslt.com |
| JP | xml-jp.amznxslt.com |
| UK | xml-uk.amznxslt.com |
XSL is an XML-based language for transforming XML tags into either HTML or an alternate set of XML tags. To use the ECS XSLT service, you must provide an XSL style sheet with your request and ECS will return data formatted according to that style sheet rather than the ECS default XML tags.
The Style request parameter allows you to specify the location of your XSLT style sheet. In the example below, the results of the ItemLookup operation are returned with the standard ECS XML tags transformed according to the contents of the XSLT style sheet http://www.yourdomain.com/your-xsl-style-sheet.xsl.
Sample Request with Style Parameter
http://webservices.amazon.com/onca/xml?Service=AWSECommerceService
&AWSAccessKeyId=[Your Access Key ID Here]
&Operation=ItemLookup
&IdType=ASIN
&ItemId=B00008OE6I
&ResponseGroup=Large
&Style=http://www.yourdomain.com/your-xsl-style-sheet.xsl
You must create a namespace prefix at the top of your style sheet. In previous versions of ECS, it was possible to use the default namespace, which meant that you did not need to specify a namespace to access elements in the response. This is no longer the case.
You use the namespace in your XSL stylesheet to access elements in your ECS response. For more information about XML namespaces, we recommend these articles:
Here is a sample style sheet that shows how namespaces are defined and used with ECS responses:
http://webservices.amazon.com/xsl/aws4/item-search.xsl
Setting the Namespace Prefix
In this example, the third line that starts with xmlns defines a namespace prefix and URL for the style sheet. The namespace prefix is aws, and the namespace URL is http://webservices.amazon.com/AWSECommerceService/2004-03-19. In your style sheet, you may name the namespace prefix anything. The namespace URL must match the namespace URL that is returned to you in the ECS response. The namespace URL will typically be in the second line of the ECS response and will look something like the namespace URL in the example above.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2004-03-19">
Using the Namespace Prefix to Match Elements
Once you have created your namespace prefix, use it to match elements in the ECS response. For instance, if you are trying to match an element called ItemLookupResponse, and your prefix is aws, the matching string would be aws:ItemLookupResponse.
Here is an example of how and where the namespace prefix should be used.
<xsl:template match="/">
<xsl:apply-templates select="aws:Items/aws:Item"/>
</xsl:template>
<xsl:template match="aws:Items/aws:Item">
<tr>
<td style="border-bottom:#C0C0C0 dotted 1px;padding:10px">
<table cellpadding="0" cellspacing="0" style="width: 90%;padding:5px">
<tr>
<xsl:if test="aws:SmallImage/aws:URL">
<td valign="top" width="50">
<img>
<xsl:attribute name="src">
<xsl:value-of select="aws:SmallImage/aws:URL" />
</xsl:attribute>
<xsl:attribute name="border">0</xsl:attribute>
</img>
</td>
</xsl:if>
<td valign="top">
<xsl:value-of select="aws:ItemAttributes/aws:Title" />
<br />
<span style="font-size:10px">
<xsl:if test="aws:ItemAttributes/aws:Author">
by <xsl:value-of select="aws:ItemAttributes/aws:Author" />
</xsl:if>
<xsl:if test="aws:ItemAttributes/aws:Artist">
by <xsl:value-of select="aws:ItemAttributes/aws:Artist" />
</xsl:if>
<xsl:if test="aws:ItemAttributes/aws:Director">
by <xsl:value-of select="aws:ItemAttributes/aws:Director" />
</xsl:if>
<xsl:if test="aws:ItemAttributes/aws:Composer">
by <xsl:value-of select="aws:ItemAttributes/aws:Composer" />
</xsl:if>
<xsl:if test="aws:ItemAttributes/aws:Manufacturer">
from <xsl:value-of select="aws:ItemAttributes/aws:Manufacturer" />
</xsl:if>
</span>
<br />
<br />
<span style="font-size:11px;">
List Price: <xsl:value-of
select="aws:ItemAttributes/aws:ListPrice/aws:FormattedPrice" />
</span>
</td>
</tr>
</table>
</td>
</tr>
</xsl:template>