<?xml version="1.0" encoding="UTF-8"?>
<!--
 - Desc:    This file is part of the eCromedos document preparation system
 - Date:    2006/03/09
 - Author:  Tobias Koch (tkoch@ecromedos.net)
 - License: GNU General Public License, version 2
 - URL:     http://www.ecromedos.net
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!--
  - Quotation marks
-->
<xsl:template match="qq">
	<xsl:choose>
		<xsl:when test="not(ancestor::qq)">
			<xsl:text>{</xsl:text>
			<xsl:call-template name="i18n.print">
				<xsl:with-param name="key" select="'startquote'"/>
			</xsl:call-template>
			<xsl:text>}</xsl:text>
			<xsl:apply-templates/>
			<xsl:text>{</xsl:text>
			<xsl:call-template name="i18n.print">
				<xsl:with-param name="key" select="'endquote'"/>
			</xsl:call-template>
			<xsl:text>}</xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text>{</xsl:text>
			<xsl:call-template name="i18n.print">
				<xsl:with-param name="key" select="'startnestedquote'"/>
			</xsl:call-template>
			<xsl:text>}</xsl:text>		
			<xsl:apply-templates/>
			<xsl:text>{</xsl:text>
			<xsl:call-template name="i18n.print">
				<xsl:with-param name="key" select="'endnestedquote'"/>
			</xsl:call-template>
			<xsl:text>}</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="q">
	<xsl:text>{</xsl:text>
	<xsl:call-template name="i18n.print">
		<xsl:with-param name="key" select="'startsinglequote'"/>
	</xsl:call-template>
	<xsl:text>}</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>{</xsl:text>
	<xsl:call-template name="i18n.print">
		<xsl:with-param name="key" select="'endsinglequote'"/>
	</xsl:call-template>
	<xsl:text>}</xsl:text>
</xsl:template>

<!--
  - Set verbatim text
-->
<xsl:template match="verbatim">
	<xsl:text>\begin{alltt}</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>\end{alltt}</xsl:text>
</xsl:template>

<!-- font size -->
<xsl:template match="xx-small">
	<xsl:text>{\scriptsize{}</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:template>

<xsl:template match="x-small">
	<xsl:text>{\footnotesize{}</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:template>

<xsl:template match="small">
	<xsl:text>{\small{}</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:template>

<xsl:template match="medium">
	<xsl:text>{\normalsize{}</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:template>

<xsl:template match="large">
	<xsl:text>{\large{}</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:template>

<xsl:template match="x-large">
	<xsl:text>{\Large{}</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:template>

<xsl:template match="xx-large">
	<xsl:text>{\LARGE{}</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:template>

<!-- text in italics -->
<xsl:template match="i">
	<xsl:text>\textit{</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:template>

<!-- text in bold face -->
<xsl:template match="b">
	<xsl:text>\textbf{</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:template>

<!-- underlined text -->
<xsl:template match="u">
	<xsl:text>\uline{</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
	<xsl:call-template name="footnotetext"/>
</xsl:template>

<!-- typewriter text -->
<xsl:template match="tt">
	<xsl:text>\texttt{</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:template>

<!-- prevent line break or hyphenation -->
<xsl:template match="nobr">
	<xsl:text>\mbox{</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:template>

<!-- line break -->
<xsl:template match="br">
	<xsl:choose>
		<xsl:when test="ancestor::title">
			<xsl:text>\\{}</xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text>&#x200b;\newline{}</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- page break -->
<xsl:template match="pagebreak">
	<xsl:text>\pagebreak{}</xsl:text>
</xsl:template>

<!-- paragraph -->
<xsl:template match="p">
	<xsl:choose>
		<xsl:when test="title">
			<xsl:text>\paragraph*{</xsl:text>
			<xsl:apply-templates select="title"/>
			<xsl:text>} </xsl:text>
			<xsl:apply-templates select="title/following-sibling::*|title/following-sibling::text()"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:apply-templates/>
		</xsl:otherwise>
	</xsl:choose>
	<xsl:choose>
		<xsl:when test="name(following-sibling::*[1]) = 'equation'">
			<xsl:text></xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text>&#x0a;&#x0a;</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- hyphenation -->
<xsl:template match="y">
	<xsl:text>\-</xsl:text>
</xsl:template>

<!-- cross-referencing -->
<xsl:template match="label">
	<xsl:text>\label{</xsl:text>
	<xsl:value-of select="@name"/>
	<xsl:text>}</xsl:text>
</xsl:template>

<xsl:template match="ref">
	<xsl:variable name="name" select="@name"/>
	<xsl:choose>
		<xsl:when test="//counter[@label=$name]">
			<xsl:for-each select="//counter[@label=$name]">
				<xsl:call-template name="counter.prefix"/>
			</xsl:for-each>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text>\ref{</xsl:text>
			<xsl:value-of select="@name"/>
			<xsl:text>}</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="pageref">
	<xsl:variable name="name" select="@name"/>
	<xsl:text>\pageref{</xsl:text>
	<xsl:value-of select="@name"/>
	<xsl:text>}</xsl:text>
</xsl:template>

<!--
  - Print text-nodes
-->
<xsl:template match="text()">
	<xsl:value-of select="."/>
</xsl:template>

</xsl:stylesheet>
