<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#160;"> ]>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:m="http://www.w3.org/1998/Math/MathML"
>
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*"/>

	<xsl:template name="replace-string">
		<xsl:param name="text"/>
		<xsl:param name="replace"/>
		<xsl:param name="with"/>
		<xsl:choose>
		<xsl:when test="contains($text,$replace)">
			<xsl:value-of select="substring-before($text,$replace)"/>
			<xsl:value-of select="$with"/>
			<xsl:call-template name="replace-string">
			<xsl:with-param name="text"
	select="substring-after($text,$replace)"/>
			<xsl:with-param name="replace" select="$replace"/>
			<xsl:with-param name="with" select="$with"/>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$text"/>
		</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="font-size">
		<xsl:choose>
			<xsl:when test="@value='1'">font-size: xx-small;</xsl:when>
			<xsl:when test="@value='2'">font-size: xx-small;</xsl:when>
			<xsl:when test="@value='3'">font-size: x-small;</xsl:when>
			<xsl:when test="@value='4'">font-size: small;</xsl:when>
			<xsl:when test="@value='5'">font-size: medium;</xsl:when>
			<xsl:when test="@value='6'">font-size: large;</xsl:when>
			<xsl:when test="@value='7'">font-size: x-large;</xsl:when>
			<xsl:when test="@value='8'">font-size: x-large;</xsl:when>
			<xsl:when test="@value='9'">font-size: xx-large;</xsl:when>
			<xsl:when test="@value='10'">font-size: xx-large;</xsl:when>	
		</xsl:choose>	
	</xsl:template>
	
	<xsl:template name="font">
		<xsl:choose>
			<xsl:when test="@type='bold'">font-weight : bold;</xsl:when>
			<xsl:when test="@type='italic'">font-style : italic;</xsl:when>
			<xsl:when test="@type='subscript'"></xsl:when>
			<xsl:when test="@type='superscript'"></xsl:when>
			<xsl:when test="@type='smallcaps'">font-variant: small-caps;</xsl:when>
			<xsl:when test="@type='sans-serif'">font-family: sans-serif;</xsl:when>
			<xsl:when test="@type='courier'">font-family: courier;</xsl:when>
			<xsl:when test="@type='uppercase'">font-transform: uppercase;</xsl:when>
			<xsl:when test="@type='underline'">text-decoration: underline;</xsl:when>
			<xsl:when test="@type='double-underline'">text-decoration: underline;</xsl:when>
			<xsl:when test="@type='wave-underline'">text-decoration: underline;</xsl:when>						
			<xsl:when test="@type='strike'">text-decoration: line-through;</xsl:when>
			<xsl:when test="@type='hidden'">display: none;</xsl:when>
		</xsl:choose>	
	</xsl:template>
	
	<xsl:template name="font-color">color: #<xsl:value-of select="@color" />;</xsl:template>
	
	<xsl:template name="font-background">background-color: #<xsl:value-of select="@color" />;</xsl:template>
	
	<xsl:template name="box">
		<xsl:choose>
			<xsl:when test="@border-color">border: 1px solid #<xsl:value-of select="@border-color" />;</xsl:when>
			<xsl:otherwise>border: 1px solid #000;</xsl:otherwise>
		</xsl:choose>
		
		<xsl:if test="@background-color">background-color: #<xsl:value-of select="@background-color" />;</xsl:if>	
	</xsl:template>
				
	
	<!-- ********************************* -->

	<xsl:template match="/">
	<xsl:text disable-output-escaping="yes">
	<![CDATA[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
               "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" [
  <!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
]>  
	]]>
</xsl:text>
		<html>
			<xsl:apply-templates />
		</html>
	</xsl:template>
	
	<xsl:template match="head">
		<head>
			<xsl:apply-templates />
		</head>
	</xsl:template>
	
	<!-- CSS STYLES -->				
	
	<xsl:template match="styles">
		<style type="text/css">
			.eqcontainer {
				width: 100%;
				text-align : center;				
			}
			.eqlabel {
				display : inline;
				margin-left : 10px;
			}
			.eqnumbered {
				display : inline;
			}
			.cleaner {
				clear : both;
				height : 1px;
			}
			p {
				padding : 3px;
				margin : 0px;
			}
			body {
				margin : 20px;
			}
			<xsl:apply-templates />		
		</style>
	</xsl:template>
	
	<xsl:template match="style">
		<span>
		<xsl:attribute name="class"><xsl:value-of select="@name" /></xsl:attribute>
		<xsl:apply-templates />
		</span>
	</xsl:template>
	
	<xsl:template match="style-definition">
		.<xsl:value-of select="@name" /> {
			<xsl:apply-templates />
		}
	</xsl:template>
	
	<xsl:template match="style-definition//font">
		<xsl:call-template name="font" />
		
		<xsl:apply-templates />
	</xsl:template>
	
	<xsl:template match="style-definition//font-size">
		<xsl:call-template name="font-size" />
		
		<xsl:apply-templates />
	</xsl:template>

	<xsl:template match="style-definition//font-color">
		<xsl:call-template name="font-color" />
		<xsl:apply-templates />	
	</xsl:template>
	
	<xsl:template match="style-definition//font-background">
		<xsl:call-template name="font-background" />
		<xsl:apply-templates />		
	</xsl:template>
		
	<xsl:template match="style-definition//box">
		<xsl:call-template name="box" />		
		<xsl:apply-templates />
	</xsl:template>	
		
	<!-- END OF CSS STYLES -->
	
	<xsl:template match="table-of-contents">
		<xsl:for-each select="//heading">
			<xsl:choose>
				<xsl:when test="@level=1">
					<p><strong><a>
					<xsl:attribute name="href">#heading<xsl:value-of select="generate-id(.)" /></xsl:attribute>
					<xsl:value-of select="."/>
					</a></strong></p>
				</xsl:when>
				<xsl:when test="@level=2">
					<p style="text-indent:20pt"><a>
					<xsl:attribute name="href">#heading<xsl:value-of select="generate-id(.)" /></xsl:attribute>
					<xsl:value-of select="."/>
					</a>					
					</p>
				</xsl:when>
				<xsl:when test="@level=3">
					<p style="text-indent:40pt"><a>
					<xsl:attribute name="href">#heading<xsl:value-of select="generate-id(.)" /></xsl:attribute>
					<xsl:value-of select="."/>
					</a>					
					</p>
				</xsl:when>
			</xsl:choose>		
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="body">
		<body>
			<xsl:apply-templates />
		</body>
	</xsl:template>
	
	<xsl:template match="title">
		<title>
			<xsl:apply-templates />
		</title>
	</xsl:template>	
	
	<xsl:template match="para | table-para | list-para">
		<xsl:if test="not(descendant::heading)">
		<p>
			<xsl:variable name="styleindent">
				<xsl:choose>
					<xsl:when test="par-indent">padding-left: <xsl:value-of select="par-indent/@left" />pt; padding-right: <xsl:value-of select="par-indent/@right " />pt;text-indent: <xsl:value-of select="par-indent/@first-line" />pt;</xsl:when>
					<xsl:otherwise></xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			
			<xsl:variable name="stylealign">
				<xsl:choose>
					<xsl:when test="align">
						<xsl:choose>
							<xsl:when test="align/@type='left'">text-align: left;</xsl:when>
							<xsl:when test="align/@type='right'">text-align: right;</xsl:when>
							<xsl:when test="align/@type='center'">text-align: center;</xsl:when>
						</xsl:choose>					
					</xsl:when>
					<xsl:otherwise></xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			
			<xsl:if test="not($styleindent='' and $stylealign='')">
				<xsl:attribute name="style"><xsl:value-of select="$styleindent" /><xsl:value-of select="$stylealign" /></xsl:attribute>
			</xsl:if>
			<xsl:apply-templates />
		</p>
		</xsl:if>
		<xsl:if test="descendant::heading">
			<xsl:apply-templates />
		</xsl:if>
	</xsl:template>
	
	<!-- todo stejny nadpis -->
	<xsl:template match="heading">
		<!--
		<xsl:variable name="me"><xsl:value-of select="." /></xsl:variable>
		<xsl:for-each select="//heading">
			<xsl:if test=".=$me">
				<xsl:variable name="number" select="position()" />

				<xsl:choose>
					<xsl:when test="@level &lt; 8">
						<xsl:element name="h{@level}">
						<a>
						<xsl:attribute name="name">heading<xsl:value-of select="$number" />
						</xsl:attribute>
						<xsl:apply-templates />
						</a>
						</xsl:element>
					</xsl:when>			
					<xsl:otherwise>
						<p>
							<xsl:apply-templates />
						</p>
					</xsl:otherwise>
				</xsl:choose>
		
			</xsl:if>
		</xsl:for-each>
		-->
		
				<xsl:choose>
					<xsl:when test="@level &lt; 8">
						<xsl:element name="h{@level}">
						<a>
						<xsl:attribute name="name">heading<xsl:value-of select="generate-id(.)" />
						</xsl:attribute>
						<xsl:apply-templates />
						</a>
						</xsl:element>
					</xsl:when>			
					<xsl:otherwise>
						<p>
							<xsl:apply-templates />
						</p>
					</xsl:otherwise>
				</xsl:choose>		
	</xsl:template>	
	
	<xsl:template match="list">
		<xsl:choose>
			<xsl:when test="@type='itemize'">
				<ul>
				<xsl:apply-templates />
				</ul>
			</xsl:when>
			<xsl:when test="@type='enumerate'">
				<ol>
				<xsl:apply-templates />
				</ol>
			</xsl:when>
		</xsl:choose>
	</xsl:template>	
	

	<xsl:template match="list-item">
		<li>
			<xsl:apply-templates />
		</li>
	</xsl:template>

	
	<xsl:template match="image">
		<img>
			<xsl:attribute name="src">
				<xsl:call-template name="replace-string">
					<xsl:with-param name="text" select="@src"/>
					<xsl:with-param name="replace" select="'.eps'"/>
					<xsl:with-param name="with" select="'.png'"/>
				</xsl:call-template>
			</xsl:attribute>
			<xsl:attribute name="title">
				<xsl:value-of select="@title" />				
			</xsl:attribute>
			<xsl:attribute name="alt">
				<xsl:value-of select="@title" />				
			</xsl:attribute>			
			<xsl:attribute name="style">				
				<xsl:text>width: </xsl:text>
				<xsl:value-of select="@width" />
				<xsl:text>pt</xsl:text>
			</xsl:attribute> 						
		</img>
	</xsl:template>
	
	<xsl:template match="link">
		<a>
			<xsl:attribute name="href">
				<xsl:value-of select="@href" />
			</xsl:attribute>
			<xsl:apply-templates />
		</a>
	</xsl:template>
	
	<xsl:template match="font">
		<xsl:choose>

			<!--
			<xsl:when test="@type='bold'">
				<strong>
				<xsl:apply-templates />
				</strong>
			</xsl:when>
			<xsl:when test="@type='italic'">
				<em>
				<xsl:apply-templates />
				</em>
			</xsl:when>
			-->
			
			<xsl:when test="@type='subscript'">
				<sub>
				<xsl:apply-templates />
				</sub>
			</xsl:when>
			<xsl:when test="@type='superscript'">
				<sup>
				<xsl:apply-templates />
				</sup>
			</xsl:when>

			<!--
			<xsl:when test="@type='smallcaps'">
				<sc>
				<xsl:apply-templates />
				</sc>
			</xsl:when>
			<xsl:when test="@type='sans-serif'">
				<xsl:apply-templates />
			</xsl:when>
			<xsl:when test="@type='courier'">
			 <tt>
				<xsl:apply-templates />
			 </tt>
			</xsl:when>
			-->


			<xsl:otherwise>
				<span>
					<xsl:attribute name="style"><xsl:call-template name="font" /></xsl:attribute>
				<xsl:apply-templates />
				</span>
			</xsl:otherwise>		

		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="box">
		<span>
			<xsl:attribute name="style"><xsl:call-template name="box" /></xsl:attribute>
		<xsl:apply-templates />
		</span>
	</xsl:template>
	
	<xsl:template match="font-color">
		<span>
			<xsl:attribute name="style"><xsl:call-template name="font-color" /></xsl:attribute>
		<xsl:apply-templates />
		</span>
	</xsl:template>
	
	<xsl:template match="font-background">
		<span>
			<xsl:attribute name="style"><xsl:call-template name="font-background" /></xsl:attribute>
		<xsl:apply-templates />
		</span>
	</xsl:template>
	
	<xsl:template match="font-size">
		<span>
			<xsl:attribute name="style"><xsl:call-template name="font-size" /></xsl:attribute>
		<xsl:apply-templates />
		</span>
	</xsl:template>
	
	<!-- TABLES -->
	
	<xsl:template match="table">
		<table border="1">			
			<xsl:if test="../align">
				<xsl:choose>
					<xsl:when test="../align/@type='left'"></xsl:when>
					<xsl:when test="../align/@type='right'"></xsl:when>
					<xsl:when test="../align/@type='center'"><xsl:attribute name="style">margin-left: auto; margin-right: auto;</xsl:attribute></xsl:when>
				</xsl:choose>					
			</xsl:if>
			<xsl:if test="@title">
				<caption><xsl:value-of select="@title" /></caption>
			</xsl:if>				
			<xsl:apply-templates />
		</table>
	</xsl:template>
	
	<xsl:template match="table-row">
		<tr>
			<xsl:apply-templates />
		</tr>
	</xsl:template>	
	
	<xsl:template match="table-cell">
		<td>
			<xsl:if test="@multi &gt; 1">
				<xsl:attribute name="colspan"><xsl:value-of select="@multi" /></xsl:attribute>
			</xsl:if>
			
			<xsl:choose>
				<xsl:when test="@width and @color">
					<xsl:attribute name="style">width: <xsl:value-of select="@width" />pt; background-color: #<xsl:value-of select="@color" />;</xsl:attribute>
				</xsl:when>
				<xsl:when test="@width">
					<xsl:attribute name="style">width: <xsl:value-of select="@width" />pt;</xsl:attribute>
				</xsl:when>
				<xsl:when test="@color">
					<xsl:attribute name="style">background-color: #<xsl:value-of select="@color" />;</xsl:attribute>
				</xsl:when>				
			</xsl:choose>				

			<xsl:if test="table-multirow-cell[@multi]">
				<xsl:attribute name="rowspan"><xsl:value-of select="table-multirow-cell/@multi" /></xsl:attribute>
			</xsl:if>
			<xsl:apply-templates />
		</td>
	</xsl:template>
	
	<!-- END OF TABLES -->	
	
	<xsl:template match="bibliography">
		<xsl:apply-templates />
	</xsl:template>
	
	<xsl:template match="bib-item">
		<p>
		<a>
			<xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
		</a>
		[<xsl:value-of select="@name" />]
		<xsl:apply-templates />
		</p>
	</xsl:template>
	
	<xsl:template match="equation">
		<xsl:choose>
			<xsl:when test="@type='inline' and m:math">
				<m:math diplay="inline">
					<xsl:copy-of select="m:math/*" />
				</m:math>
			</xsl:when>
			<xsl:when test="@type='inline' and not(m:math)">
				<m:math diplay="inline">
					<xsl:apply-templates />
				</m:math>
			</xsl:when>			
			<xsl:when test="@type='numbered'">
				<div class="eqcontainer">
					<a>
						<xsl:attribute name="name"><xsl:value-of select="label/@name" /></xsl:attribute>
					</a>
					<div class="eqnumbered">
						<m:math diplay="block">
							<xsl:copy-of select="m:math/*" />
						</m:math>				
					</div>
					<div class="eqlabel"><xsl:value-of select="@origlabel"/></div>
				</div>
				<div class="cleaner" />
			</xsl:when>
			<xsl:otherwise>
				<m:math diplay="block">
					<xsl:copy-of select="m:math/*" />
				</m:math>			
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="printindex">
		<ul>
		<xsl:for-each select="//index-entry">
			<li><xsl:apply-templates /></li>
		</xsl:for-each>		
		</ul>
	</xsl:template>
	
	<xsl:template match="bookmark">
		<a>
			<xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
			<xsl:apply-templates />
		</a>
	</xsl:template>
	
	<xsl:template match="reference | page-reference">
		<a>
			<xsl:attribute name="href">#<xsl:value-of select="@name" /></xsl:attribute>
			see <xsl:value-of select="@name" />
			<xsl:apply-templates />
		</a>
	</xsl:template>
	
	<xsl:template match="math-reference | biblio-reference">
		<a>
			<xsl:attribute name="href">#<xsl:value-of select="@name" /></xsl:attribute>
			<xsl:apply-templates />
		</a>
	</xsl:template>
	
	<xsl:template match="endnote-reference">
		<a>
			<xsl:attribute name="href">#<xsl:value-of select="@name" /></xsl:attribute>
			[<xsl:value-of select="@name" />]
		</a>
	</xsl:template>	
	
	<xsl:template match="note-reference">
		<a><xsl:attribute name="href">#<xsl:value-of select="@name" /></xsl:attribute>[<xsl:value-of select="@name" />]</a>
	</xsl:template>
	
	<xsl:template match="footnote">
		(<xsl:apply-templates />)
	</xsl:template>
	
	<xsl:template match="tab">
		&nbsp;&nbsp;&nbsp;&nbsp;
	</xsl:template>
	
	<xsl:template match="linebreak">
		<br />
	</xsl:template>
	
	<xsl:template match="index-entry"></xsl:template>	


</xsl:stylesheet>

  















