<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
	<xsl:preserve-space elements="pre"/>
	<xsl:template match="br">
		<br/>
	</xsl:template>
	<xsl:template match="img">
		<xsl:if test="not(starts-with(@src, 'javascript:'))"><img src="{@src}" alt="image"/></xsl:if>
	</xsl:template>
	<xsl:template match="sup">
		<sup><xsl:apply-templates/></sup>
	</xsl:template>
	<xsl:template match="sub">
		<sub><xsl:apply-templates/></sub>
	</xsl:template>
	<xsl:template match="e">
		<em><xsl:apply-templates/></em>
	</xsl:template>
	<xsl:template match="path">
		<code><xsl:apply-templates/></code>
	</xsl:template>
	<xsl:template match="b">
		<b><xsl:apply-templates/></b>
	</xsl:template>
	<xsl:template match="brite">
		<strong><xsl:apply-templates/></strong>
	</xsl:template>
	<xsl:template match="c">
		<kbd><xsl:apply-templates/></kbd>
	</xsl:template>
	<xsl:template match="mail">
		<xsl:choose>
			<xsl:when test="@link"><a href="mailto:{@link}"><xsl:value-of select="."/></a></xsl:when>
			<xsl:otherwise><a href="mailto:{.}"><xsl:value-of select="."/></a></xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="ul">
		<ul><xsl:apply-templates/></ul>
	</xsl:template>
	<xsl:template match="dl">
		<dl><xsl:apply-templates/></dl>
	</xsl:template>
	<xsl:template match="ol">
		<ol><xsl:apply-templates/></ol>
	</xsl:template>
	<xsl:template match="dt">
		<dt><xsl:apply-templates/></dt>
	</xsl:template>
	<xsl:template match="dd">
		<dd><xsl:apply-templates/></dd>
	</xsl:template>
	<xsl:template match="li">
		<li><xsl:apply-templates/></li>
	</xsl:template>
	<xsl:template match="uri">
		<xsl:variable name="link">
			<xsl:choose>
				<xsl:when test="@link">
					<xsl:value-of select="@link"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="."/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="starts-with($link, 'javascript:')"/>
			<xsl:when test="starts-with($link, '/')">
				<a href="{$_engineroot_}{substring($link, 2)}"><xsl:apply-templates/></a>
			</xsl:when>
			<xsl:otherwise>
				<a href="{$link}"><xsl:apply-templates/></a>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="p">
		<xsl:choose>
			<xsl:when test="@by">
				<p class="epigraph">
					<xsl:apply-templates/>
					<span class="episig"><xsl:value-of select="@by"/></span>
				</p>
			</xsl:when>
			<xsl:otherwise>
				<p><xsl:apply-templates/></p>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="chapter">
		<xsl:choose>
			<xsl:when test="@id">
				<h2 id="{@id}"><xsl:value-of select="title"/></h2>
			</xsl:when>
			<xsl:otherwise>
				<h2><xsl:value-of select="title"/></h2>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates select="section"/>
	</xsl:template>
	<xsl:template match="section">
		<xsl:if test="title">
			<xsl:choose>
				<xsl:when test="@id">
					<h3 id="{@id}"><xsl:value-of select="title"/></h3>
				</xsl:when>
				<xsl:otherwise>
					<h3><xsl:value-of select="title"/></h3>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
		<xsl:apply-templates select="body"/>
	</xsl:template>
	<xsl:template match="figure">
		<xsl:variable name="caption">
			<xsl:choose>
				<xsl:when test="@caption"><xsl:value-of select="@caption"/></xsl:when>
				<xsl:otherwise>Figure</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="short">
			<xsl:choose>
				<xsl:when test="@short"><xsl:value-of select="@short"/></xsl:when>
				<xsl:otherwise>image</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:if test="not(starts-with(@link, 'javascript:'))">
			<div class="figure">
				<xsl:value-of select="$caption"/>
				<img src="{@link}" alt="{$short}"/>
			</div>
		</xsl:if>
	</xsl:template>
	<xsl:template match="fig">
		<xsl:variable name="short">
			<xsl:choose>
				<xsl:when test="@short"><xsl:value-of select="@short"/></xsl:when>
				<xsl:otherwise>image</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:if test="not(starts-with(@link, 'javascript:'))">
			<xsl:choose>
				<xsl:when test="@linkto">
					<xsl:choose>
						<xsl:when test="starts-with(@linkto, 'javascript:')"/>
						<xsl:when test="starts-with(@linkto, '/')">
							<a href="{$_engineroot_}{substring(@linkto, 2)}"><img src="{@link}" alt="{$short}"/></a>
						</xsl:when>
						<xsl:otherwise>
							<a href="{@linkto}"><img src="{@link}" alt="{$short}"/></a>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
					<img src="{@link}" alt="{$short}"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>
	<xsl:template match="note">
		<div class="note">
			<b>Note: </b>
			<xsl:apply-templates/>
		</div>
	</xsl:template>
	<xsl:template match="impo">
		<div class="impo">
			<b>Important: </b>
			<xsl:apply-templates/>
		</div>
	</xsl:template>
	<xsl:template match="warn">
		<div class="warn">
			<b>Warning: </b>
			<xsl:apply-templates/>
		</div>
	</xsl:template>
	<xsl:template match="table">
		<table><xsl:apply-templates/></table>
	</xsl:template>
	<xsl:template match="tcolumn">
		<col width="{@width}"/>
	</xsl:template>
	<xsl:template match="tr">
		<tr>
			<xsl:if test="@id"><xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute></xsl:if>
			<xsl:apply-templates/>
		</tr>
	</xsl:template>
	<xsl:template match="ti">
		<td>
			<xsl:attribute name="align">
				<xsl:choose>
					<xsl:when test="@align">
						<xsl:value-of select="@align"/>
					</xsl:when>
					<xsl:otherwise>left</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			<xsl:if test="@colspan"><xsl:attribute name="colspan"><xsl:value-of select="@colspan"/></xsl:attribute></xsl:if>
			<xsl:if test="@rowspan"><xsl:attribute name="rowspan"><xsl:value-of select="@rowspan"/></xsl:attribute></xsl:if>
			<xsl:apply-templates/>
		</td>
	</xsl:template>
	<xsl:template match="th">
		<th>
			<xsl:attribute name="align">
				<xsl:choose>
					<xsl:when test="@align">
						<xsl:value-of select="@align"/>
					</xsl:when>
					<xsl:otherwise>left</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			<xsl:if test="@colspan"><xsl:attribute name="colspan"><xsl:value-of select="@colspan"/></xsl:attribute></xsl:if>
			<xsl:if test="@rowspan"><xsl:attribute name="rowspan"><xsl:value-of select="@rowspan"/></xsl:attribute></xsl:if>
			<xsl:apply-templates/>
		</th>
	</xsl:template>
	<xsl:template match="pre">
		<div class="pre">
			<xsl:value-of select="@caption"/>
			<pre>
				<xsl:apply-templates/>
			</pre>
		</div>
	</xsl:template>
	<xsl:template match="comment">
		<span class="code-comment"><xsl:apply-templates/></span>
	</xsl:template>
	<xsl:template match="i">
		<span class="code-input"><xsl:apply-templates/></span>
	</xsl:template>
	<xsl:template match="keyword">
		<span class="code-keyword"><xsl:apply-templates/></span>
	</xsl:template>
	<xsl:template match="ident">
		<span class="code-identifier"><xsl:apply-templates/></span>
	</xsl:template>
	<xsl:template match="const">
		<span class="code-constant"><xsl:apply-templates/></span>
	</xsl:template>
	<xsl:template match="stmt">
		<span class="code-statement"><xsl:apply-templates/></span>
	</xsl:template>
	<xsl:template match="var">
		<span class="code-variable"><xsl:apply-templates/></span>
	</xsl:template>
	<xsl:template match="/*" priority="-1">
		<xsl:message terminate="yes">guide.xsl doesn't support <xsl:value-of select="name()"/> document type</xsl:message>
	</xsl:template>
</xsl:stylesheet>


