<?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 name="filename">
  <xsl:param name="path"/>
  <xsl:choose>
    <xsl:when test="contains($path, '/')">
      <xsl:call-template name="filename">
        <xsl:with-param name="path" select="substring-after($path, '/')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$path"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="/">
<XMM_Movie_Database>
	<xsl:for-each select="xml/viddb/movie">
		<Movie>
			<MovieID><xsl:value-of select="position()"/></MovieID>
			<Title><xsl:value-of select="title"/></Title>
			<Media>DVD</Media>
			<Genre><xsl:value-of select="genre"/></Genre>
			<Year><xsl:value-of select="year"/></Year>
			<Length><xsl:value-of select="length"/></Length>
			<Plot><xsl:value-of select="description"/></Plot>
			
			
			<Cover>
			<xsl:call-template name="filename">
            <xsl:with-param name="path" select="poster"/>
            </xsl:call-template>
			</Cover>
			
			<PersonalRating><xsl:value-of select="rating"/></PersonalRating>
			<URL><xsl:value-of select="url"/></URL>
			<Purchase></Purchase>
			<Actors>
				<Actor><xsl:value-of select="actors"/></Actor>
			</Actors>
			<Director><xsl:value-of select="director"/></Director>
			<Position></Position>
			<Country><xsl:value-of select="country"/></Country>
		</Movie>
	</xsl:for-each>
</XMM_Movie_Database>
</xsl:template>

</xsl:stylesheet>