<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<XMM_Movie_Database>
	<xsl:for-each select="data/movies/movie">
		<Movie>
			<MovieID><xsl:value-of select="@id"/></MovieID>
			<Title><xsl:value-of select="@title"/></Title>
			<xsl:variable name="format" select="@format"/>
			<Media><xsl:value-of select="/data/formats/format[@id=$format]"/></Media>
			<xsl:variable name="genre" select="genre"/>
			
			<Genre><xsl:value-of select="/data/genres/genre[@id=$genre]"/></Genre>
			<Year><xsl:value-of select="@year"/></Year>
			<Length><xsl:value-of select="@runtime"/></Length>
			<Plot><xsl:value-of select="description"/></Plot>
			<Cover><xsl:value-of select="@id"/>_m.jpg</Cover>
			<PersonalRating><xsl:value-of select="@rating div 10"/></PersonalRating>
			<URL>http://www.imdb.com/title/tt<xsl:value-of select="@imdb"/></URL>
			<Purchase><xsl:value-of select="@added"/></Purchase>
			<Actors>
				<xsl:for-each select="actor">
				<xsl:variable name="actorid" select="@id"/>
				<Actor><xsl:value-of select="/data/actors/actor[@id=$actorid]"/></Actor>
				</xsl:for-each>
			</Actors>
			<xsl:variable name="directorid" select="@director"/>
			<Director><xsl:value-of select="/data/actors/actor[@id=$directorid]"/></Director>
			<Position><xsl:value-of select="@location"/></Position>
			<xsl:variable name="countryid" select="@country"/>
			<Country><xsl:value-of select="/data/countries/country[@id=$countryid]"/></Country>
			<UPC></UPC>
			<xsl:choose>
				<xsl:when test="@rated='0'">
					<Rating>G</Rating>		
				</xsl:when>
				<xsl:when test="@rated='1'">
					<Rating>PG</Rating>		
				</xsl:when>
				<xsl:when test="@rated='2'">
					<Rating>PG-13</Rating>		
				</xsl:when>
				<xsl:when test="@rated='3'">
					<Rating>R</Rating>		
				</xsl:when>
				<xsl:when test="@rated='4'">
					<Rating>NC-17</Rating>		
				</xsl:when>
			</xsl:choose>
		</Movie>
	</xsl:for-each>
</XMM_Movie_Database>
</xsl:template>

</xsl:stylesheet>