<?xml version="1.0"?>

<!DOCTYPE xsl:stylesheet [
	<!ENTITY tableborder "#993333">
	<!ENTITY titlebg "#DDDDDD">
	<!ENTITY tablebg "#FFFFFF">
]>

<!-- 
In the <xsl:stylesheet> instruction I'm asking the XSL engine to emit the result tree as an HTML instance. I'm making the default namespace that of HTML, so no prefixes will be required on ordinary HTML elements
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
                xmlns="http://www.w3.org/TR/REC-html40"
                result-ns="">

<xsl:template match="/">                    <!--root rule-->
<HTML>
  <HEAD>
    <TITLE>
      <xsl:value-of select="/faq/title"/> by <xsl:value-of select="/faq/author/contact/name"/>
    </TITLE>
      
  </HEAD>
  <BODY BGCOLOR="#FFFFFF"  LINK="#0000ff" VLINK="#800080">

    <H1><xsl:value-of select="/faq/title"/></H1>

    <!-- maybe these items should go in a separate 
    section ("intro" or "info") -->

    <P><font size="-1">
    By <xsl:apply-templates select="/faq/author"/><BR />
    <xsl:apply-templates select="/faq/version"/><BR />
    <A href="#log">Revision History</A> is at the end of this document.
    </font></P>

    <P><font size="-1">
    The current version of this document can be found at
    <xsl:apply-templates select="/faq/location/url"/><BR />
    Please send comments, corrections, questions you want answered,
    answers you want questioned, or additional resources to
    <xsl:apply-templates select="/faq/feedback/email"/>
    </font></P>

<table border="0" bgcolor="&tableborder;" cellspacing="0" cellpadding="4">
<tr><td>
<table border="0" bgcolor="&titlebg;" cellspacing="2" cellpadding="4">
<tr><td>
<a href="http://www.jguru.com/faq/Servlets"><img src="jguru-32-purple.gif" align="left" border="0"/></a>
    <xsl:apply-templates select="/faq/intro"/>
</td></tr></table>
</td></tr></table>

    <!-- table of contents -->
<a name="toc"/>
    <H2>Table of Contents</H2>
    <xsl:apply-templates select="/faq/questionlist" mode="toc"/>
    <xsl:apply-templates select="/faq/references" mode="toc"/>

    <!-- list of questions -->
    <xsl:apply-templates select="/faq/questionlist"/>

    <!-- list of references -->
    <xsl:apply-templates select="/faq/references"/>

    <!-- footer -->
    <A name="log" />
    <H2>Revision History</H2>
    <FONT size='-1'><PRE>
    <xsl:apply-templates select="/faq/history"/>
    </PRE></FONT>
  </BODY>
</HTML>

</xsl:template>  <!-- root rule -->

<!-- basic HTML-type tags -->

<xsl:template match="ul">
<UL><xsl:apply-templates/>
</UL>
</xsl:template>

<xsl:template match="ol">
<OL><xsl:apply-templates/>
</OL>
</xsl:template>

<xsl:template match="li">
<LI><xsl:apply-templates/>
</LI>
</xsl:template>

<xsl:template match="ol/li">
<LI><xsl:apply-templates/><BR/><BR/>
</LI>
</xsl:template>

<xsl:template match="p">
<P><xsl:apply-templates/>
</P>
</xsl:template>

<xsl:template match="br">
<BR/>
</xsl:template>

<xsl:template match="b">
<B><xsl:apply-templates/></B>
</xsl:template>

<xsl:template match="i">
<I><xsl:apply-templates/></I>
</xsl:template>

<xsl:template match="mono">
<TT><xsl:apply-templates/></TT>
</xsl:template>

<xsl:template match="quote">
<BLOCKQUOTE><xsl:apply-templates/>
</BLOCKQUOTE>
</xsl:template>

<xsl:template match="table">
<TABLE border="1">
 <xsl:apply-templates/>
</TABLE>
</xsl:template>

<xsl:template match="tr">
<TR><xsl:apply-templates/></TR>
</xsl:template>

<xsl:template match="th">
<TH><xsl:apply-templates/></TH>
</xsl:template>

<xsl:template match="td">
<TD><xsl:apply-templates/></TD>
</xsl:template>

<!-- more complicated formatting tags -->
<xsl:template match="code">
<CENTER>
<TABLE BGCOLOR="&tableborder;" BORDER="0" CELLPADDING="1" CELLSPACING="0" ALIGN="CENTER">
 <TR><TD>
  <TABLE BORDER="0" CELLPADDING="6" CELLSPACING="0" BGCOLOR="#FFFFFF">
   <TR><TD><PRE><xsl:apply-templates/></PRE></TD></TR>
  </TABLE>
 </TD></TR>
</TABLE>
</CENTER>
</xsl:template>

<!-- informational content -->

<xsl:template match="contact">
<xsl:if test="url">
 <A><xsl:attribute name="href">
 <xsl:value-of select="url"/>
 </xsl:attribute><xsl:value-of select="name"/></A>
</xsl:if>
<xsl:if test="not(url)">
<xsl:value-of select="name"/>
</xsl:if>
<xsl:if test="email">
 (<xsl:apply-templates select="email"/>)
</xsl:if>
</xsl:template>

<xsl:template match="email">
<A><xsl:attribute name="href">
mailto:<xsl:value-of select="."/>
</xsl:attribute><xsl:value-of select="."/></A>
</xsl:template>

<xsl:template match="url">
<A><xsl:attribute name="href">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:value-of select="."/></A>
</xsl:template>

<!-- link -->
<xsl:template match="link">
<!-- name part -->
<xsl:choose>
 <xsl:when test="url">
<A><xsl:attribute name="href">
<xsl:value-of select="url"/>
</xsl:attribute>
<xsl:choose>
 <xsl:when test="name"><xsl:value-of select="name"/></xsl:when>
 <xsl:otherwise><xsl:value-of select="url"/></xsl:otherwise>
</xsl:choose>
</A>
 </xsl:when> <!-- url -->
 <xsl:otherwise><xsl:value-of select="name"/></xsl:otherwise>
</xsl:choose>
<!-- (contact) - comment -->
<xsl:if test="contact"> by <xsl:apply-templates select="contact"/></xsl:if>
<xsl:if test="comment"><font size="-1"> - <xsl:apply-templates select="comment"/></font></xsl:if>
<!-- list of related links -->
<xsl:if test="link">
 <ul>
 <xsl:for-each select="link">
  <li><xsl:apply-templates select="."/></li>
 </xsl:for-each>
 </ul>
</xsl:if>
</xsl:template>

<!-- faq content -->
<xsl:template match="title"/> <!-- skip -->

<xsl:template match="questionlist">
<A><xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute></A>
<H2><xsl:value-of select="@title"/></H2>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="question">
<A><xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute></A>
<H3><xsl:number/>. <xsl:value-of select="q"/></H3>
<xsl:apply-templates select="a"/>

</xsl:template> <!-- question -->

<xsl:template match="ref">
<A><xsl:attribute name="href">
#<xsl:value-of select="@id"/></xsl:attribute>
<xsl:apply-templates/>
</A>
</xsl:template>

<!-- references -->
<xsl:template match="references">
<A><xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute></A>
<H2>Resources</H2>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="section">
<A><xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute></A>
<table border="0" bgcolor="&tableborder;" cellspacing="0" cellpadding="2">
<tr><td>
<table border="0" bgcolor="&tablebg;" cellspacing="2" cellpadding="4">
<tr><td bgcolor="&titlebg;">
<b><xsl:value-of select="@title"/></b>
<xsl:if test="comment">
 <P><xsl:apply-templates select="comment"/></P>
</xsl:if>
</td></tr>
<tr><td>
<!-- <UL> -->
 <xsl:for-each select="link">
  <LI><xsl:apply-templates select="."/></LI> <br/><br/>
 </xsl:for-each>
<!-- </UL> -->
</td></tr>
</table>
</td></tr>
</table>
<br/>
</xsl:template>

<!-- table of contents -->
<xsl:template match="questionlist" mode="toc">
<H3><xsl:value-of select="@title"/></H3>
<OL>
<xsl:apply-templates mode="toc"/>
</OL>
</xsl:template>

<xsl:template match="question" mode="toc">
<LI><A><xsl:attribute name="href">
#<xsl:value-of select="@id" />
</xsl:attribute>
<xsl:value-of select="q"/>
</A>
</LI>
</xsl:template> <!-- question -->

<xsl:template match="references" mode="toc">
<H3>Resources</H3>
<UL>
 <xsl:apply-templates mode="toc"/>
</UL>
</xsl:template>

<xsl:template match="section" mode="toc">
<LI><A><xsl:attribute name="href">#<xsl:value-of select="@id"/></xsl:attribute>
 <xsl:value-of select="@title"/>
</A></LI>
</xsl:template>

</xsl:stylesheet>
