<?xml version='1.0' encoding='utf-8' ?><xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:s="http://www.w3.org/2000/SMIL20/CR/Language"
	exclude-result-prefixes="s">

<!--
	SMIL20 profile to SMIL basic profile
	author: Lionel Villard
	email:Lionel.Villard@inrialpes.fr
	date: 06 July 2001
	last modification: 06 July 2001
-->

<!-- Structure module -->
<xsl:template match="s:smil|s:head|s:body">
	<xsl:copy>
		<xsl:apply-templates select="@*"/>
		<xsl:apply-templates/> 	
	</xsl:copy>
</xsl:template>


<!-- HierarchicalLayout module -->
<xsl:template match="s:layout">
	<xsl:copy>
		<xsl:copy-of select="@*"/>

		<xsl:choose>
			<xsl:when test="s:root-layout">
				<xsl:variable name="width">
					<xsl:choose>
						<xsl:when test="s:root-layout/@width">
							<xsl:call-template name="length2abs">
								<xsl:with-param name="length" select="s:root-layout/@width"/>
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>50</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:variable name="height">
					<xsl:choose>
						<xsl:when test="s:root-layout/@height">
							<xsl:call-template name="length2abs">
								<xsl:with-param name="length" select="s:root-layout/@height"/>
							</xsl:call-template>							
						</xsl:when>
						<xsl:otherwise>50</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:apply-templates>
					<xsl:with-param name="width" select="$width"/>
					<xsl:with-param name="height" select="$height"/>
				</xsl:apply-templates>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:copy>
</xsl:template>

<xsl:template match="s:region">
	<xsl:param name="parent-top" select="0"/>
	<xsl:param name="parent-left" select="0"/>
	<xsl:param name="parent-width" select="50"/>
	<xsl:param name="parent-height" select="50"/>

	<xsl:variable name="top">
		<xsl:call-template name="length2abs">
			<xsl:with-param name="length" select="@top"/>
			<xsl:with-param name="parent-size" select="$parent-height"/>
			<xsl:with-param name="parent-pos" select="$parent-top"/>
		</xsl:call-template>
	</xsl:variable>

	<xsl:variable name="left">
		<xsl:call-template name="length2abs">
			<xsl:with-param name="length" select="@left"/>
			<xsl:with-param name="parent-size" select="$parent-width"/>
			<xsl:with-param name="parent-pos" select="$parent-left"/>
		</xsl:call-template>
	</xsl:variable>

	<xsl:variable name="width">
		<xsl:call-template name="length2abs">
			<xsl:with-param name="length" select="@width"/>
			<xsl:with-param name="parent-size" select="$parent-width"/>			
		</xsl:call-template>
	</xsl:variable>

	<xsl:variable name="height">
		<xsl:call-template name="length2abs">
			<xsl:with-param name="length" select="@height"/>
			<xsl:with-param name="parent-size" select="$parent-height"/>			
		</xsl:call-template>
	</xsl:variable>

	<region top="{$top}" left="{$left}" width="{$width}" height="{$height}">
		<xsl:apply-templates select="@*"/>
	</region>

	<xsl:apply-templates>
		<xsl:with-param name="parent-top" select="$top"/>
		<xsl:with-param name="parent-left" select="$left"/>
		<xsl:with-param name="parent-width" select="$width"/>
		<xsl:with-param name="parent-height" select="$height"/>
	</xsl:apply-templates>
</xsl:template>

<xsl:template match="s:root-layout">
	<xsl:copy>
		<xsl:copy-of select="@*"/>		
	</xsl:copy>
</xsl:template>

<xsl:template match="@top|@left|@width|@height">
	<!-- filtered -->
</xsl:template>

<xsl:template name="length2abs">
	<xsl:param name="length" select="0"/>
	<xsl:param name="parent-size" select="0"/>
	<xsl:param name="parent-pos" select="0"/>

	<xsl:choose>
		<xsl:when test="contains($length, '%')">
			<xsl:value-of select="$parent-size * substring($length, 0, string-length($length)) div 100"/>
		</xsl:when>
		<xsl:when test="contains($length, 'px')">
			<xsl:value-of select="$parent-pos + substring($length, 0, string-length($length) - 1)"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$parent-pos + $length"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- BasicMedia module -->
<xsl:template match="s:img|s:ref|s:animation|s:audio|s:video|s:text|s:textstream">
	<xsl:copy>
		<xsl:apply-templates select="@*"/>
		<!--xsl:apply-templates/-->
	</xsl:copy>
</xsl:template>


<!-- BrushMedia module -->
<xsl:template match="s:brush">
	<!-- filtered -->
</xsl:template>


<!-- Timing modules -->

<xsl:template match="s:par|s:seq">
	<xsl:copy>
		<xsl:apply-templates select="@*"/>
		<xsl:apply-templates/>
	</xsl:copy>
</xsl:template>

<!-- ExclTiming module -->
<xsl:template match="s:excl">
	<seq>
		<xsl:apply-templates select="@*"/>
		<xsl:apply-templates/>
	</seq>
</xsl:template>


<!-- Metainformation module -->
<!-- BasicAnimation module -->
<!-- PrefetchControl module -->
<!-- AudioLayout Module -->
<xsl:template match="s:meta|s:metadata|s:animate|s:set|s:animateMotion|s:animateColor|@targetElement|@prefetch|@soundLevel">
	<!-- filtered -->
</xsl:template>

<!-- Transition Module -->
<xsl:template match="s:transition|@transIn|@transOut">
	<!-- filtered -->
</xsl:template>


<xsl:template match="@*">
	<xsl:copy/>
</xsl:template>


</xsl:stylesheet>
