<!--

   XSLT Stylesheet Template.
   
   AUTHOR:        Leigh Dodds. 
   
   DESCRIPTION: Generates default documentation from a 
   JSP Tag library description. This could form the basis 
   for a richer set of documentation.
   
   DATE           11/1/2002

  -->
  
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>

<xsl:template match="taglib">

<html>
   <head>
      <title><xsl:value-of select="shortname"/> Tag Library, Version <xsl:value-of select="tlibversion"/></title>
   </head>
   
   <body>
      <h1><xsl:value-of select="shortname"/> Tag Library, version <xsl:value-of select="tlibversion"/></h1>   
      
      <p>
      <xsl:value-of select="info"/>
      </p>

      <xsl:call-template name="contents"/>
      
      <a name="declaration"><h2>How To Declare This Library</h2></a>
      
      <xsl:call-template name="declaration">
         <xsl:with-param name="name" select="shortname"/>
         <xsl:with-param name="theURI" select="uri"/>
      </xsl:call-template>
          
      <a name="tags"><h2>Library Tags</h2></a>

     <xsl:apply-templates select="tag">
         <xsl:sort select="name"/>
     </xsl:apply-templates>
      
   </body>
   
</html>
</xsl:template>

<xsl:template match="tag">
   <xsl:element name="a">
      <xsl:attribute name="name">
         <xsl:value-of select="name"/>
      </xsl:attribute>
      <h3><xsl:value-of select="name"/></h3>
   </xsl:element>

   <p>
   Description: <xsl:value-of select="info"/>
   </p>

   <xsl:apply-templates select="bodycontent"/>

   <p>
   Attributes:
      <table cols="3" border="1">
         <tr>
         <th>Name</th><th>Required?</th><th>Allows Scripting?</th>
         </tr>
         <xsl:apply-templates select="attribute">
           <xsl:sort select="name"/>
         </xsl:apply-templates>
      </table>
   </p>
   
</xsl:template>

<!-- interprets the body content tag -->
<xsl:template match="bodycontent">
   <p>Body:
      <xsl:variable name="type" select="text()"/>
      <xsl:choose>
         <xsl:when test="$type='jsp' or $type='JSP'">
         Can contain other JSP tags
         </xsl:when>
         <xsl:when test="$type='tagdependent' or $type='TAGDEPENDENT'">
         Contains tag specific content
         </xsl:when>
         <xsl:when test="$type='empty' or $type='EMPTY'">
         Tag has no body
         </xsl:when>
      </xsl:choose>
   </p>   
</xsl:template>

<xsl:template match="attribute">
   <tr>
      <td><b><xsl:value-of select="name"/></b></td>
      <td>
         <xsl:choose>
            <xsl:when test="required">
               <xsl:variable name="req" select="required/text()"/>
               <xsl:choose>
                  <xsl:when test="$req='true' or $req='TRUE' or $req='yes' or $req='YES'">
                  true
                  </xsl:when>
                  <xsl:when test="$req='false' or $req='FALSE' or $req='no' or $req='NO'">
                  false
                  </xsl:when>
               </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
            false
            </xsl:otherwise>
         </xsl:choose>
      </td>
      <td>
        <xsl:choose>
            <xsl:when test="rtexprvalue">
               <xsl:variable name="expr" select="rtexprvalue/text()"/>
               <xsl:choose>
                  <xsl:when test="$expr='true' or $expr='TRUE' or $expr='yes' or $expr='YES'">
                  true
                  </xsl:when>
                  <xsl:when test="$expr='false' or $expr='FALSE' or $expr='no' or $expr='NO'">
                  false
                  </xsl:when>
               </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
            false
            </xsl:otherwise>
         </xsl:choose>      
      </td>
   </tr>
</xsl:template>

<!-- generates an example taglib directive -->
<xsl:template name="declaration">
   <xsl:param name="name"/>
   <xsl:param name="theURI"/>
   
   <p>You can use this tag library by adding the following declaration to 
   your JSP pages:<br /><br />
   <code>
   &lt;%@ taglib uri="<xsl:value-of select="$theURI"/>" prefix="<xsl:value-of select="$name"/>" %&gt;
   </code>
   </p>
</xsl:template>

<xsl:template name="contents">
   <ul>
   <li><a href="#declaration">How To Declare This Library</a></li>
   <li><a href="#tags">Library Tags</a></li>
      <ul>
        <xsl:for-each select="tag">
            <xsl:sort select="name"/>
            <li><a href="#{name}"><xsl:value-of select="name"/></a></li>
        </xsl:for-each>
      </ul>
   </ul>
</xsl:template>

<!-- supress anything not explicitly matched -->
<xsl:template match="*">
</xsl:template>


</xsl:stylesheet>  