topical media & game development

talk show tell print

mashup-amazon-09-09-01-MovieMogul-AmazonYouTube.xsl / xsl



  <?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="/">
      <xsl:apply-templates select="a:ItemLookupResponse"/>
      <xsl:apply-templates select="a:ItemSearchResponse"/>
      <table>
        <xsl:apply-templates select="ut_response"/>
      </table>    
      </xsl:template>
  
    <xsl:template match="ut_response">
      <tr><td colspan="2"><h2>Related results from YouTube</h2></td></tr>
      <xsl:apply-templates select="video_list/video"/>
    </xsl:template>  
    
    <xsl:template match="a:ItemLookupResponse|a:ItemSearchResponse">
      <h2>Related results from Amazon</h2>
      <xsl:apply-templates select="a:Items"/>
    </xsl:template>
  
    <xsl:template match="a:Items">    
      <xsl:apply-templates select="a:Request/a:Errors/a:Error"/>
      <xsl:apply-templates select="a:Item"/>
    </xsl:template>
  
    <xsl:template match="a:Error">
      <div class="errors">Errors from Amazon</div>
      <xsl:value-of select="a:Message"/>
    </xsl:template>
  
    <xsl:template match="a:Item">
      <img align="left">
        <xsl:choose>
          <xsl:when test="a:MediumImage/a:URL">
            <xsl:attribute name="src">
              <xsl:value-of select="a:MediumImage/a:URL" />
            </xsl:attribute>
            <xsl:attribute name="width">
              <xsl:value-of select="a:MediumImage/a:Width" />
            </xsl:attribute>
            <xsl:attribute name="height">
              <xsl:value-of select="a:MediumImage/a:Height" />
            </xsl:attribute>
          </xsl:when>
          <xsl:otherwise>
            <!-- there are no small image, time to search -->
            <xsl:attribute name="src">images/noimage.gif</xsl:attribute>
          </xsl:otherwise>
        </xsl:choose>
      </img>
      <a>
        <xsl:attribute name="href">
          <xsl:value-of select="a:DetailPageURL" />
        </xsl:attribute>
        <xsl:value-of select="a:ItemAttributes/a:Title" />
      </a>
      <br/>
      <xsl:apply-templates select="a:OfferSummary"/>
      <xsl:apply-templates select="a:CustomerReviews/a:AverageRating"/>
      <b>SalesRank: </b>
      <xsl:value-of select="a:SalesRank" />
      <br/>
      <xsl:apply-templates select="a:ItemAttributes"/>
      <xsl:apply-templates select="a:EditorialReviews/a:EditorialReview"/>
      <br/>
      <xsl:apply-templates select="a:BrowseNodes"/>
      <br/>
    </xsl:template>
  
    <xsl:template match="a:BrowseNodes">
      <xsl:apply-templates select="a:BrowseNode"/>
    </xsl:template>
  
    <xsl:template match="a:BrowseNode" name="myBranch">
      <xsl:choose>
        <xsl:when test="a:Ancestors/a:BrowseNode">
          <xsl:for-each select="a:Ancestors/a:BrowseNode">
            <xsl:call-template name="myBranch" />
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <br/>
        </xsl:otherwise>
      </xsl:choose>
      &gt;&gt; <xsl:value-of select="a:Name" />
    </xsl:template>
  
    <xsl:template match="a:OfferSummary">
      <b>Lowest Price: </b>
      <xsl:value-of select="a:LowestNewPrice/a:FormattedPrice" />
      <br/>
      <b>Total New: </b>
      <xsl:value-of select="a:TotalNew" />
      <br/>
      <b>Total Used: </b>
      <xsl:value-of select="a:TotalUsed" />
    </xsl:template>
  
    <xsl:template match="a:ItemAttributes">
      <b>List Price: </b>
      <span class="c">
        <xsl:value-of select="a:ListPrice/a:FormattedPrice" />
      </span>
      <br/>
      <b>Product Group: </b>
      <xsl:value-of select="a:ProductGroup" />
      <br/>
      <xsl:apply-templates select="a:UPC"/>
      <xsl:apply-templates select="a:Binding"/>
      <xsl:apply-templates select="a:Feature"/>
      <xsl:apply-templates select="a:Director"/>
      <xsl:apply-templates select="a:Actor"/>
      <xsl:apply-templates select="a:Author"/>
      <xsl:apply-templates select="a:Platform"/>
      <xsl:apply-templates select="a:TheatricalReleaseDate"/>
    </xsl:template>
  
    <xsl:template match="a:Binding">
      <xsl:value-of select="."/>
      <br/>
    </xsl:template>
    <xsl:template match="a:Platform">
      <xsl:value-of select="."/>
      <br/>
    </xsl:template>
    <xsl:template match="a:Studio">
      <xsl:value-of select="."/>
      <br/>
    </xsl:template>
    <xsl:template match="a:UPC">
      <b>UPC: </b>
      <xsl:value-of select="."/>
      <br/>
    </xsl:template>
    <xsl:template match="a:Feature">
      <b>* </b>
      <xsl:value-of select="."  disable-output-escaping="yes"/>
      <br/>
    </xsl:template>
    <xsl:template match="a:TheatricalReleaseDate">
      <b>Theatrical Release Date: </b>
      <xsl:value-of select="."/>
      <br/>
    </xsl:template>
    <xsl:template match="a:Director">
      <b>Director: </b>
      <a href="javascript:void(0)">
        <xsl:attribute name="onclick">DirectorSearch('<xsl:value-of select="." />');</xsl:attribute>
        <xsl:value-of select="." />
      </a>
      <br/>
    </xsl:template>
    <xsl:template match="a:Actor">
      <b>Actor: </b>
      <a href="javascript:void(0)">
        <xsl:attribute name="onclick">ActorSearch('<xsl:value-of select="." />');</xsl:attribute>
        <xsl:value-of select="." />
      </a>
      <br/>
    </xsl:template>
  
    <xsl:template match="a:EditorialReviews/a:EditorialReview">
      <b>Editorial Review: </b>
      <xsl:value-of select="a:Source"/>
      <br/>
      <xsl:value-of select="a:Content" disable-output-escaping="yes"/>
      <br/>
      <br/>
    </xsl:template>
    <xsl:template match="a:CustomerReviews/a:AverageRating">
      <br/><b>Average Rating: </b><xsl:value-of select="."/> out of 5<br/>
    </xsl:template>
  
  <!-- YouTube Templates Follow -->
    <xsl:template match="video">
     <tr><td>
          <a target="_blank">
                  <xsl:attribute name="href">
                          <xsl:value-of select="url" />
                  </xsl:attribute>                        
                  <img border="0" width="130" height="97" align="left">
                          <xsl:attribute name="src">
                                  <xsl:value-of select="thumbnail_url" />
                          </xsl:attribute> 
                          <xsl:attribute name="alt"><xsl:value-of select="title" /></xsl:attribute>
                          <xsl:attribute name="title"><xsl:value-of select="title" /></xsl:attribute>
                  </img>
      </a>     
       </td><td>
         <a target="_blank"><xsl:attribute name="href"><xsl:value-of select="url" /></xsl:attribute><xsl:value-of select="title" />
          </a><br/>
     Average Rating: <xsl:value-of select="rating_avg" /> | 
     Length: <xsl:value-of select="length_seconds" /> secs<br/>
           <xsl:value-of select="description" />
       </td>
       </tr>         
     </xsl:template>
  </xsl:stylesheet>


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.