Generating RSS with XSLT and Amazon ECS
Pages: 1, 2
Building the XSLT File
Next, we'll create an XSLT file that transforms this information into an RSS feed. This XSLT file uses the Wish List name and URL for the RSS feed title and uses information about the products to create separate items in the RSS feed.
<?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/2006-06-07">
<xsl:output method="xml"/>
<xsl:template match="/">
<rss version="2.0">
<channel>
<xsl:apply-templates select="aws:ListLookupResponse/aws:Lists/aws:List" />
</channel>
</rss>
</xsl:template>
<xsl:template match="aws:List">
<title>WishList for <xsl:value-of select="aws:CustomerName" /></title>
<link><xsl:value-of select="aws:ListURL"/></link>
<xsl:apply-templates select="aws:ListItem"/>
</xsl:template>
<xsl:template match="aws:ListItem">
<!--Filter out items that have already been purchased-->
<xsl:if test="aws:QuantityDesired > aws:QuantityReceived">
<item>
<title><xsl:value-of select="aws:Item/aws:ItemAttributes/aws:Title" /></title>
<link><xsl:value-of select="aws:Item/aws:DetailPageURL" /></link>
<description>Lowest New Price:
<xsl:value-of select="aws:Item/aws:OfferSummary/aws:LowestNewPrice/aws:FormattedPrice"/>
</description>
<guid><xsl:value-of select="aws:Item/aws:DetailPageURL" /></guid>
</item>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Amazon ECS requires that we declare a namespace and namespace prefix for processing the web service response. For example, our reference to aws:Item in the XSLT file corresponds to the <Item> element in the XML response. Be sure the version number in the namespace matches the version number in your request to Amazon ECS.
We added a link to the detail page for each product returned. We do this to be in compliance with the Amazon Web Services License Agreement.
Making the XSLT Service Request
We'll need to make a few changes to use the XSLT service with our original Amazon ECS request:
- Add the Style parameter to the request
- Send the request to the special XSLT service endpoint: http://xml-us.amznxslt.com
We also need to store the XSLT file on the web so Amazon ECS can access it. We stored our file using Amazon S3. Here's the request to the XSLT service:
http://xml-us.amznxslt.com/onca/xml?
Service=AWSECommerceService&
Version=2006-06-07&
AWSAccessKeyId=1CE7SK4ZPTNDQZCWBP82&
Operation=ListLookup&
ListType=WishList&
ListId=30BOZ74K6RSKJ&
ResponseGroup=ItemAttributes,ListItems,ListInfo,Offers
Sort=DateAdded&
Style=http://s3.amazonaws.com/amazon_xslt_files/ecs_to_rss-wishlist.xslt
Consuming the RSS Feed
The XSLT service allows you to directly enter your request to Amazon ECS as a URL in your favorite RSS reader. There are a ton of RSS readers available, so just pick one that works best for you. We're using Sage in Firefox, so the feed looks like Figure 1:

Figure 1. Wish List feed
Creating Your Own Feeds
You can customize the example above for your own use. The basic steps are as follows:
- Download the XSLT file under Additional Resources.
- Place the XSLT file in a publicly-accessible place. Using Amazon S3 with a public-read policy works great!
- Update the Wish List ID in the Amazon ECS request with your ID.
You can also add your Associate ID to the Amazon ECS request, which allows you to earn a referral fee for any purchases that originate from your RSS feed. If you don't already have an Associate ID, you can sign up to get one.
You can also use the XSLT service to create any type of output you want. There are just a few things you should keep in mind:
- The XSLT service isn't best for debugging, so a great way to test your XSLT is to save the standard Amazon ECS response as an XML file, then use a local XSLT processor to transform your saved XML file using the XSLT file you're developing.
- Be sure the version number in the XSLT file namespace matches the version number in your request to Amazon ECS.
- Be sure to include a link to the product.
Additional Resources
- Sample XSLT file: ecs_to_rss-wishlist.xslt
- Amazon Web Services
- Amazon E-Commerce Service
- Using XSLT with ECS from the ECS Developer's Guide
- RSS
- XML.com's Transforming XML column
Share your experience in our forums.
(* You must be a member of XML.com to use this feature.)
Comment on this Article
| Titles Only | Titles Only | Newest First |
- XSLT file hosting
2008-10-07 14:11:09 mar1r [Reply]
Does the XSLT file need to be hosted on the Amazon S3 solution? Can't it be hosted on any file server? I uploaded the ecs_to_rss-wishlist.xslt file to my free web server and I can download it without problem. However, putting the new URL in the XSL request only gets back the XML file, not the XML transformed into an RSS feed. Could the problem be that the Amazon XSLT service endpoint only accepts stylesheets hosted on S3? Or do i need to associate the AccessKeyID to my other url in some way?
Thanks
- Isn't an & missing at the end of the line ResponseGroup=... ?
2006-10-21 07:24:43 jeanwall [Reply]
http://xml-us.amznxslt.com/onca/xml?
Service=AWSECommerceService&
Version=2006-06-07&
AWSAccessKeyId=1CE7SK4ZPTNDQZCWBP82&
Operation=ListLookup&
ListType=WishList&
ListId=30BOZ74K6RSKJ&
ResponseGroup=ItemAttributes,ListItems,ListInfo,Offers
Sort=DateAdded&
Style=http://s3.amazonaws.com/amazon_xslt_files/ecs_to_rss-wishlist.xslt
- Cool!
2006-08-30 16:35:37 alastairrankine [Reply]
That is so cool. Some questions:
I'm assuming this engine is XSLT 1.0. Are the EXSLT extensions available? Do you know of XSLT 2.0 plans? (IIRC the W3C's XSLT service supports 2.0)
Is there any particular reason to prefer an <xsl:if> test over a predicate in the template match pattern? eg:
match="aws:ListItem[number(aws:QuantityDesired) > number(aws:QuantityReceived)]"
