Using REST to do an ItemSearch Amazon ASIN query and transform the resulting XML into HTML.
Prerequisites:
Here is the query (substitute the bracketed phrases with your own ids)
<?php
require_once('includes/MM_XSLTransform/MM_XSLTransform.class.php');
$restquery = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService
&AWSAccessKeyId=[your access key]&Operation=ItemLookup&ResponseGroup=
Medium&AssociateTag=[your associate id]&ItemId=" . $asin;
$mm_xsl = new MM_XSLTransform();
$mm_xsl->setXML($restquery);
$mm_xsl->setXSL("aws1.xsl");
?>
You can pass the ASIN as a URL parameter or pull it from a database. Next I run the transform. The if condition displays a back button if the user is coming from a page in my domain
<?php
echo $mm_xsl->Transform();
if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], "arcster.com")) {
echo "<p><a href=\"" . $_SERVER['HTTP_REFERER'] . "\">Back</a></p>";
}
?>
Here's what the xsl file looks like. Thanks to KTS on stackoverflow who provided some much needed help with my transform
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml"
xmlns:tns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:a="http://webservices.amazon.com/AWSECommerceService/2005-10-05">
<xsl:output method="html"/>
<xsl:template match="/">
<table border="0">
<tr>
<td>
<h2>arcster.com - results from amazon.com</h2>
</td>
</tr>
<tr>
<td valign="top">
<xsl:apply-templates select="a:ItemLookupResponse/a:Items"/>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="a:Items">
<table border="0">
<xsl:apply-templates select="a:Item"/>
</table>
</xsl:template>
<xsl:template match="a:Item">
<tr>
<td>
<img>
<xsl:attribute name="src">
<xsl:value-of select="a:SmallImage/a:URL" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="a:ItemAttributes/a:Title" />
</xsl:attribute>
<xsl:attribute name="align">left</xsl:attribute>
</img>
<a>
<xsl:attribute name="href">
<xsl:value-of select="a:DetailPageURL" />
</xsl:attribute>
<xsl:value-of select="a:ItemAttributes/a:Title" />
</a>
<br/>
</td>
</tr>
<tr>
<td>
Price: <xsl:value-of select="a:ItemAttributes/a:ListPrice/a:FormattedPrice" /><br />
<xsl:if test="a:ItemAttributes/a:Artist">
Artist: <xsl:value-of select="a:ItemAttributes/a:Artist" />
</xsl:if>
<xsl:if test="a:ItemAttributes/a:Author">
Author: <xsl:value-of select="a:ItemAttributes/a:Author" />
</xsl:if>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
If you see a box of pine
With a name that looks like mine
Just say I drowned in a barrel of wine
When I got to the border
- Richard Thompson