<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
    
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
 <xsl:template match="/">
      <h2><a name="top"><xsl:value-of select="//title"/></a></h2>
		<xsl:text>Version </xsl:text><xsl:value-of select="//articleinfo/releaseinfo"/>
      	<div class="toc">
			<h3>Table of Contents</h3>
			<ul>
			 <xsl:for-each select="//chapter">
				<li>
					<a>
						<xsl:attribute name="href">#<xsl:value-of select="./@id"/></xsl:attribute>
						<xsl:choose>
							<xsl:when test="./title">
								<xsl:value-of select="./title/text()"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="./@id"/>
							</xsl:otherwise>
						</xsl:choose>
					</a>
				<xsl:if test="./sect1">
					<ul>
					<xsl:for-each select="./sect1">
						<li>
							<a>
								<xsl:attribute name="href">#<xsl:value-of select="./@id"/></xsl:attribute>
								<xsl:value-of select="./title/text()"/>
							</a>
						</li>
					</xsl:for-each>
					</ul>
				</xsl:if>
				</li>
			 </xsl:for-each>
			 <xsl:for-each select="//appendix">
				<li>
					<a>
						<xsl:attribute name="href">#<xsl:value-of select="./@id"/></xsl:attribute>
						<xsl:choose>
							<xsl:when test="./title">
								<xsl:text>Appendix</xsl:text><xsl:value-of select="./@label"/><xsl:value-of select="./title/text()"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="./@id"/>
							</xsl:otherwise>
						</xsl:choose>
					</a>
				<xsl:if test="./sect2">
					<ul>
					<xsl:for-each select="./sect2">
						<li>
							<a>
								<xsl:attribute name="href">#<xsl:value-of select="./@id"/></xsl:attribute>
								<xsl:value-of select="./title/text()"/>
							</a>
						</li>
					</xsl:for-each>
					</ul>
				</xsl:if>
				</li>
			 </xsl:for-each>
			 </ul>
			</div>
          <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="*[@role!='xhtml']">
    </xsl:template>
    
    <xsl:template match="article//title|refentry//refname">
    </xsl:template>

	<xsl:template match="abstract">
	</xsl:template>

	<xsl:template match="email">
		<div class="email"><a href="mailto:{.}"><xsl:value-of select='.'/></a></div>
	</xsl:template>

	<xsl:template match="copyright">
		<div class="copyright">&#169;<xsl:value-of select="./year"/>&#160;<xsl:value-of select="./holder"/></div>
	</xsl:template>

    <xsl:template match="section">
        <xsl:apply-templates/>
    </xsl:template>
        
        <!-- Formatting for JUST section titles -->
        <xsl:template match="section/title">
          <h2><xsl:value-of select="."/></h2>
        </xsl:template>

        <xsl:template match="sect1|refsect1">
			<div class="sect1">
			<xsl:if test="./title">
				<h3>
					<a>
						<xsl:attribute name="name">
							<xsl:value-of select="./@id"/>
						</xsl:attribute>
						<xsl:value-of select="./title/text()"/>
					</a>
				</h3>
			</xsl:if>
				<xsl:apply-templates/>
			<a href="#top" class="top-button">Top</a>
			 </div>
        </xsl:template>
        <xsl:template match="sect2|refsect2">
			<div class="sect2">
			<xsl:if test="./title">
				<h4>
					<a>
						<xsl:attribute name="name">
							<xsl:value-of select="./@id"/>
						</xsl:attribute>
						<xsl:value-of select="./title/text()"/>
					</a>
				</h4>
			</xsl:if>
				<xsl:apply-templates/>
			 </div>
        </xsl:template>
        <xsl:template match="sect3|refsect3">
			<div class="sect3">
				<xsl:apply-templates/>
			 </div>
        </xsl:template>

 

    <xsl:template match="para">
      <p><xsl:apply-templates/></p>
    </xsl:template>

	<xsl:template match="//screenshot/mediaobject">
		<div class="screenshot">
		<xsl:for-each select="./imageobject">
			<img>
			  <xsl:attribute name="src">
				<xsl:value-of select="@fileref" />
			  </xsl:attribute>      
			</img>	
		</xsl:for-each>
		<xsl:for-each select="./caption">
			<div class="caption"><xsl:apply-templates/></div>
		</xsl:for-each>
		</div>
	</xsl:template>
	<xsl:template match="graphic|imageobject">
		<img>
		  <xsl:attribute name="src">
		  	<xsl:value-of select="@fileref" />
		  </xsl:attribute>      
		  <xsl:if test="@width">
			  <xsl:attribute name="width">
				<xsl:value-of select="@width" />
			  </xsl:attribute>
		</xsl:if>
		</img>	
	</xsl:template>
	
	<xsl:template match="author|releaseinfo">
	</xsl:template>

	<xsl:template match="ulink">
		<a>
			<xsl:attribute name="href">
			<xsl:value-of select="@url"/>
			</xsl:attribute>
			<xsl:value-of select="."/>
		</a>
	</xsl:template>
	<xsl:template match="link">
		<a>
			<xsl:attribute name="href">
			<xsl:text>#</xsl:text><xsl:value-of select="@linkend"/>
			</xsl:attribute>
			<xsl:value-of select="."/>
		</a>
	</xsl:template>
			
	<xsl:template match="variablelist">
	<dl><xsl:apply-templates/></dl>
	</xsl:template>

	<xsl:template match="variablelist//term">
		<dt><xsl:apply-templates/></dt>
	</xsl:template>
	<xsl:template match="variablelist//listitem">
		<dd><xsl:apply-templates/></dd>
	</xsl:template>

	<xsl:template match="listitem/para">
		<xsl:apply-templates/>
		</xsl:template>
	<xsl:template match="itemizedlist">
		<ul><xsl:apply-templates/></ul>
	</xsl:template>
	<xsl:template match="orderedlist">
		<ol><xsl:apply-templates/></ol>
	</xsl:template>
	<xsl:template match="listitem">
		<li><xsl:apply-templates/></li>
	</xsl:template>
	
	<xsl:template match="literal">
		<tt><xsl:value-of select="."/></tt>
	</xsl:template>
</xsl:stylesheet>