home *** CD-ROM | disk | FTP | other *** search
/ hobbes.nmsu.edu 2008 / 2008-06-02_hobbes.nmsu.edu.zip / new / scummc-0.2.0-os2.zip / ScummC / manual / html.xslt < prev    next >
Encoding:
Extensible Markup Language  |  2008-02-03  |  9.1 KB  |  297 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  ScummC
  4.  Copyright (C) 2008  Alban Bedel
  5.  
  6.  This program is free software; you can redistribute it and/or
  7.  modify it under the terms of the GNU General Public License
  8.  as published by the Free Software Foundation; either version 2
  9.  of the License, or (at your option) any later version.
  10.  
  11.  This program is distributed in the hope that it will be useful,
  12.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  GNU General Public License for more details.
  15.  
  16.  You should have received a copy of the GNU General Public License
  17.  along with this program; if not, write to the Free Software
  18.  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  19. -->
  20. <xsl:stylesheet version="1.0"
  21.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  22.                 xmlns="http://www.w3.org/1999/xhtml">
  23.  
  24.   <xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes'
  25.     doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  26.     doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
  27.  
  28.   <!-- The whole HTML document -->
  29.   <xsl:template match="/">
  30.     <html>
  31.       <head>
  32.         <title>
  33.           <xsl:value-of select="man/@name"/>
  34.           <xsl:text> - </xsl:text>
  35.           <xsl:value-of select="man/@long-name"/>
  36.         </title>
  37.         <link rel="stylesheet" type="text/css" href="man.css"/>
  38.       </head>
  39.       <body>
  40.         <xsl:apply-templates/>
  41.       </body>
  42.     </html>
  43.   </xsl:template>
  44.  
  45.   <!-- Write the body -->
  46.   <xsl:template match="man">
  47.     <div class="man">
  48.       <!-- TOC -->
  49.       <div class="toc">
  50.         <div class="toc-entry">
  51.           <a href="#name">name</a>
  52.         </div>
  53.         <div class="toc-entry">
  54.           <a href="#synopsis">synopsis</a>
  55.         </div>
  56.         <xsl:apply-templates mode="part-toc"/>
  57.       </div>
  58.       <!-- CONTENT -->
  59.       <div class="part-block" id="name">
  60.         <h1>name</h1>
  61.         <p class="part" id="name-content">
  62.           <span class="man-name">
  63.             <xsl:value-of select="@name"/>
  64.           </span>
  65.           <xsl:text> - </xsl:text>
  66.           <span class="man-long-name" >
  67.             <xsl:value-of select="@long-name"/>
  68.           </span>
  69.         </p>
  70.       </div>
  71.       <div class="part-block" id="synopsis">
  72.         <h1>synopsis</h1>
  73.           <p class="part" id="synopsis-content">
  74.           <xsl:apply-templates select="command" mode="synopsis"/>
  75.         </p>
  76.       </div>
  77.       <xsl:apply-templates mode="part-block"/>
  78.     </div>
  79.   </xsl:template>
  80.  
  81.   <!-- Synopsis writing -->
  82.  
  83.   <!-- Write the synopsis for a command or parameter group -->
  84.   <xsl:template match="command|param-group" mode="synopsis">
  85.     <div class="{name()}-synopsis">
  86.       <span class="{name()}-synopsis-name">
  87.         <xsl:value-of select="@name"/>
  88.       </span>
  89.       <xsl:apply-templates select="file|param|param-group" mode="synopsis-param"/>
  90.       <!-- xsl:apply-templates select="param-group" mode="synopsis"/ -->
  91.     </div>
  92.   </xsl:template>
  93.  
  94.   <!-- Write a parameter, filename or parameter group name  -->
  95.   <xsl:template match="file|param|param-group" mode="synopsis-param">
  96.     <xsl:text> </xsl:text>
  97.     <span class="synopsis-{name()}">
  98.       <xsl:if test="not(@required = 'true')">
  99.         <xsl:text>[</xsl:text>
  100.       </xsl:if>
  101.       <span class="{name()}-name">
  102.         <xsl:value-of select="@name"/>
  103.       </span>
  104.       <xsl:if test="@arg">
  105.         <span class="{name()}-arg">
  106.           <xsl:text> </xsl:text>
  107.           <xsl:value-of select="@arg"/>
  108.         </span>
  109.       </xsl:if>
  110.       <xsl:if test="@repeat = 'true'"> …</xsl:if>
  111.       <xsl:if test="not(@required = 'true')">
  112.         <xsl:text>]</xsl:text>
  113.       </xsl:if>
  114.     </span>
  115.   </xsl:template>
  116.  
  117.  
  118.   <!-- Parts -->
  119.  
  120.  
  121.   <!-- Write the title of a part -->
  122.   <xsl:template match="*" mode="part-title">
  123.     <xsl:choose>
  124.       <xsl:when test="@title"><xsl:value-of select="@title"/></xsl:when>
  125.       <xsl:otherwise><xsl:value-of select="translate(name(),'-',' ')"/></xsl:otherwise>
  126.     </xsl:choose>
  127.   </xsl:template>
  128.  
  129.   <!-- TOC entry -->
  130.   <xsl:template match="*" mode="part-toc">
  131.     <xsl:param name="title">
  132.       <xsl:apply-templates select="." mode="part-title"/>
  133.     </xsl:param>
  134.     <div class="toc-entry">
  135.       <a href="#{translate($title,' ','-')}">
  136.         <xsl:value-of select="$title"/>
  137.       </a>
  138.     </div>
  139.   </xsl:template>
  140.  
  141.   <!-- Part block -->
  142.   <xsl:template match="*" mode="part-block">
  143.     <xsl:param name="title">
  144.       <xsl:apply-templates select="." mode="part-title"/>
  145.     </xsl:param>
  146.     <div class="part-block" id="{translate($title,' ','-')}">
  147.       <h1><xsl:value-of select="$title"/></h1>
  148.       <p class="part">
  149.         <xsl:apply-templates/>
  150.       </p>
  151.     </div>
  152.   </xsl:template>
  153.  
  154.   <!-- Command parameters -->
  155.  
  156.   <!-- TOC entry -->
  157.   <xsl:template match="command" mode="part-toc">
  158.     <xsl:choose>
  159.       <xsl:when test="count(param-group) > 1">
  160.         <div class="toc-entry">
  161.           <a href="#description">parameters</a>
  162.           <div class="toc-entry-childs">
  163.             <xsl:apply-templates select="param-group" mode="toc"/>
  164.           </div>
  165.         </div>
  166.       </xsl:when>
  167.       <xsl:otherwise>
  168.         <xsl:apply-templates select="param-group" mode="toc"/>
  169.       </xsl:otherwise>
  170.     </xsl:choose>
  171.   </xsl:template>
  172.  
  173.   <!-- Write a toc entry for a parameter group -->
  174.   <xsl:template match="param-group" mode="toc">
  175.     <xsl:param name="base-id"/>
  176.     <xsl:variable name="id"
  177.       select="translate(concat($base-id,@name),' ','-')"/>
  178.     <div class="toc-entry">
  179.       <a href="#{$id}"><xsl:value-of select="@name"/></a>
  180.       <xsl:if test="param-group">
  181.         <div class="toc-entry-childs">
  182.           <xsl:apply-templates select="param-group" mode="toc">
  183.             <xsl:with-param name="base-id" select="concat($id,'-')"/>
  184.           </xsl:apply-templates>
  185.         </div>
  186.       </xsl:if>
  187.     </div>
  188.   </xsl:template>
  189.  
  190.   <!-- Parameters description -->
  191.   <xsl:template match="command" mode="part-block">
  192.     <xsl:apply-templates/>
  193.   </xsl:template>
  194.  
  195.   <!-- Write the doc for a parameter group -->
  196.   <xsl:template match="param-group">
  197.     <xsl:param name="level">1</xsl:param>
  198.     <xsl:param name="base-id"/>
  199.     <xsl:variable name="id"
  200.                 select="translate(concat($base-id,@name),' ','-')"/>
  201.  
  202.     <div class="part-block" id="{$id}">
  203.       <xsl:element name="h{$level}">
  204.         <xsl:choose>
  205.           <xsl:when test="@title"><xsl:value-of select="@title"/></xsl:when>
  206.           <xsl:otherwise><xsl:value-of select="@name"/></xsl:otherwise>
  207.         </xsl:choose>
  208.       </xsl:element>
  209.       <p class="part" id="{$id}-content">
  210.         <xsl:if test="description">
  211.           <p class="param-group-description">
  212.             <xsl:apply-templates select="description"/>
  213.           </p>
  214.         </xsl:if>
  215.         <xsl:apply-templates select="param|param-group">
  216.           <xsl:with-param name="level" select="$level+1"/>
  217.           <xsl:with-param name="base-id" select="concat($id,'-')"/>
  218.         </xsl:apply-templates>
  219.       </p>
  220.     </div>
  221.   </xsl:template>
  222.  
  223.   <!-- Write the doc for a parameter -->
  224.   <xsl:template match="param">
  225.     <xsl:param name="base-id"/>
  226.     <xsl:variable name="id"
  227.       select="translate(concat($base-id,@name),' ','-')"/>
  228.     <p class="param" id="{$id}">
  229.       <div class="param-usage">
  230.         <span class="param-name">
  231.           <xsl:value-of select="concat('-',@name)"/>
  232.         </span>
  233.         <xsl:if test="@arg">
  234.           <xsl:text> </xsl:text>
  235.           <span class="arg-name">
  236.             <xsl:value-of select="concat('<',@arg,'>')"/>
  237.           </span>
  238.         </xsl:if>
  239.       </div>
  240.       <div class="param-description">
  241.         <!-- Do we have a short description ? -->
  242.         <xsl:choose>
  243.           <xsl:when test="short">
  244.             <div class="param-description-short">
  245.               <xsl:apply-templates select="short"/>
  246.             </div>
  247.             <div class="param-description-long">
  248.               <xsl:apply-templates select="text()|*[name() != 'short']"/>
  249.             </div>
  250.           </xsl:when>
  251.           <xsl:otherwise>
  252.             <xsl:apply-templates/>
  253.           </xsl:otherwise>
  254.         </xsl:choose>
  255.       </div>
  256.     </p>
  257.   </xsl:template>
  258.  
  259.   <!-- Write the short description -->
  260.   <xsl:template match="short">
  261.     <xsl:apply-templates/>
  262.   </xsl:template>
  263.  
  264.   <!-- Create a link from command names -->
  265.   <xsl:template match="cmd">
  266.     <a class="cmd-name" href="{.}.xml"><xsl:value-of select="."/></a>
  267.   </xsl:template>
  268.  
  269.   <!-- Tag to reference option names -->
  270.   <xsl:template match="opt">
  271.     <span class="param-name"><xsl:value-of select="."/></span>
  272.   </xsl:template>
  273.  
  274.   <!-- Tag to reference argument names -->
  275.   <xsl:template match="arg">
  276.     <span class="arg-name">
  277.       <xsl:value-of select="concat('<',.,'>')"/>
  278.     </span>
  279.   </xsl:template>
  280.  
  281.   <!-- Tag to reference the default value of the option -->
  282.   <xsl:template match="default">
  283.     <xsl:value-of select="ancestor::param[1]/@default"/>
  284.   </xsl:template>
  285.  
  286.   <!-- Pass some html through  -->
  287.   <xsl:template match="p|a|em|q|pre">
  288.     <xsl:copy>
  289.       <xsl:apply-templates/>
  290.     </xsl:copy>
  291.   </xsl:template>
  292.  
  293.   <!-- Kill anything not explicitly matched -->
  294.   <xsl:template match="*"/>
  295.  
  296. </xsl:stylesheet>
  297.