<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html [
<!ENTITY copy "&#169;">
<!ENTITY ndash "&#8211;">
]>

<!--
Stylesheet to process Article documents to XHTML
Copyright (C) 2008, Ertugrul Söylemez

Version: 1.00

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the
      distribution.

    * Neither the name of the author nor the names of any contributors
      may be used to endorse or promote products derived from this
      software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://www.w3.org/1999/xhtml"
	version="1.0">


<xsl:output
	method="xml"
	encoding="UTF-8"
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
	doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
	omit-xml-declaration="yes"
	/>


<!-- Root element -->

<xsl:template match="/Article">
	<html>
		<xsl:attribute name="lang"><xsl:value-of select="lang" /></xsl:attribute>

		<head>
			<title><xsl:value-of select="title" /></title>
			<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
			<xsl:call-template name="css-style" />
		</head>

		<body>
			<h1><xsl:value-of select="title" /></h1>
			<p class="copyright">
				<xsl:text>Copyright &copy; </xsl:text>
				<xsl:value-of select="year" />
				<xsl:text> </xsl:text>
				<xsl:value-of select="author" />
			</p>

			<p><xsl:value-of select="normalize-space(version)" /></p>

			<xsl:if test="count(abstract) = 1">
				<p class="abstract">
					<xsl:value-of select="normalize-space(abstract)" />
				</p>
			</xsl:if>

			<ul id="menu">
				<xsl:for-each select="section">
					<li>
						<a>
							<xsl:attribute name="href">#section-<xsl:number value="position()" format="1" /></xsl:attribute>
							<xsl:number value="position()" format="1. " />
							<xsl:value-of select="@title" />
						</a>

						<xsl:if test="count(subsection) > 0 and /Article/options/@subsections = &quot;yes&quot;">
							<ul>
								<xsl:variable name="section" select="position()" />
								<xsl:for-each select="code | img | list | math | p | subsection">
									<xsl:if test="name(.) = &quot;subsection&quot;">
										<li>
											<a>
												<xsl:attribute name="href">#section-<xsl:value-of select="$section" />-<xsl:value-of select="position()" /></xsl:attribute>
												<xsl:value-of select="." />
											</a>
										</li>
									</xsl:if>
								</xsl:for-each>
							</ul>
						</xsl:if>
					</li>
				</xsl:for-each>

				<xsl:for-each select="appendix">
					<li>
						<a>
							<xsl:attribute name="href">#appendix-<xsl:number value="position()" format="a" /></xsl:attribute>
							<xsl:number value="position()" format="A. " />
							<xsl:value-of select="@title" />
						</a>
					</li>
				</xsl:for-each>

				<xsl:if test="count(bibliography) > 0">
					<li>
						<a href="#bibliography">
							<xsl:value-of select="bibliography/title" />
						</a>
					</li>
				</xsl:if>
			</ul>

			<xsl:apply-templates select="section" />
			<xsl:apply-templates select="appendix" />
			<xsl:apply-templates select="bibliography" />

			<p class="footer">
				<xsl:value-of select="date" />
				<xsl:text>, </xsl:text>
				<xsl:value-of select="author" />
			</p>
		</body>
	</html>
</xsl:template>


<!-- Article section -->

<xsl:template match="section">
	<h2>
		<a>
			<xsl:attribute name="name">section-<xsl:number value="position()" format="1" /></xsl:attribute>
			<xsl:number value="position()" format="1. " />
			<xsl:value-of select="@title" />
		</a>
	</h2>

	<xsl:apply-templates select="code | img | list | math | p | subsection">
		<xsl:with-param name="section"><xsl:value-of select="position()" /></xsl:with-param>
	</xsl:apply-templates>
</xsl:template>

<xsl:template match="appendix">
	<h2>
		<a>
			<xsl:attribute name="name">appendix-<xsl:number value="position()" format="a" /></xsl:attribute>
			<xsl:number value="position()" format="A. " />
			<xsl:value-of select="@title" />
		</a>
	</h2>

	<xsl:apply-templates select="code | img | list | math | p | subsection">
		<xsl:with-param name="section"><xsl:value-of select="position()" /></xsl:with-param>
	</xsl:apply-templates>
</xsl:template>


<!-- Various elements marking up normal article text -->

<xsl:template match="bibref">
	<xsl:choose>
		<xsl:when test="string-length(.) = 0">
			<xsl:value-of select="/Article/bibliography/bibitem[@ref = current()/@ref]/name" />
			<xsl:text> </xsl:text>
		</xsl:when>

		<xsl:when test=". = &quot;-&quot;">
		</xsl:when>

		<xsl:otherwise>
			<xsl:value-of select="normalize-space()" />
			<xsl:text> </xsl:text>
		</xsl:otherwise>
	</xsl:choose>

	<xsl:text>[</xsl:text>
	<a>
		<xsl:variable name="bibref" select="@ref" />
		<xsl:for-each select="/Article/bibliography/bibitem">
			<xsl:if test="@ref = $bibref">
				<xsl:attribute name="href">#bib-<xsl:value-of select="position()" /></xsl:attribute>
				<xsl:value-of select="position()" />
			</xsl:if>
		</xsl:for-each>
	</a>
	<xsl:text>]</xsl:text>
</xsl:template>


<xsl:template match="li/code | p/code" priority="1">
	<code><xsl:value-of select="." /></code>
</xsl:template>


<xsl:template match="code" priority="0">
	<pre>
		<xsl:value-of select="concat(normalize-space(substring(., 1, 1)), substring(., 2, string-length() - 2), normalize-space(substring(., string-length(), 1)))" />
	</pre>
</xsl:template>


<xsl:template match="em">
	<em><xsl:value-of select="." /></em>
</xsl:template>


<xsl:template match="img">
	<a>
		<xsl:attribute name="href"><xsl:value-of select="/Article/pics" />/<xsl:value-of select="@src" /></xsl:attribute>
		<img>
			<xsl:attribute name="src"><xsl:value-of select="/Article/pics" />/<xsl:value-of select="@tn" /></xsl:attribute>
			<xsl:attribute name="alt"><xsl:value-of select="." /></xsl:attribute>
			<xsl:if test="@side = &quot;right&quot;">
				<xsl:attribute name="class">right</xsl:attribute>
			</xsl:if>
		</img>
	</a>
</xsl:template>


<xsl:template match="list">
	<xsl:choose>
		<xsl:when test="string-length(@type) = 0 or @type = &quot;ul&quot;">
			<ul>
				<xsl:for-each select="li">
					<li><xsl:call-template name="paragraph" /></li>
				</xsl:for-each>
			</ul>
		</xsl:when>
		<xsl:when test="@type = &quot;ol&quot;">
			<ol>
				<xsl:for-each select="li">
					<li><xsl:call-template name="paragraph" /></li>
				</xsl:for-each>
			</ol>
		</xsl:when>
	</xsl:choose>
</xsl:template>


<xsl:template match="math">
	<p class="math">
		<var><xsl:value-of select="normalize-space()" /></var>
	</p>
</xsl:template>


<xsl:template name="paragraph">
	<xsl:apply-templates select="text()|bibref|code|em|ref|strong|v" />
</xsl:template>


<xsl:template match="p">
	<p><xsl:call-template name="paragraph" /></p>
</xsl:template>


<xsl:template match="ref">
	<a>
		<xsl:attribute name="href"><xsl:value-of select="@href" /></xsl:attribute>
		<xsl:value-of select="." />
	</a>
</xsl:template>


<xsl:template match="strong">
	<strong><xsl:value-of select="." /></strong>
</xsl:template>


<xsl:template match="subsection">
	<xsl:param name="section" />
	<h3>
		<a>
			<xsl:attribute name="name">section-<xsl:value-of select="$section" />-<xsl:value-of select="position()"></xsl:value-of></xsl:attribute>
			<xsl:value-of select="normalize-space()" />
		</a>
	</h3>
</xsl:template>


<xsl:template match="v">
	<var><xsl:value-of select="normalize-space()" /></var>
</xsl:template>


<!-- Bibliography (if present) -->

<xsl:template match="bibliography">
	<h2>
		<a name="bibliography">
			<xsl:value-of select="title" />
		</a>
	</h2>

	<dl id="biblist">
		<xsl:for-each select="bibitem">
			<dt>
				<a>
					<xsl:attribute name="name">bib-<xsl:value-of select="position()" /></xsl:attribute>
					[<xsl:value-of select="position()" />]
				</a>
				<xsl:text> </xsl:text>

				<xsl:choose>
					<xsl:when test="href != &quot;&quot;">
						<a>
							<xsl:attribute name="href"><xsl:value-of select="href" /></xsl:attribute>
							<xsl:value-of select="name" />
						</a>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="name" />
					</xsl:otherwise>
				</xsl:choose>
			</dt>

			<dd>
				<xsl:text>&ndash; </xsl:text>
				<xsl:value-of select="normalize-space(description)" />
			</dd>
		</xsl:for-each>
	</dl>
</xsl:template>


<!-- The CSS style sheet -->

<xsl:template name="css-style">
<style type="text/css">

html {
	background: #DDD;
	color: #000;
	margin: 0;
	padding: 0;
	text-align: justify;
	word-spacing: 0.2ex;
}

body {
	background: #FFF;
	border: 2px solid;
	margin: 1em auto;
	padding: 1em 4ex;
	max-width: 80ex;
}

#menu {
	list-style: square outside;
	margin: 1.5em 0 2em 0;
}

#menu li {
	margin: 0;
	padding: 0;
}

#menu li ul {
	list-style: none outside;
	margin: 0 0 0 4ex;
	padding: 0;
}

a:link {
	color: #C00;
	text-decoration: none;
}

a:visited {
	color: #800;
	text-decoration: none;
}

a:link:hover, a:visited:hover {
	text-decoration: underline;
}

code {
	color: #008;
	font-style: oblique;
	padding: 0 0.25ex;
	word-spacing: 0;
	white-space: nowrap;
}

dl#biblist dt {
	clear: left;
	float: left;
	margin: 0 2ex 0 0;
	padding: 0;
}

dl#biblist dd {
	margin: 0 0 1em 0;
	padding: 0 0 0 6ex;
}

h1 {
	clear: left;
	font-size: 1.4em;
	margin: 0;
	padding: 0;
}

h2 {
	font-size: 1.6em;
	margin: 1.25em 0 0.5em 0;
	padding: 0;
}

h3 {
	font-size: 1.2em;
	font-style: italic;
	margin: 1.5em 0 0.25em 0;
	padding: 0;
}

img {
	border: 1px solid #888;
	clear: left;
	float: left;
	margin: 0 2ex 0.5em 0;
	padding: 0;
}

img:hover {
	border: 1px solid #800;
}

img.right {
	clear: right;
	float: right;
	margin: 0 0 0.5em 2ex;
}

li {
	margin: 0 0 0.5em 0;
	padding: 0;
}

ol, ul {
	margin: 1em 0;
	padding: 0 0 0 6ex;
}

p {
	margin: 0 0 0.8em 0;
}

p.abstract {
	max-width: 70ex;
}

p.footer {
	border-top: 1px solid;
	clear: left;
	margin: 2em 0 0 0;
	padding: 0.5em 2ex;
	text-align: right;
}

p.math {
	text-align: center;
}

pre {
	border-left: 1ex solid #DDD;
	color: #006;
	margin: 1.25em 0;
	padding: 0 0 0 2ex;
	word-spacing: 0;
}

var {
	font-style: italic;
	font-weight: normal;
	white-space: nowrap;
}

</style>

<style type="text/css" media="print">

body {
	border: none;
	margin: 0 auto;
	padding: 0;
}

</style>
</xsl:template>


</xsl:stylesheet>
