<?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">

<!--
  - Set an inline math node
-->
<xsl:template match="m">
	<xsl:value-of select="."/>
</xsl:template>


<!--
  - Set block equation
-->
<xsl:template match="equation">
	<table border="0" cellspacing="0" cellpadding="0" width="100%">
		<tr>
			<td style="text-align: center; padding-top: 0.8ex; padding-bottom: 0.8ex;">
				<xsl:apply-templates/>
			</td>
			<td style="width: 4em;">
				<xsl:choose>
					<xsl:when test="@number = 'yes'">
						<xsl:text>(</xsl:text>
						<xsl:call-template name="equation.prefix"/>
						<xsl:text>)</xsl:text>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</td>
		</tr>
	</table>
</xsl:template>


<!--
  - Get combined counter for equation
-->
<xsl:template name="equation.prefix">
	<xsl:choose>
		<xsl:when test="ancestor::chapter">
			<xsl:number count="chapter"/>
			<xsl:text>.</xsl:text>
			<xsl:variable name="id" select="generate-id(ancestor::chapter)"/>
			<xsl:number value="count(preceding::equation[
				generate-id(ancestor::chapter) = $id
				and (@number = 'yes')]) + 1"/>
		</xsl:when>
		<xsl:when test="ancestor::appendix">
			<xsl:number count="appendix" format="A"/>
			<xsl:text>.</xsl:text>
			<xsl:variable name="id" select="generate-id(ancestor::appendix)"/>
			<xsl:number value="count(preceding::equation[
				generate-id(ancestor::appendix) = $id
				and (@number = 'yes')]) + 1"/>
		</xsl:when>
		<xsl:when test="ancestor::section">
			<xsl:number count="section"/>
			<xsl:text>.</xsl:text>
			<xsl:variable name="id" select="generate-id(ancestor::section)"/>
			<xsl:number value="count(preceding::equation[
				generate-id(ancestor::section) = $id
				and (@number = 'yes')]) + 1"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text>0.</xsl:text>
			<xsl:number value="count(
				preceding::equation/ancestor::*[name() = 'preface']) + 1"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

</xsl:stylesheet>
