Current File : /home/lifechur/carp-wp/Amazon2RSS-2.0-2011-08-01.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 RSS 2.0, ECS 4.0, made configurable, etc. by Antone Roundy 2005-10-26
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.
trick from http://www.mycgiserver.com/~~lisali/papers/paper.htm
-->
<!DOCTYPE stylesheet [
<!ENTITY nbsp "<xsl:text disable-output-escaping="yes"
xmlns:xsl= "http://www.w3.org/1999/XSL/Transform "
>&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"
xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2011-08-01"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<xsl:output encoding="UTF-8" method="xml" media-type="text/xml"/>
<xsl:template match="aws:ItemSearchResponse">
<xsl:variable name="CaRPMaxReviewLength">
<xsl:choose>
<xsl:when test="aws:OperationRequest/aws:Arguments/aws:Argument[@Name = 'CaRPMaxReviewLength']/@Value">
<xsl:value-of select="aws:OperationRequest/aws:Arguments/aws:Argument[@Name = 'CaRPMaxReviewLength']/@Value" />
</xsl:when>
<xsl:otherwise><xsl:text>250</xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<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="aws:Items/aws:Item">
<xsl:with-param name="CaRPMaxReviewLength" select="$CaRPMaxReviewLength" />
</xsl:apply-templates>
</channel>
</rss>
</xsl:template>
<xsl:template match="aws:Items/aws:Item">
<xsl:param name="CaRPMaxReviewLength" select="''"/>
<item>
<title><xsl:value-of select="aws:ItemAttributes/aws:Title"/></title>
<link><xsl:call-template name="fixurl">
<xsl:with-param name="string" select="aws:DetailPageURL"/></xsl:call-template></link>
<dc:creator><xsl:for-each select="aws:ItemAttributes/aws:Author">
<xsl:apply-templates/>
<xsl:if test="not(position()=last())">, </xsl:if>
</xsl:for-each></dc:creator>
<description>
<b>Amazon Price:</b> <xsl:value-of select="aws:Offers/aws:Offer[1]/aws:OfferListing[1]/aws:Price/aws:FormattedPrice"/>
<xsl:apply-templates select="aws:EditorialReviews/aws:EditorialReview[1]">
<xsl:with-param name="CaRPMaxReviewLength" select="$CaRPMaxReviewLength" />
</xsl:apply-templates>
</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(aws:SmallImage/aws:URL,'.gif')"><enclosure url="{aws:SmallImage/aws:URL}" length="1000" type="image/gif" /></xsl:when>
<xsl:when test="contains(aws:SmallImage/aws:URL,'.jpeg') or contains(aws:SmallImage/aws:URL,'.jpg')"><enclosure url="{aws:SmallImage/aws:URL}" length="1000" type="image/jpeg" /></xsl:when>
<xsl:when test="contains(aws:SmallImage/aws:URL,'.png')"><enclosure url="{aws:SmallImage/aws:URL}" length="1000" type="image/png" /></xsl:when>
</xsl:choose>
</item>
</xsl:template>
<xsl:template match="aws:EditorialReviews/aws:EditorialReview">
<xsl:param name="CaRPMaxReviewLength" select="''"/>
<br/>
<xsl:value-of select="substring(aws:Content,1,$CaRPMaxReviewLength)"/><xsl:if test="string-length(aws:Content)>$CaRPMaxReviewLength">...</xsl:if>
</xsl:template>
<xsl:template name="fixurl">
<xsl:param name="string" select="''"/>
<xsl:choose>
<xsl:when test="contains($string,'%26')">
<xsl:value-of select="substring-before($string,'%26')"/>&<xsl:call-template name="fixurl">
<xsl:with-param name="string" select="substring-after($string,'%26')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>