<?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="split-actors">
    <xsl:param name="list" /> 
    <xsl:variable name="newlist" select="concat(normalize-space($list),' ')" /> 
    <xsl:variable name="first" select="substring-before($newlist, ' ')" /> 
    <xsl:variable name="tmp" select="substring-after($newlist, ' ')" /> 
    <xsl:variable name="second" select="substring-before($tmp, ' ')" /> 
    <xsl:variable name="remaining" select="substring-after($tmp, ' ')" /> 
    <Actor>
        <xsl:value-of select="$first" /><xsl:text>&#x20;</xsl:text><xsl:value-of select="$second" /> 
    </Actor>
    <xsl:if test="$remaining">
        <xsl:call-template name="split-actors">
                <xsl:with-param name="list" select="$remaining" /> 
        </xsl:call-template>
    </xsl:if>
</xsl:template>

<xsl:template match="/">
<XMM_Movie_Database>
	<xsl:for-each select="library/items/movie">
		<Movie>
			<MovieID><xsl:value-of select="@uuid"/></MovieID>
			<Title><xsl:value-of select="@fullTitle"/></Title>
			<Media><xsl:value-of select="@aspect"/></Media>
			<Genre><xsl:value-of select="@genre"/></Genre>
			<Year><xsl:value-of select="@theatricalDate"/></Year>
			<Length><xsl:value-of select="@minutes"/></Length>
			<PersonalRating><xsl:value-of select="@netRating"/></PersonalRating>
			<Purchase><xsl:value-of select="@purchaseDate"/></Purchase>
			<Plot><xsl:value-of select="description"/></Plot>
			<Cover><xsl:value-of select="@uuid"/>.jpg</Cover>
			<URL></URL>
			<Actors>
				<xsl:call-template name="split-actors">
				<xsl:with-param name="list" select="@stars"/>
				</xsl:call-template>
			</Actors>
			<Director><xsl:value-of select="@director"/></Director>
			<Position><xsl:value-of select="@location"/></Position>
			<Country></Country>
			<UPC><xsl:value-of select="@upc"/></UPC>
			<Rating><xsl:value-of select="@mpaarating"/></Rating>		
		</Movie>
	</xsl:for-each>
</XMM_Movie_Database>
</xsl:template>

</xsl:stylesheet>