CaRP: Caching RSS Parser - Manual
     Version 3.5.4 (10/7/2004)

NOTE: This version of CaRP is obsolete. This documentation is being left here for those who have not yet upgraded to the current version.

Download | Installation | Configuration | Upgrading from version 2 | Functions | Examples | Donations

Old documentation: Version 2

Examples:
Styles & Classes | Multiple Feeds on a Page | Unordered List | Background Refreshing | Filtering | Aggregating 1 | Aggregating 2 | Amazon.com Associates | JavaScript

Amazon.com associates, use this code to easy display best sellers based on whatever search terms you want The results are cached and refreshed every 12 hours, speeding the performance of your website. Once you've finished the main setup, adding custom best seller lists all over your website will be a snap!

First, copy the two XSL templates from below and save them on your web server with the filenames indicated. NOTE: The XSL templates have been improved from their original form. If you downloaded them previously, you may want to check to be sure you have the latest templates.

Second, copy the following code and save it in a file named "amazonnewsfeed.php" in the same directory as carp.php, after changing:

  • the URLs in the $xsllist array to point to the XSL templates saved in the previous step.
  • put_your_developer_token_here to your Amazon developer token.
  • put_your_associates_id_here to your Amazon associates ID.
If you do not have a web services developer token or associates ID, sign up for them at Amazon.com.

<?php
$xsllist=array(
	1=>'http://www.yourdomain.com/xsl/Amazon2RSS20.1.xsl',
	2=>'http://www.yourdomain.com/xsl/Amazon2RSS20.xsl'
);
$devt='put_your_developer_token_here';
$busid='put_your_associates_id_here';

if (!($mi+=0)) $mi=5;
if (!($rc+=0)) $rc=1;
$q=urlencode($q);
if (!isset($cat)) $cat='books';

require_once dirname(__FILE__).'/carp.php';
CarpConf('corder','');
CarpConf('iorder','image,link,author,desc');
CarpConf('cacheinterval',720);
CarpConf('maxitems',$mi);
CarpConf('linktarget',1);
CarpConf('aidesc','');
CarpConf('ai','<br clear="all">&nbsp;<br>');
CarpConf('biimage','<div style="float:left;margin-right:5px;">');
CarpConf('aiimage','</div>');
$query="http://xml.amazon.com/onca/xml3?t=$busid&dev-t=$devt&KeywordSearch=$q&mode=$cat&sort=+salesrank&offer=All&type=heavy&page=1&f=".$xsllist[$rc];
$cachefile="amazon.".md5($query).".rss";
CarpCache($query,$cachefile);
CarpShow(CarpCachePath().$cachefile);
?>

Third, find an Amazon.com logo you like and upload a copy of it to your website.

Finally, copy the following code (which will be a template for adding Amazon links to your web pages) and save it on your computer, changing:
  • the URL of the image to point to the one uploaded to your site in the previous step.
  • the associates ID in the image link (where it says "tag=moulc") to your ID.
  • the path to amazonnewsfeed.php (the file created in the second step).
<div style="width:200;height:420px;overflow:auto;margin:5px;padding:5px;background:#cccccc;">
<span style="color:#003366;font-size:16pt;font-weight:bold;">Best sellers from</span><br>
<a href="http://www.amazon.com/exec/obidos/redirect?tag=moulc&path=subst/home/home.html"><img src="http://www.yourwebsite.com/img/126X32-w-logo.gif" border="0"></a><br>
<?php
$q='web design';
$cat='books';
$mi=5;
$rc=1;
include '/path/to/amazonnewsfeed.php';
?>
</div>

You've completed the main setup. Now you can add Amazon links to any page by pasting a copy of the code saved in the last step above into your web page with the following changes as needed:

  • the value of $q to the search terms you wish to use.
  • the value of $mi to the maximum number of items you wish to display.
  • the value of $rc to 2 if you wish to display as many customer reviews as Amazon gives you in response to the search query (generally 3, if that many are available). The default setting of $rc=1 displays only one review.
  • the value of $cat to the appropriate value for whatever product category you wish to search for, if not books.
  • the styles of the div and span to look the way you want them to (If you don't want everything displayed in a scrolling box, remove the opening and closing div tags completely).

That's it! Depending on whether you are using the free or commercial version of CaRP, something like the examples to the right will appear on your web page.

XSL templates:

Amazon2RSS20.1.xsl

<?xml version="1.0" encoding="UTF-8"?>
<!--Raymond Yee (yee@uclink.berkeley.edu) , Interactive University, University of California, Berkeley 2002-07-26 -->
<!--Adapted for Amazon heavy output and RSS 2.0 by Antone Roundy -->
<!-- 
Raymond Yee  yee@uclink.berkeley.edu   Interactive University Project Amazon Lite to RSS 0.92 XSLT

Copyright (c) 2002 The Regents of the University of California
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this XSLT
style sheet for any purpose, provided that the above copyright notice
and the following two paragraphs appear in all copies of this
document.

IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS DOCUMENT TYPE DEFINITION, EVEN IF THE
UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE COMPUTER
FILE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.  
-->
<!--&nbsp; trick from http://www.mycgiserver.com/~~lisali/papers/paper.htm -->
<!DOCTYPE stylesheet [
	<!ENTITY nbsp "<xsl:text disable-output-escaping=&#34;yes&#34; 
    xmlns:xsl= &#34;http://www.w3.org/1999/XSL/Transform &#34;
    >&amp;nbsp;</xsl:text>">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output encoding="UTF-8" method="xml" media-type="text/xml"/>
<xsl:template match="ProductInfo">
<rss version="2.0">
<channel>
	<title>Amazon Search Results</title>
	<link>http://www.amazon.com/</link>
	<description>Amazon Search Results</description>
	<xsl:apply-templates select="Details"/>
</channel>
</rss>
</xsl:template>
<xsl:template match="Details">
<item>
<title><xsl:value-of select="ProductName"/></title>
<link><xsl:call-template name="removeurlparams">
	<xsl:with-param name="text" select="normalize-space(@url)"/>
</xsl:call-template></link>
<author><xsl:for-each select="Authors/Author">
	<xsl:apply-templates/>
	<xsl:if test="not(position()=last())">, </xsl:if>
</xsl:for-each></author>
<description>
	&lt;b&gt;Amazon Price:&lt;/b&gt; <xsl:value-of select="OurPrice"/>
	<xsl:apply-templates select="Reviews/CustomerReview[1]"/>
</description>
<!-- length="1000" is not accurate, but what can we do? we don't know the size of the file -->
<xsl:choose>
	<xsl:when test="contains(ImageUrlSmall,'.gif')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/gif" /></xsl:when>
	<xsl:when test="contains(ImageUrlSmall,'.jpeg') or contains(ImageUrlSmall,'.jpg')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/jpeg" /></xsl:when>
	<xsl:when test="contains(ImageUrlSmall,'.png')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/png" /></xsl:when>
</xsl:choose>
</item>
</xsl:template>
<xsl:template match="Reviews/CustomerReview">
	&lt;br/&gt;
	&lt;b&gt;Customer Review:&lt;/b&gt; <xsl:value-of select="substring(Comment,1,300)"/><xsl:if test="string-length(Comment)>300">...</xsl:if>
</xsl:template>
<xsl:template name="removeurlparams">
<xsl:param name="text"/>
<xsl:choose>
	<xsl:when test="contains($text,'?')"><xsl:value-of select="substring-before($text,'?')"/></xsl:when>
	<xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

Amazon2RSS20.xsl

<?xml version="1.0" encoding="UTF-8"?>
<!--Raymond Yee (yee@uclink.berkeley.edu) , Interactive University, University of California, Berkeley 2002-07-26 -->
<!--Adapted for Amazon heavy output and RSS 2.0 by Antone Roundy -->
<!-- 
Raymond Yee  yee@uclink.berkeley.edu   Interactive University Project Amazon Lite to RSS 0.92 XSLT

Copyright (c) 2002 The Regents of the University of California
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this XSLT
style sheet for any purpose, provided that the above copyright notice
and the following two paragraphs appear in all copies of this
document.

IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS DOCUMENT TYPE DEFINITION, EVEN IF THE
UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE COMPUTER
FILE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.  
-->
<!--&nbsp; trick from http://www.mycgiserver.com/~~lisali/papers/paper.htm -->
<!DOCTYPE stylesheet [
	<!ENTITY nbsp "<xsl:text disable-output-escaping=&#34;yes&#34; 
    xmlns:xsl= &#34;http://www.w3.org/1999/XSL/Transform &#34;
    >&amp;nbsp;</xsl:text>">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output encoding="UTF-8" method="xml" media-type="text/xml"/>
<xsl:template match="ProductInfo">
<rss version="2.0">
<channel>
	<title>Amazon Search Results</title>
	<link>http://www.amazon.com/</link>
	<description>Amazon Search Results</description>
	<xsl:apply-templates select="Details"/>
</channel>
</rss>
</xsl:template>
<xsl:template match="Details">
<item>
<title><xsl:value-of select="ProductName"/></title>
<link><xsl:call-template name="removeurlparams">
	<xsl:with-param name="text" select="normalize-space(@url)"/>
</xsl:call-template></link>
<author><xsl:for-each select="Authors/Author">
	<xsl:apply-templates/>
	<xsl:if test="not(position()=last())">, </xsl:if>
</xsl:for-each></author>
<description>
	&lt;b&gt;Amazon Price:&lt;/b&gt; <xsl:value-of select="OurPrice"/>&lt;br /&gt;
	&lt;b&gt;Customer Reviews:&lt;/b&gt;
	<xsl:apply-templates select="Reviews/CustomerReview"/>
</description>
<!-- length="1000" is not accurate, but what can we do? we don't know the size of the file -->
<xsl:choose>
	<xsl:when test="contains(ImageUrlSmall,'.gif')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/gif" /></xsl:when>
	<xsl:when test="contains(ImageUrlSmall,'.jpeg') or contains(ImageUrlSmall,'.jpg')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/jpeg" /></xsl:when>
	<xsl:when test="contains(ImageUrlSmall,'.png')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/png" /></xsl:when>
</xsl:choose>
</item>
</xsl:template>
<xsl:template match="Reviews/CustomerReview">
	&lt;br/&gt;&amp;raquo; <xsl:value-of select="substring(Comment,1,200)"/><xsl:if test="string-length(Comment)>200">...</xsl:if>
	<xsl:if test="not(position()=last())">&lt;br /&gt;</xsl:if>
</xsl:template>
<xsl:template name="removeurlparams">
<xsl:param name="text"/>
<xsl:choose>
	<xsl:when test="contains($text,'?')"><xsl:value-of select="substring-before($text,'?')"/></xsl:when>
	<xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Depending on whether you are using the free or commercial version of CaRP, the output will look similar to the following:

CaRP commercial version:

Best sellers from


[CaRP] Can't open remote newsfeed [410].

[CaRP] Failed to open file: /www/templates/global/carp/autocache/ad3bd037992eeca6323ae415c06e0f65

[CaRP] Can't open remote newsfeed [-1].

CaRP free version:

Best sellers from


[CaRP] Can't open remote newsfeed [410].

[CaRP] Failed to open file: /www/templates/global/carp/autocache/09740e9bd6d45e836bcaa945c95ebe07

[CaRP] Can't open remote newsfeed [-1].