XSLT - display child elements located in different XML files

kumar

New Member
I have the following \[code\]movies.xml\[/code\] file that stores movie titles and Amazon API ItemId for dvd and bluray:\[code\]<moviesxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="movies.xsd"><movie movieID="1"> <title>The Dark Knight</title> <amazon> <dvd>B004Q9SZGC</dvd> <bluray>B004Q9T6CO</bluray> </amazon></movie><movie movieID="2"> <title>Lawless</title> <amazon> <dvd>B008OPZ83C</dvd> <bluray>B008OPZD8C</bluray> </amazon></movie></movies>\[/code\]\[code\]movies_list.xsl\[/code\] displays movie titles as hyperlinkes that take the user to the \[code\]movie_details\[/code\] page where they can seethe movie title they have clicked on AND its corresponding Amazon dvd and bluray product information:movies_list.xsl\[code\]<xsl:template match="/"> <xsl:element name="html"> <xsl:element name="head"> <xsl:element name="h2">Movies list</xsl:element> </xsl:element> <xsl:element name="body"> <xsl:apply-templates select="movies/movie"/> </xsl:element> </xsl:element></xsl:template><xsl:template match="movie"> <xsl:element name="a"> <xsl:attribute name="href">movie_details.php?movieID=<xsl:value-of select="@movieID"/></xsl:attribute> <xsl:value-of select="title"/> </xsl:element> <xsl:element name="br" /></xsl:template> \[/code\]\[code\]movie_details.php\[/code\] looks up and displays movie information (dvd and bluray) from Amazon API XML:\[code\]$movies = file_get_contents('movies.xml');$xml = new SimpleXmlElement($movies);$dvd = $xml->movie->amazon->dvd;$bluray = $xml->movie->amazon->bluray;$request = aws_signed_request('co.uk', array( 'Operation' => 'ItemLookup', 'ItemId' => $dvd.', '.$bluray, 'ResponseGroup' => 'Medium, Offers', 'MerchantId' => 'All'), $public_key, $private_key, $associate_tag); $response = @file_get_contents($request);$xml2 = new DOMDocument();$xml2->loadXML($response);$xsl = new DOMDocument;$xsl->load('movie_details.xsl');$proc = new XSLTProcessor();$proc->importStyleSheet($xsl);$params = $_GET['movieID'];$proc->setParameter('', 'movieID', $params);echo $proc->transformToXML($xml2);\[/code\]Instead of hardcoding the actual ItemId values into the array, I have created $dvd and $bluray variablesthat look up ItemId for dvd and bluray stored in the local \[code\]movies.xml\[/code\] file.This is my \[code\]movie_details.xsl\[/code\] file that displays all the movie details information: title (from movies.xml) and Amazon DVD and Bluray pictures (from Amazon API):\[code\]<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2011-08-01"exclude-result-prefixes="aws"><xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/><xsl:variable name="moviesXML" select="document('movies.xml')"/><xsl:param name="movieID"/><xsl:template match="/"> <xsl:element name="html"> <xsl:element name="head"> <title>Movie details</title> </xsl:element> <xsl:element name="body"> <xsl:apply-templates select="$moviesXML/movies/movie[@movieID=$movieID]" /> </xsl:element> </xsl:element></xsl:template><xsl:template match="movie"> <xsl:value-of select="title"/> <xsl:element name="br" /> <xsl:apply-templates select="../aws:ItemLookupResponse/aws:Items/aws:Item/aws:MediumImage/aws:URL"/></xsl:template><xsl:template match="aws:URL"> <xsl:element name="img"> <xsl:attribute name="src"> <xsl:value-of select="." /> </xsl:attribute> </xsl:element> <xsl:element name="br" /></xsl:template></xsl:stylesheet>\[/code\]Based on the movie title that the user has clicked on in the \[code\]movies_list\[/code\] page, it should take him to the \[code\]movie_details\[/code\] pagethat will display that specific movie title and its corresponding Amazon dvd and bluray URL (link to the product cover picture) which in turn will be displayed as a picture.I do get the movie title displayed on the \[code\]movie_details\[/code\] page based on the movie title the user has clicked on in the \[code\]movies_list\[/code\] page.However, I am not sure where do I need to put: \[code\]<xsl:apply-templates select="../aws:ItemLookupResponse/aws:Items/aws:Item/aws:MediumImage/aws:URL"/>\[/code\]To also display that movie's Amazon DVD and bluray product information.The end result that I want to achieve:
O7soOet.png
Movie ID 2 should work the same way except it will display Lawless movie information instead of the Dark Knight.
 
Back
Top