<?xml version="1.0" encoding="iso-8859-1"?>

<!-- 
Ecrit par Stéphane Bonhomme http://www.biophyse.net
Ce document est sous licence GPL http://www.gnu.org/licenses/gpl.html
Article lié : http://www.scriptsphp.org/article.De-OOo-a-Xhtml-via-XSLT
-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:office="http://openoffice.org/2000/office" xmlns:style="http://openoffice.org/2000/style" xmlns:text="http://openoffice.org/2000/text" xmlns:table="http://openoffice.org/2000/table" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="office style text table draw fo xlink svg xhtml" >

<xsl:output
	method="xml"
	version="1.0"
	encoding="iso-8859-1"
	doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
	standalone="yes"
	indent="yes" />

<xsl:template match="office:body">
	<html lang="fr" xml:lang="fr">
	<head>
	    <title>Mon Site - <xsl:value-of select="text:p[@text:style-name='Heading']" /></title>
	    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	</head>
	<body>		
		<xsl:apply-templates />
	</body>
	</html>
</xsl:template>

<xsl:template match="text:p">
<!--
	<xsl:if test="@text:style-name='Heading'">
		<h2><xsl:apply-templates /></h2>
	</xsl:if>
	<xsl:if test="(@text:style-name='Standard' or @text:style-name='Text body') and node()">
		<p><xsl:apply-templates /></p>
	</xsl:if>
	<xsl:if test="@text:style-name='Quotations'">
		<blockquote><p><xsl:apply-templates /></p></blockquote></xsl:if>
-->
	<xsl:choose>
		<xsl:when test="@text:style-name='Heading' and node()">
			<h2>
				<xsl:apply-templates />
			</h2>
		</xsl:when>
		<xsl:when test="@text:style-name='Quotations' and node()">
			<blockquote>
				<p>
				<xsl:apply-templates />
				</p>
			</blockquote>
		</xsl:when>
		<xsl:when test="name(..)='text:list-item'">
			<xsl:apply-templates /> 
		</xsl:when>
		<xsl:otherwise>
			<xsl:if test="node()">
				<p>
					<xsl:apply-templates />  
				</p>
			</xsl:if>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="text:span">
	<xsl:variable name="StyleType" select="@text:style-name"/>
	<xsl:variable name="weight" select="/office:document-content/office:automatic-styles/style:style[@style:name=$StyleType]/style:properties/@fo:font-weight"/>
	<xsl:variable name="style" select="/office:document-content/office:automatic-styles/style:style[@style:name=$StyleType]/style:properties/@fo:font-style"/>
	
	<xsl:choose>
        	<xsl:when test="$weight='bold'">
			<strong><xsl:apply-templates /></strong>
		</xsl:when>
        	<xsl:when test="$style='italic'">
        		<em><xsl:apply-templates /></em>
        	</xsl:when>
        	<xsl:otherwise>
		       	<xsl:apply-templates />
		</xsl:otherwise>
	</xsl:choose>   
</xsl:template>

<xsl:template match="text:h">
	<xsl:variable name="level" select="@text:level+2" />
	<xsl:choose>
		<xsl:when test="$level &lt;= 6">
			<xsl:element name="h{$level}">
				<xsl:apply-templates />
			</xsl:element>
		</xsl:when>
		<xsl:otherwise>
			<p>
				<xsl:apply-templates />  
			</p>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="text:a">
	<a>
		<xsl:attribute name="href"><xsl:value-of select="@xlink:href" /></xsl:attribute>
		<xsl:attribute name="title"><xsl:value-of select="@office:name" /></xsl:attribute>
		<xsl:choose>		
			<xsl:when test="contains(.,')') and string-length(substring-after(substring-before(.,')'),'('))&lt;=2">
				<xsl:attribute name="hreflang">
					
					<xsl:value-of select="substring-after(substring-before(.,')'),'(')" />
					
				</xsl:attribute>
				<xsl:value-of select="substring-before(.,'(')" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>
	</a>
</xsl:template>

<xsl:template match="draw:image">
	<img>
		<xsl:attribute name="src">
			<xsl:value-of select="substring(@xlink:href,2)"/>
		</xsl:attribute>
		<xsl:attribute name="width">
			<xsl:value-of select="round(substring-before(@svg:width,'cm')*38.37)"/>
		</xsl:attribute>
		<xsl:attribute name="height">
			<xsl:value-of select="round(substring-before(@svg:height,'cm')*38.37)"/>
		</xsl:attribute>
		<xsl:attribute name="alt">
			<xsl:value-of select="@draw:name"/>
		</xsl:attribute>
		<xsl:if test="svg:desc">
			<xsl:attribute name="longdesc"><xsl:value-of select="svg:desc"/></xsl:attribute>
		</xsl:if>
	</img>
</xsl:template>
  
<xsl:template match="text:ordered-list">
	<ol>
		<xsl:apply-templates />
	</ol>
</xsl:template> 

<xsl:template match="text:unordered-list"> 
	<ul>
		<xsl:apply-templates />
	</ul>
</xsl:template> 

<xsl:template match="text:list-item"> 
	<li>
		<xsl:apply-templates />
	</li>
</xsl:template>
  
</xsl:stylesheet>
