<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output 
    method="html"     
    media-type="text/html"
    indent="yes"
    encoding="UTF-8"/>
  <!-- 
     gus_xslt.xsl
     Copyright (c) Sun Feb 18 01:45:11 UTC 2007 by Gan Uesli Starling 
     Free for any use provided this notice retained in full. 
  -->
  
  <!-- BEGIN USER-DEFINED GLOBAL VARIABLES -->
  
  <!-- Set style colors -->
  <xsl:variable name="page_background_color" select="'white'"/>
  <xsl:variable name="dark_background_color" select="'moccasin'"/>
  <xsl:variable name="lite_background_color" select="'cornsilk'"/>
  <xsl:variable name="border_color" select="'darkred'"/>
  <xsl:variable name="text_bold_color" select="'maroon'"/>
  <xsl:variable name="text_note_color" select="'teal'"/>
  <xsl:variable name="text_warn_color" select="'red'"/>
  <xsl:variable name="text_cmd_color" select="'black'"/>
  <xsl:variable name="background_image_left" 
     select="'http://starling.us/images/border_brn_lh.png'"/>
  
  <!-- Set border style -->
  <!-- Cannot call $border_color var inside var def. Mozilla allowed but Xalan choked.-->
  <xsl:variable name="border_style">
    <xsl:text>border: 5px double darkred;</xsl:text>
  </xsl:variable>
  
  <!-- Cannot call $dark_background_color var, etc. inside var def. Mozilla allowed but Xalan choked.-->
  <xsl:variable name="button_style">
    <xsl:text>
      border: 2px outset darkred;
      color: black;
      background: moccasin;
      font-size: 80%; font-family: monospace;
      position: relative;
      bottom: .1em;
    </xsl:text>
  </xsl:variable> 
  
  <xsl:variable name="button_hover_style">
    <xsl:text>
      border: 2px inset black;
      color: white;
      background: firebrick;
    </xsl:text>
  </xsl:variable>
  
  <xsl:variable name="button_space">
    <xsl:text>&#160;&#160;</xsl:text>
  </xsl:variable> 
   
  <!-- Set ordination variables for OL list-style-type -->
  <xsl:variable name="list-style-1" select="'decimal'"/>
  <xsl:variable name="list-style-2" select="'upper-alpha'"/>
  <xsl:variable name="list-style-3" select="'upper-roman'"/>
  <xsl:variable name="list-style-4" select="'lower-alpha'"/>
  <xsl:variable name="list-style-5" select="'lower-roman'"/>
  <xsl:variable name="list-style-6" select="'disc'"/>
  <xsl:variable name="list-style-7" select="'circle'"/>
  <xsl:variable name="list-style-8" select="'square'"/>
  
  <!-- Set display chararacters for use in nav buttons -->
  <xsl:variable name="button_char_left" select="'&#8592;'"/>
  <xsl:variable name="button_char_up" select="'&#8593;'"/>
  <xsl:variable name="button_char_down" select="'&#8595;'"/>
  <xsl:variable name="button_char_right" select="'&#8594;'"/>
  
  <!-- END USER-DEFINED GLOBAL VARIABLES -->
  <!-- BEGIN ALL-PURPOSE GENERIC TEMPLATES -->
  
  <!-- Generic template to pass thru all attributes -->
  <xsl:template name="attribs_thru">  
    <xsl:for-each select="@*">
      <xsl:attribute name="{name()}">
        <xsl:value-of select="."/>          
      </xsl:attribute>
    </xsl:for-each>
  </xsl:template>
  
  <!-- END ALL-PURPOSE GENERIC TEMPLATES -->
  
  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
      <xsl:apply-templates select="(gus_xslt|howto)/head"/>
      <xsl:apply-templates select="(gus_xslt|howto)/body"/> 
    </html>
  </xsl:template>
  
  <xsl:template match="head">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <xsl:apply-templates select="title"/>
    <meta name="author" content="Gan Uesli Starling"/>
    <meta name="copyright" content="2006, Gan Uesli Starling"/>
    <xsl:apply-templates select="description"/>
    <xsl:apply-templates select="keywords"/>
    <xsl:apply-templates select="author"/>
    <xsl:apply-templates select="copyright"/>
    <xsl:apply-templates select="style"/>
    <link rel="alternate" type="application/atom+xml" title="Atomic Starling" href="http://starling.us/cgi-bin/gus_atom_xsl.pl?atom=starling_us_atom.xml!sort_order=Updated" />
    <style type="text/css">
        body { font-family: serif;
        <!-- Check flag attrib to see if HTML is for *.ps then *.pdf. -->
         <xsl:choose>
           <xsl:when test="//head/pdfmarks/@body='yes'"> 
             font-size: 12pt;
           </xsl:when>
           <xsl:otherwise>
             font-size: 100%;
           </xsl:otherwise>
         </xsl:choose>    
          line-height: 120%;
          color: #000000;
          <!-- Check flag attrib to see if HTML is for *.ps then *.pdf. -->
         <xsl:choose>
           <xsl:when test="//head/pdfmarks/@body='yes' and //head/pdfmarks/@ToC='no'">             
             margin-left: 2px;
             margin-right: 2px;
             margin-top: 2px;
             margin-bottom: 2px;
             background: <xsl:value-of select="$page_background_color"/>); 
           </xsl:when>
           <xsl:otherwise>             
             margin-left: 60px;
             margin-right: 20px;
             margin-top: 20px;
             margin-bottom: 20px;
             background: <xsl:value-of select="$page_background_color"/> url(<xsl:value-of select="$background_image_left"/>);
             background-image: url(<xsl:value-of select="$background_image_left"/>);
             background-repeat: repeat-y;
             background-attachment: fixed;
           </xsl:otherwise>
         </xsl:choose>            
        }
        h1 { font-family: sans-serif;
          font-weight: 700;
          font-size: 125%;
          color: <xsl:value-of select="$text_bold_color"/>; 
        } 
        h2 { font-family: sans-serif;
          font-weight: 600; 
          font-size: 115%;
          color: <xsl:value-of select="$text_bold_color"/>; 
        } 
        h3 { font-family: sans-serif;
          font-weight: 500;
          font-size: 100%;
          color: <xsl:value-of select="$text_bold_color"/>; 
        }
        h4 { font-family: sans-serif;
          font-weight: 400;
          font-size: 90%;
          color: black;
        } 
        h1.center { text-align: center;
        } 
        h2.center { text-align: center;
        }
        h3.center { text-align: center;
        }
        h4.center { text-align: center;
        } 
        h5.center { text-align: center;
        } 
        h6.center { text-align: center;
        } 
        p { text-indent: 0%;
          text-align: left;
        }
        p.right { text-indent: 0%;
          text-align: right;
        }
        p.center { text-indent: 0%;
          text-align: center;
        }
        b { color: <xsl:value-of select="$text_bold_color"/>; 
        }
        code { font-family:monospace;
          color: <xsl:value-of select="$text_bold_color"/>; 
        }
        span.cmd { color: <xsl:value-of select="$text_cmd_color"/>;
          font-weight:bold;
        }  
        span.cli { background-color: <xsl:value-of select="$lite_background_color"/>;
        }  
        span.note { color: <xsl:value-of select="$text_note_color"/>;
        }  
        span.warn { color: <xsl:value-of select="$text_warn_color"/>;
        }  
        div.note { color: <xsl:value-of select="$text_note_color"/>;
        }  
        div.warn { color: <xsl:value-of select="$text_warn_color"/>;
        }  
        <!-- Works for both MSIE 6 & Mozilla 1.2.1 -->
        hr {  height: 5px;
          color: <xsl:value-of select="$dark_background_color"/>;
          background-color: <xsl:value-of select="$dark_background_color"/>;
          border: 2px solid <xsl:value-of select="$border_color"/>;
          clear: left;
        }    
        pre { font-family:monospace;
          color:<xsl:value-of select="$text_bold_color"/>;
          background-color:<xsl:value-of select="$lite_background_color"/>;
        }  
        ol { font-size:95%;
          line-height:160%;
          margin: .1em 0em .1em 1.5em;
          padding: 0em 0em 0em 0em;
          list-style-type: decimal;
        }  
        ol { font-size:95%;
          line-height:160%;
          margin: .1em 0em .1em 1.5em;
          padding: 0em 0em 0em 0em;
          list-style-type:<xsl:value-of select="$list-style-1"/>;
        } 
        ul { font-size:95%;
          line-height:160%;
          margin:.1em 0em .1em 1.5em;
          padding: 0em 0em 0em 0em;
          list-style-type: disc;
        }
        ul ul { list-style-type: circle; }
        ul ul ul { list-style-type: square; }
        ul ul ul ul { list-style-type: ; disc}
        ul ul ul ul ul { list-style-type: circle; }
        ul ul ul ul ul ul { list-style-type: square; }
        <!-- Works for both MSIE 6 & Mozilla 1.2.1 
             Does not interfere with ToC
        -->
        table { width:auto;
          margin-left:auto;
          margin-right:auto;
          margin-bottom:.5em;
          border-collapse:collapse;
          <xsl:value-of select="$border_style"/>
        }
        <!-- Works for both MSIE 6 & Mozilla 1.2.1 -->
        table.nested {
          margin:0;
          width:100%;
          border-collapse:collapse;
          border:0px;  
        }
        <!-- Works for both MSIE 6 & Mozilla 1.2.1 -->
        table.layout { clear:both;
          width:80%;
          margin-left:10%;
          margin-right:10%;
          border:0px;
        }
        caption { padding: .3em;
          background:<xsl:value-of select="$dark_background_color"/>;
        }
        th { padding: .3em;
          background:<xsl:value-of select="$dark_background_color"/>;
        }
        td { padding: .3em;
          background:<xsl:value-of select="$lite_background_color"/>;
        }
        fieldset { background:<xsl:value-of select="$lite_background_color"/>;
        }
        sup sub { font-size:80%;
        } 
        img { border: 0px;
        }
        a:link { color: #0000bb;
          text-decoration: none;
        } 
        a:visited { color: #0000bb;
          text-decoration: none;
        } 
        a:active {  color: #800000;
          text-decoration: none;
        }     
        a.button { <xsl:value-of select="$button_style"/>
        }
        a:hover { <xsl:value-of select="$button_hover_style"/> 
        }
      </style>
      <script type="text/javascript" src="./external_links.js">
      </script>
    </head>
  </xsl:template>
  
  <xsl:template match="head/title">
    <title>
      <xsl:value-of select="."/>
    </title>
  </xsl:template>
  
  <xsl:template match="head/description">
    <meta name="description">
      <xsl:attribute name="content">
        <xsl:value-of select="."/>          
      </xsl:attribute>
    </meta>
  </xsl:template>
  
  <xsl:template match="head/keywords">
    <meta name="keywords">
      <xsl:attribute name="content">
        <xsl:value-of select="."/>          
      </xsl:attribute>
    </meta>
  </xsl:template>
  
  <xsl:template match="head/author">
    <meta name="author">
      <xsl:attribute name="content">
        <xsl:value-of select="."/>          
      </xsl:attribute>
    </meta>
  </xsl:template>
  
  <xsl:template match="head/copyright">
    <meta name="copyright">
      <xsl:attribute name="content">
        <xsl:value-of select="."/>          
      </xsl:attribute>
    </meta>
  </xsl:template>
  
  <xsl:template match="head/style">
    <style type="text/css">
      <xsl:value-of select="."/>
    </style>
  </xsl:template>
  
  <xsl:template match="head/link">
    <link rel="{@rel}" href="{@href}" type="{@type}"/>                         <!-- TEST THIS 2007-02-15 -->
  </xsl:template>
  
  <xsl:template match="body">
    <body>
      <!-- Make table of contents unless flagged not to by XML /head/navigation@ToC attribute -->
      <xsl:choose>
        <xsl:when test="//head/navigation/@ToC='no'">
          <!-- Default is to show navigation. But skip if 'no'. -->
        </xsl:when>
        <xsl:otherwise>
          <div>
            <xsl:attribute name="style">
              <xsl:text>
                float:right;
                margin: 0em 0em 1em 1em;
                padding: 0em 1em .2em 1em;
                background-color:
              </xsl:text>
              <xsl:value-of select="$lite_background_color"/>
              <xsl:text>;</xsl:text>
              <xsl:value-of select="$border_style"/>
            </xsl:attribute>
            <xsl:call-template name="ToC"/>
          </div>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates select="title"/>
      <xsl:apply-templates select="*[not(self::title) and not(self::section)]"/>
      <hr />
      <xsl:apply-templates select="section"/>
    </body>
  </xsl:template>
  
  <xsl:template match="body/title">
    <div style="margin: 1em .5em 1em .5em;">
      <h1 class="center">
        <xsl:value-of select="."/>
      </h1>
    </div>
  </xsl:template>
  
  <xsl:template name="ToC"> 
    <!-- Show Atom feed icon if page is syndicated -->
    <xsl:if test="//head/syndication">
      <div style="margin-left:auto;width:51px;margin-right:auto;padding-top:20px;">
        <a href="{//head/syndication/@atom}" type="application/atom+xml" rel="external">
          <img src="http://starling.us/images/button_atom.png" 
            title="Atom feed syndication link" 
            alt="Atom Feed" 
            height="17" width="51" />  
        </a>
      </div>
    </xsl:if>
    <h3> 
        <xsl:value-of select="//head/navigation/@ToC"/>
    </h3>
    <xsl:call-template name="ToC_section"/>
  </xsl:template>
   
  <xsl:template name="ToC_section">
    <xsl:if test="section">
      <!-- Create links for section in ToC -->
      <ol style="font-size:85%;font-height:120%;">
        <xsl:for-each select="section">
          <li>
            <a>
              <xsl:attribute name="href">
                <xsl:text>#GUS-</xsl:text>
                <xsl:value-of select="position()"/>
              </xsl:attribute>
              <xsl:call-template name="ToC_title"/>                           
            </a>
            <!-- Show ToC entry unless flagged otherwise in /head/navigation@topic -->
            <xsl:choose>
              <xsl:when test="//head/navigation/@topic='no'">
                <!-- Default is to show navigation. But skip if 'no'. -->
              </xsl:when>
              <xsl:otherwise>
                <xsl:call-template name="ToC_topic"/>
              </xsl:otherwise>
            </xsl:choose>
          </li>
        </xsl:for-each>
      </ol>
    </xsl:if>
  </xsl:template>
   
  <xsl:template name="ToC_topic">
    <xsl:if test="topic">
      <!-- Create links for section-topic in ToC -->    
      <xsl:variable name="section-pos">
        <xsl:value-of select="position()"/>
      </xsl:variable>  
      <ol>
        <xsl:attribute name="style">
          <xsl:text>list-style-type:</xsl:text>
          <xsl:value-of select="$list-style-2"/>
          <xsl:text>;</xsl:text>
        </xsl:attribute>
        <xsl:for-each select="topic">
          <li>
            <a>
              <xsl:attribute name="href">
                <xsl:text>#GUS-</xsl:text>
                <xsl:value-of select="$section-pos"/>
                <xsl:text>-</xsl:text>    
                <xsl:variable name="topic-pos">
                  <xsl:value-of select="position()"/>
                </xsl:variable>  
                <xsl:value-of select="$topic-pos"/>
              </xsl:attribute>
              <xsl:call-template name="ToC_title"/>                             
            </a>
            <!-- Show ToC entry unless flagged otherwise in /head/navigation@subtopic -->
            <xsl:choose>
              <xsl:when test="//head/navigation/@subtopic='no'">
                <!-- Default is to show navigation. But skip if 'no'. -->
              </xsl:when>
              <xsl:otherwise>
                <xsl:call-template name="ToC_subtopic">
                  <xsl:with-param name="section-pos" select="$section-pos"/>
                </xsl:call-template>
              </xsl:otherwise>
            </xsl:choose>
          </li>
        </xsl:for-each>
      </ol>    
    </xsl:if>
  </xsl:template>
   
  <xsl:template name="ToC_subtopic">
    <xsl:param name="section-pos"/>
    <xsl:if test="subtopic">
      <!-- Create links for section-topic-subtopic in ToC -->    
      <xsl:variable name="topic-pos">
        <xsl:value-of select="position()"/>
      </xsl:variable>  
      <ol>
        <xsl:attribute name="style">
          <xsl:text>list-style-type:</xsl:text>
          <xsl:value-of select="$list-style-3"/>
          <xsl:text>;</xsl:text>
        </xsl:attribute>
        <xsl:for-each select="subtopic">
          <li>
            <a>
              <xsl:attribute name="href">
                <xsl:text>#GUS-</xsl:text>
                <xsl:value-of select="$section-pos"/>
                <xsl:text>-</xsl:text>
                <xsl:value-of select="$topic-pos"/>
                <xsl:text>-</xsl:text>
                <xsl:value-of select="position()"/>
              </xsl:attribute>
              <xsl:call-template name="ToC_title"/>  
            </a>
            <!-- Show nav buttons unless flagged otherwise in /head/navigation@subsubtopic -->
            <xsl:choose>
              <xsl:when test="//head/navigation/@subsubtopic='no'">
                <!-- Default is to show navigation. But skip if 'no'. -->
              </xsl:when>
              <xsl:otherwise>
                <xsl:call-template name="ToC_subsubtopic">
                  <xsl:with-param name="section-pos" select="$section-pos"/>
                  <xsl:with-param name="topic-pos" select="$topic-pos"/>
                </xsl:call-template>
              </xsl:otherwise>
            </xsl:choose>
          </li>
        </xsl:for-each>
      </ol>   
    </xsl:if>
  </xsl:template>
   
  <xsl:template name="ToC_subsubtopic">
    <xsl:param name="section-pos"/>
    <xsl:param name="topic-pos"/>
    <xsl:if test="subsubtopic">
      <!-- Create links for section-topic-subtopic-subsubtopic in ToC -->    
      <xsl:variable name="subtopic-pos">
        <xsl:value-of select="position()"/>
      </xsl:variable>  
      <ol>
        <xsl:attribute name="style">
          <xsl:text>list-style-type:</xsl:text>
          <xsl:value-of select="$list-style-4"/>
          <xsl:text>;</xsl:text>
        </xsl:attribute>
        <xsl:for-each select="subsubtopic">
          <li>
            <a>
              <xsl:attribute name="href">
                <xsl:text>#GUS-</xsl:text>
                <xsl:value-of select="$section-pos"/>
                <xsl:text>-</xsl:text>
                <xsl:value-of select="$topic-pos"/>
                <xsl:text>-</xsl:text>
                <xsl:value-of select="$subtopic-pos"/>
                <xsl:text>-</xsl:text>
                <xsl:value-of select="position()"/>
              </xsl:attribute>
              <xsl:call-template name="ToC_title"/>  
            </a>
          </li>
        </xsl:for-each>
      </ol>
    </xsl:if>
  </xsl:template>  
              
  <xsl:template name="ToC_title">
    <!-- Allow for shorter title in the TOC if full title too long --> 
    <xsl:choose>  
      <xsl:when test="title/@toc">
        <xsl:value-of select="title/@toc"/>
      </xsl:when>  
      <xsl:otherwise>
        <xsl:value-of select="title"/>
      </xsl:otherwise>  
    </xsl:choose>  
  </xsl:template>
    
  <xsl:template match="body/section">  
    <xsl:if test="position() != 1">
      <hr>
        <!-- So can do style="clear:both" on section -->
        <xsl:call-template name="attribs_thru"/>
      </hr>
    </xsl:if>
    <h2 class="center">
      <!-- Create in-bound anchor links if needed -->
      <xsl:apply-templates select="inlink"/>
      <!-- Insert an anchor for the for this position -->
      <a>
        <xsl:attribute name="id">
          <xsl:text>GUS-</xsl:text>
          <xsl:value-of select="position()"/>
        </xsl:attribute>
        <xsl:apply-templates select="title"/>
      </a>
      <!-- Show nav buttons unless flagged otherwise in /head/navigation@section -->
      <xsl:choose>
        <xsl:when test="//head/navigation/@section='no'">
          <!-- Default is to show navigation -->
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="section_nav"/>
        </xsl:otherwise>
      </xsl:choose>
    </h2>
    <xsl:apply-templates select="*[not(self::topic) and not(self::title)]"/>
    <xsl:if test="topic">
      <ol>
        <xsl:attribute name="style">
          <xsl:text>list-style-type:</xsl:text>
          <xsl:value-of select="$list-style-2"/>
          <xsl:text>;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates select="topic"/>
      </ol>
    </xsl:if>
  </xsl:template>
  
  <xsl:template match="section/topic">
    <li> 
      <h3>
        <!-- Create in-bound anchor links if needed -->
        <xsl:apply-templates select="inlink"/>
        <!-- Create anchor for section-topic -->
        <a>
          <xsl:attribute name="id">
            <xsl:text>GUS-</xsl:text>
            <xsl:number level="multiple" count="section | topic" format="1-1"/>
          </xsl:attribute>
        </a>

        <xsl:apply-templates select="title"/>
        <!-- Show nav buttons unless flagged otherwise in /head/navigation@topic -->
        <xsl:choose>
          <xsl:when test="//head/navigation/@topic='no'">
            <!-- Default is to show navigation. But skip if 'no'. -->
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="topic_nav"/>
          </xsl:otherwise>
        </xsl:choose>
      </h3>
      <xsl:apply-templates select="*[not(self::subtopic) and not(self::title)]"/>
      <xsl:if test="subtopic">
        <ol>
          <xsl:attribute name="style">
            <xsl:text>list-style-type:</xsl:text>
            <xsl:value-of select="$list-style-3"/>
            <xsl:text>;</xsl:text>
          </xsl:attribute>
          <xsl:apply-templates select="subtopic"/>
        </ol>
      </xsl:if>
    </li>      
  </xsl:template>
  
  <xsl:template match="topic/subtopic">
    <li> 
      <h3>
        <!-- Create in-bound anchor links if needed -->
        <xsl:apply-templates select="inlink"/>
        <!-- Create anchor for section-topic from ToC -->
        <a>
          <xsl:attribute name="id">
            <xsl:text>GUS-</xsl:text>
            <xsl:number level="multiple" count="section | topic | subtopic" format="1-1-1"/>
          </xsl:attribute>
        </a>
        <xsl:apply-templates select="title"/>
        <!-- Show nav buttons unless flagged otherwise in /head/navigation@subtopic -->
        <xsl:choose>
          <xsl:when test="//head/navigation/@subtopic='no'">
            <!-- Default is to show navigation. But skip if 'no'. -->
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="subtopic_nav"/>
          </xsl:otherwise>
        </xsl:choose>
      </h3>
      <xsl:apply-templates select="*[not(self::subsubtopic) and not(self::title)]"/>
      <xsl:if test="subsubtopic">
        <ol>
          <xsl:attribute name="style">
            <xsl:text>list-style-type:</xsl:text>
            <xsl:value-of select="$list-style-4"/>
            <xsl:text>;</xsl:text>
          </xsl:attribute>
          <xsl:apply-templates select="subsubtopic"/>
        </ol> 
      </xsl:if>
    </li>
  </xsl:template>
  
  <xsl:template match="subtopic/subsubtopic">
    <li> 
      <h3>
        <!-- Create in-bound anchor links if needed -->
        <xsl:apply-templates select="inlink"/>
        <!-- Create anchor for section-topic from ToC -->
        <a>
          <xsl:attribute name="id">
            <xsl:text>GUS-</xsl:text>
            <xsl:number level="multiple"
              count="section | topic | subtopic | subsubtopic" format="1-1-1-1"/>
          </xsl:attribute>
        </a>
        <xsl:apply-templates select="title"/>
        <!-- Show nav buttons unless flagged otherwise in /head/navigation@subsubtopic -->
        <xsl:choose>
          <xsl:when test="//head/navigation/@subsubtopic='no'">
          <!-- Default is to show navigation. But skip if 'no'. -->
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="subsubtopic_nav"/>
          </xsl:otherwise>
        </xsl:choose>
      </h3>
      <xsl:apply-templates select="*[not(self::title)]"/>
    </li>
  </xsl:template>
  
  <xsl:template match="title">
      <xsl:apply-templates/>
  </xsl:template>
  
  <!-- image rows -->
  
  <xsl:template match="images">
    <table class="layout">
      <tr>
        <xsl:apply-templates select="img"/>
      </tr>
    </table>
  </xsl:template>
  
  <!-- pass-through templates -->
  
  <xsl:template match="span">
    <span>
      <xsl:call-template name="attribs_thru"/>
      <xsl:copy-of select="node()"/>
    </span>
  </xsl:template>
  
  <xsl:template match="div">
    <div>
      <xsl:call-template name="attribs_thru"/>
      <xsl:copy-of select="node()"/>
    </div>
  </xsl:template>
  
  <xsl:template match="form">
    <form>
      <xsl:call-template name="attribs_thru"/>
      <xsl:copy-of select="node()"/>
    </form>
  </xsl:template>
  
  <!-- paragraph templates -->
  
  <xsl:template match="p">
    <p>
      <xsl:call-template name="attribs_thru"/>
      <xsl:apply-templates/>
    </p>
  </xsl:template>
  
  <xsl:template match="a">
    <!-- Make link unless flagged not to by XML /head/navigation@ToC attribute -->
    <xsl:choose>
      <xsl:when test="//head/navigation/@links='no'">
        <!-- Default is to show navigation. But skip if 'no'. -->
      </xsl:when>
      <xsl:otherwise>
        <a>
          
          <!-- Provide a pop-up title showing link path -->
          <xsl:attribute name="title">
            <xsl:value-of select="./@href"/>
          </xsl:attribute>

          <!-- Make external links into buttons -->
          <xsl:if test="contains(@href,'http') and not(@class='no_button')">
            <xsl:attribute name="class">
              <xsl:text>button</xsl:text>
            </xsl:attribute>
          </xsl:if> 

          <!-- Pass through any defined attributes even of overwrites the two above. -->
          <xsl:call-template name="attribs_thru"/> 

          <!-- Prevent button border from crowding the text on left side -->
          <!-- Does not work when nested together with the button test -->
          <!-- All URLs have a dot somewhere: Aboslute, Relative, Email, etc -->
          <xsl:if test="contains(@href,'.') and not(@class='no_button')">
            <xsl:text>&#160;</xsl:text>
          </xsl:if>
          
          <xsl:apply-templates/>   

          <!-- Repeat of test before last, but for right side of text. -->
          <xsl:if test="contains(@href,'.') and not(@class='no_button')">
            <xsl:text>&#160;</xsl:text>
          </xsl:if>

        </a>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template match="inlink">
    <!-- Make in-bound link unless flagged not to by XML /head/navigation@ToC attribute -->
    <xsl:choose>
      <xsl:when test="//head/navigation/@links='no'">
        <!-- Default is to show navigation. But skip if 'no'. -->
      </xsl:when>
      <xsl:otherwise>
        <a>
          <xsl:attribute name="id">
            <xsl:value-of select="."/>
          </xsl:attribute>
        </a>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template match="pdf">
    <xsl:if test="//head/pdfmarks/@body='yes'">
      <xsl:apply-templates/>
    </xsl:if>
  </xsl:template>
  
  <xsl:template match="br">
    <br />
  </xsl:template>
  
  <xsl:template match="smaller">
    <span style="font-size:smaller;font-weight:heavy;">
      <xsl:apply-templates/>
    </span>
  </xsl:template>
  
  <xsl:template match="b">
    <b>
      <xsl:call-template name="attribs_thru"/>
      <xsl:apply-templates/>
    </b>
  </xsl:template>
  
  <xsl:template match="i">
    <i>
      <xsl:call-template name="attribs_thru"/>
      <xsl:apply-templates/>
    </i>
  </xsl:template>
  
  <xsl:template match="pre">
    <pre>
      <!-- Style 'cmd' is for commands entered in block of code -->
      <xsl:apply-templates select="cmd|note|span|warn|text()"/>
    </pre>
  </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="code">
    <code>
      <xsl:apply-templates/>
    </code>
  </xsl:template>
  
  <xsl:template match="cmd">
    <span class="cmd">
      <xsl:apply-templates/>
    </span>
  </xsl:template>
  
  <xsl:template match="cli">
    <span class="cli">
      <code>
        <xsl:apply-templates/>
      </code>
    </span>
  </xsl:template>
  
  <xsl:template match="note">
    <span class="note">
      <xsl:apply-templates/>
    </span>
  </xsl:template>
  
  <xsl:template match="warn">
    <span class="warn">
      <xsl:apply-templates/>
    </span>
  </xsl:template>
  
  <xsl:template match="text()">
    <xsl:value-of select="."/>
  </xsl:template>
  
  <!-- table templates -->
  
  <xsl:template match="table">
    <table border="2">
      <xsl:call-template name="attribs_thru"/>
      <xsl:apply-templates select="caption"/>
      <xsl:apply-templates select="tr"/>
    </table>
  </xsl:template>
  
  <xsl:template match="caption">
    <caption>  
      <xsl:call-template name="attribs_thru"/>
      <xsl:copy-of select="node()"/>
    </caption>
  </xsl:template>
  
  <xsl:template match="tr">
    <tr>   
      <xsl:call-template name="attribs_thru"/>
      <xsl:apply-templates select="th"/>
      <xsl:apply-templates select="td"/>
    </tr>
  </xsl:template>
  
  <xsl:template match="th">
    <th>   
      <xsl:call-template name="attribs_thru"/>
      <xsl:copy-of select="node()"/>
    </th>
  </xsl:template>
  
  <xsl:template match="td">
    <td align="center" valign="middle">   
      <xsl:call-template name="attribs_thru"/>
      <xsl:choose>
        <xsl:when test="table">
          <xsl:attribute name="style">
            <xsl:text>margin:0px;padding:0px;</xsl:text>
          </xsl:attribute>
          <xsl:apply-templates select="table"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:copy-of select="node()"/>
        </xsl:otherwise>
      </xsl:choose>
    </td>
  </xsl:template>
  
  <xsl:template match="td/table" > 
    <table class="nested" border="2">
      <xsl:apply-templates select="tr"/>
    </table>
  </xsl:template>
  
  <xsl:template match="img">
    <td style="background:none;">
    <div style="width:auto;margin-left:auto;margin-right:auto;">
    <xsl:choose>        
    
      <!-- Presence of link attribute triggers cgi form or link anchor -->
      <xsl:when test="@href">  
        <xsl:choose>
          <xsl:when test="//head/cgi/@img='yes'"> 
            <form method="post">
            <xsl:attribute name="action">            
              <xsl:value-of select="//head/cgi/@img_action"/>  
            </xsl:attribute>  
            <p style="text-align:center;font-size:60%;">  
            
              <!-- Caption for the larger images -->              
              <input type="hidden" name="caption">
                <xsl:attribute name="value">
                  <xsl:value-of select="@caption"/>
                </xsl:attribute>
              </input>
          
              <!-- Mid-size image, itself a thumb for largest image -->
              <input type="image" name="thumb">
                <xsl:attribute  name="src">
                  <xsl:value-of select="@src"/>
                </xsl:attribute>
              </input>
          
              <!-- Full-size image, itself a thumb back to TGP -->
              <input type="hidden" name="photo">
                <xsl:attribute name="value">
                  <xsl:value-of select="//head/cgi/@img_path"/>
                  <xsl:value-of select="@href"/>
                </xsl:attribute>
              </input>
          
              
      
              <!-- Show the caption below the image -->
              <xsl:if test="string-length(node()) > 0">                  
                <br />
                <xsl:copy-of select="node()"/>            
              </xsl:if>
            </p>
          </form>
        </xsl:when>
      
        <!-- Absense of cgi flag triggers ordinary link image -->
        <xsl:otherwise>
          <p style="text-align:center;text-indent:0px;font-size:90%;">
            <a rel="external">
              <xsl:attribute name="href">
                <xsl:value-of select="@href"/>
              </xsl:attribute>
              <img alt="graphic">
                <xsl:attribute name="src">
                  <xsl:value-of select="@src"/>
                </xsl:attribute>
              </img>
      
              <!-- Show the caption below the image -->
              <xsl:if test="string-length(node()) > 0">                  
                <br />
                <xsl:copy-of select="node()"/>            
              </xsl:if>
            </a>
          </p>
        </xsl:otherwise>      
      </xsl:choose>
    </xsl:when>
  
    <!-- Absense of link attribute triggers bare image -->
    <xsl:otherwise>
      <p style="text-align:center;text-indent:0px;font-size:90%;">
        <img alt="graphic">
          <xsl:attribute name="src">
            <xsl:value-of select="@src"/>
          </xsl:attribute>
        </img>  
      
        <!-- Show the caption below the image -->
        <xsl:if test="string-length(node()) > 0">                  
          <br />
          <xsl:copy-of select="node()"/>            
        </xsl:if>
      </p>
    </xsl:otherwise>
        </xsl:choose>
      </div>
    </td>
  </xsl:template>
  
  <xsl:template match="ol">
    <xsl:variable name="strata">
      <xsl:number count="ol" from="section|topic|subtopic|subsubtopic" level="any"/>
    </xsl:variable>
    <ol>
      <xsl:attribute name="style">
        <xsl:text>list-style-type: </xsl:text>
        <xsl:choose>  
          <xsl:when test="$strata mod 8 = 1">
            <xsl:value-of select="$list-style-1"/>
          </xsl:when>
          <xsl:when test="$strata mod 8 = 2">
            <xsl:value-of select="$list-style-2"/>
          </xsl:when>
          <xsl:when test="$strata mod 8 = 3">
            <xsl:value-of select="$list-style-3"/>
          </xsl:when>
          <xsl:when test="$strata mod 8 = 4">
            <xsl:value-of select="$list-style-4"/>
          </xsl:when>
          <xsl:when test="$strata mod 8 = 5">
            <xsl:value-of select="$list-style-5"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$list-style-1"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>;</xsl:text>
        <xsl:if test="$strata &gt; 6">
          <xsl:text>font-size: 100%;</xsl:text>
        </xsl:if>
      </xsl:attribute>            
      <xsl:call-template name="attribs_thru"/>
      <xsl:apply-templates/>
    </ol>
  </xsl:template>
  
  <xsl:template match="ul">
    <ul>
      <xsl:call-template name="attribs_thru"/>
      <xsl:apply-templates/>
    </ul>
  </xsl:template>
  
  <xsl:template match="li">
    <li>          
      <xsl:call-template name="attribs_thru"/>
      <xsl:apply-templates/>
    </li>
  </xsl:template>

  <!-- Begin NAVIGATION widgets -->
  
  <xsl:template name="section_nav">
    <!-- Offset buttons by some whitespace -->
    <xsl:text>&#160;&#160;</xsl:text>
    <!-- Remember the positions for levels above -->
    <xsl:variable name="super_pos">
      <xsl:text>#GUS-</xsl:text>
    </xsl:variable>
    <xsl:call-template name="nav_buttons">
      <xsl:with-param name="super_pos" select="$super_pos"/>
      <xsl:with-param name="prev_title" select="preceding-sibling::section[1]/title"/>
      <xsl:with-param name="next_title" select="following-sibling::section/title"/>
      <xsl:with-param name="rise_title" select="../title"/>
      <xsl:with-param name="sink_title" select="./topic/title"/>
    </xsl:call-template>
  </xsl:template>
  
  <xsl:template name="topic_nav">
    <!-- Offset buttons by some whitespace -->
    <xsl:text>&#160;&#160;</xsl:text>
    <!-- Remember the positions for levels above -->
    <xsl:variable name="super_pos">
      <xsl:text>#GUS-</xsl:text>
      <xsl:number level="multiple" count="section" format="1"/>
    </xsl:variable>
    <xsl:call-template name="nav_buttons">
      <xsl:with-param name="super_pos" select="$super_pos"/>
      <xsl:with-param name="prev_title" select="preceding-sibling::topic[1]/title"/>
      <xsl:with-param name="next_title" select="following-sibling::topic/title"/>
      <xsl:with-param name="rise_title" select="../title"/>
      <xsl:with-param name="sink_title" select="./subtopic/title"/>
    </xsl:call-template>
  </xsl:template>
  
  <xsl:template name="subtopic_nav">
    <!-- Offset buttons by some whitespace -->
    <xsl:text>&#160;&#160;</xsl:text>
    <!-- Remember the positions for levels above -->
    <xsl:variable name="super_pos">
      <xsl:text>#GUS-</xsl:text>
      <xsl:number level="multiple" count="section | topic" format="1-1"/>
    </xsl:variable>
    <xsl:call-template name="nav_buttons">
      <xsl:with-param name="super_pos" select="$super_pos"/>
      <xsl:with-param name="prev_title" select="preceding-sibling::subtopic[1]/title"/>
      <xsl:with-param name="next_title" select="following-sibling::subtopic/title"/>
      <xsl:with-param name="rise_title" select="../title"/>
      <xsl:with-param name="sink_title" select="./subsubtopic/title"/>
    </xsl:call-template>
  </xsl:template>
  
  <xsl:template name="subsubtopic_nav">
    <!-- Offset buttons by some whitespace -->
    <xsl:text>&#160;&#160;</xsl:text>
    <!-- Remember the positions for levels above -->
    <xsl:variable name="super_pos">
      <xsl:text>#GUS-</xsl:text>
      <xsl:number level="multiple" count="section | topic | subtopic" format="1-1-1"/>
    </xsl:variable>
    <xsl:call-template name="nav_buttons">
      <xsl:with-param name="super_pos" select="$super_pos"/>
      <xsl:with-param name="prev_title" select="preceding-sibling::subsubtopic[1]/title"/>
      <xsl:with-param name="next_title" select="following-sibling::subsubtopic/title"/>
      <xsl:with-param name="rise_title" select="../title"/>
      <xsl:with-param name="sink_title" select="'NOT_USED'"/>
    </xsl:call-template>
  </xsl:template>
  
  <xsl:template name="nav_buttons">
    <xsl:param name="super_pos"/>
    <xsl:param name="prev_title"/>
    <xsl:param name="next_title"/>
    <xsl:param name="rise_title"/>
    <xsl:param name="sink_title"/>
    <!-- Insert a back anchor if not first position -->
    <xsl:call-template name="nav_button_left">
      <xsl:with-param name="super_pos" select="$super_pos"/>
      <xsl:with-param name="title" select="$prev_title"/>
    </xsl:call-template>
    <!-- Insert a anchor for super-nested position -->
    <xsl:call-template name="nav_button_up">
      <xsl:with-param name="super_pos" select="$super_pos"/>
      <xsl:with-param name="title" select="$rise_title"/>
    </xsl:call-template>
    <!-- Insert a anchor for sub-nested position -->
    <xsl:call-template name="nav_button_down">
      <xsl:with-param name="super_pos" select="$super_pos"/>
      <xsl:with-param name="title" select="$sink_title"/>
    </xsl:call-template>
    <!-- Insert a next anchor if not last position -->
    <xsl:call-template name="nav_button_right">
      <xsl:with-param name="super_pos" select="$super_pos"/>
      <xsl:with-param name="title" select="$next_title"/>
    </xsl:call-template>
  </xsl:template>
  
  <xsl:template name="nav_button_left">
    <xsl:param name="super_pos"/>
    <xsl:param name="title"/>
    <!-- No left button if already earliest sibling node -->
    <xsl:if test="position() &gt; 1">
      <xsl:text>&#160;&#160;</xsl:text>
      <a class="button">
        <xsl:attribute name="title">
            <xsl:value-of select="$title"/>
        </xsl:attribute>
        <xsl:attribute name="href">
          <xsl:value-of select="$super_pos"/>
          <xsl:if test="$super_pos != '#GUS-'">
            <xsl:text>-</xsl:text>
          </xsl:if>
          <xsl:value-of select="position() - 1"/>
        </xsl:attribute>
        <xsl:text>&#160;</xsl:text>
        <xsl:value-of select="$button_char_left"/>
        <xsl:text>&#160;</xsl:text>
      </a>
    </xsl:if>
  </xsl:template>
  
  <xsl:template name="nav_button_up">
    <xsl:param name="super_pos"/>
    <xsl:param name="title"/>
    <xsl:text> </xsl:text>    
    <a class="button">
      <xsl:attribute name="title">
        <xsl:value-of select="$title"/>
      </xsl:attribute>
      <xsl:attribute name="href">
        <xsl:choose>
          <xsl:when test="$super_pos = '#GUS-'">
            <xsl:text>#</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$super_pos"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xsl:text>&#160;</xsl:text>
      <xsl:value-of select="$button_char_up"/>
      <xsl:text>&#160;</xsl:text>
    </a>
  </xsl:template>
  
  <xsl:template name="nav_button_down">
    <xsl:param name="super_pos"/>
    <xsl:param name="title"/>
    <!-- No down button if child node not present -->
    <xsl:if test="topic | subtopic | subsubtopic">
      <xsl:text> </xsl:text>    
      <a class="button">
        <xsl:attribute name="title">
          <xsl:value-of select="$title"/>
        </xsl:attribute>
        <xsl:attribute name="href">
          <xsl:value-of select="$super_pos"/>
          <!-- No dash between section id and pound sign -->
          <xsl:if test="$super_pos != '#GUS-'">
            <xsl:text>-</xsl:text>
          </xsl:if>
          <xsl:value-of select="position()"/>
          <xsl:text>-1</xsl:text>
        </xsl:attribute>
        <xsl:text>&#160;</xsl:text>
        <xsl:value-of select="$button_char_down"/>
        <xsl:text>&#160;</xsl:text>
      </a>
    </xsl:if>
  </xsl:template>
  
  <xsl:template name="nav_button_right">
    <xsl:param name="super_pos"/>
    <xsl:param name="title"/>
    <!-- No right button if sibling node not present -->
    <xsl:if test="position() != last()">
      <xsl:text> </xsl:text>
      <a class="button">
        <xsl:attribute name="title">
            <xsl:value-of select="$title"/>
        </xsl:attribute>
        <xsl:attribute name="href">
          <xsl:value-of select="$super_pos"/>
          <xsl:if test="$super_pos != '#GUS-'">
            <xsl:text>-</xsl:text>
          </xsl:if>
          <xsl:value-of select="position() + 1"/>
        </xsl:attribute>
        <xsl:text>&#160;</xsl:text>
        <xsl:value-of select="$button_char_right"/>
        <xsl:text>&#160;</xsl:text>
      </a>
    </xsl:if>
  </xsl:template>
  
  <xsl:template name="button_style">
    <xsl:attribute name="style">
      <xsl:value-of select="$button_style"/>
    </xsl:attribute>
  </xsl:template>

  <!-- End NAVIGATION widets -->

</xsl:stylesheet>

