<?xml version="1.0"?>
<!--
	This transformation sheet takes as input an XHTML document.
	The XHTML document is used as a template and all its elements
	are included as-is in the resultant output.
	All xstyle:component elements are interpreted by this transformation
	sheet.
	xstyle:component elements inherits from the xlink domain language.
	Therefore each xstyle element is also an xlink:simple element.
	An xstyle element may contain the following attributes:
		- xlink:type="simple"
		- xlink:href="<URI>"
		- xlink:title="<string>"
		- xlink:show="embed"
		- xstyle:type="<MIME type>"
		- xstyle:height="<height value>"
		- xstyle:width="<width value>"
		- xstyle:role="<style role, header|footer|table-of-content|content"/>
	If the xlink:show attribute is set to the "embed" value, then its content is inserted in
	the resultant document. Otherwise, an error message is included in the output document.
-->
<xsl:stylesheet 
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:xlink="http://www.w3.org/1999/xlink/namespace/"
		xmlns:xstyle="http://www.talva.com/2000/xstyle"
		xmlns:html="http://www.w3.org/1999/xhtml"
		version="1.0"> 

<xsl:output method="xml" indent="yes"/>

<xsl:template match="xstyle:component">
<!-- 	Each style:component element is replaced
	by the external document's content
-->
	<xsl:choose>
		<!-- we embed the component's content only if 
		     the xlink:show attribute is set to 'show'
		-->
		<xsl:when test="contains(@xlink:show,'embed')">
			<xsl:choose>
				<xsl:when test="contains(@xstyle:type,'image/svg')">
					<embed type="image/svg">
					<xsl:attribute name="src"><xsl:value-of select="./@xlink:href"/></xsl:attribute>
					<xsl:attribute name="height"><xsl:value-of select="./@xstyle:height"/></xsl:attribute>
					<xsl:attribute name="width"><xsl:value-of select="./@xstyle:width"/></xsl:attribute>
					</embed>
				</xsl:when>
				<xsl:when test="contains(@xstyle:type,'text/xhtm')">
					<xsl:apply-templates select="document(@xlink:href)/html:html/html:body/*"/>
				</xsl:when>
				<!-- put here other xstyle formats identified by the
		    		     xstyle:type attribute.
		     		     An xstyle:type value is the component MIME type.
		    		     For example, if the component is an SVG document, then
		    		     its MIME type is image/svg.
				-->
			</xsl:choose>
		</xsl:when>
		<xsl:otherwise>
			<!-- We include an error message in the output document -->
			<xsl:comment>xstyle:component elements only support the xlink:show attribute set to the "embed" value.</xsl:comment>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="*|@*|text()">
<!-- 	In this template, We simply copy the 
 	content of the document's tree into 
	the result output without doing any 
	transformation
-->
	<xsl:copy>
		<xsl:apply-templates select="*|@*|text()"/>
	</xsl:copy>
</xsl:template>

</xsl:stylesheet>
