home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2007 September / maximum-cd-2007-09.iso / Assets / data / AssaultCube_v0.93.exe / docs / transformations / cuberef2xhtml.xslt < prev   
Encoding:
Extensible Markup Language  |  2007-05-10  |  15.0 KB  |  353 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- ZLIB licensed, (C) 2007 Adrian 'driAn' Henke, http://www.sprintf.org -->
  3.  
  4. <!--
  5.   transforms a cuberef document to a xhtml document
  6. -->
  7.  
  8. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="http://cubers.net/Schemas/CubeRef">
  9.  
  10.   <xsl:output method="html" omit-xml-declaration="yes" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
  11.  
  12.   
  13.   <xsl:template match="t:key">
  14.     <xsl:choose>
  15.       <xsl:when test="@name">
  16.         <xsl:value-of select="@name"/>
  17.       </xsl:when>
  18.       <xsl:otherwise>
  19.         <xsl:value-of select="@alias"/>
  20.       </xsl:otherwise>
  21.     </xsl:choose>
  22.     <xsl:if test="@description">
  23.       <xsl:text>, </xsl:text>
  24.       <xsl:value-of select="@description"/>
  25.     </xsl:if>
  26.   </xsl:template>
  27.   
  28.   <xsl:template name="identifierLink">
  29.     <a>
  30.       <xsl:attribute name="href">
  31.         <xsl:text>#identifier_</xsl:text>
  32.         <xsl:value-of select="translate(@name, ' ', '_')"/>
  33.       </xsl:attribute>
  34.       <xsl:attribute name="title">
  35.         <xsl:value-of select="@name"/>
  36.       </xsl:attribute>
  37.       <xsl:value-of select="@name"/>
  38.     </a>
  39.   </xsl:template>
  40.  
  41.   <xsl:template match="/t:cuberef">
  42.     <html>
  43.       <head>
  44.         <title>
  45.           <xsl:value-of select="@name"/>
  46.         </title>
  47.         <meta http-equiv="content-type" content="application/xhtml+xml;charset=utf-8" />
  48.         <link rel="stylesheet" href="styles/cuberef.css"/>
  49.       </head>
  50.  
  51.       <body>
  52.         <div id="fixedmenu">
  53.           <a href="#">TOP</a>
  54.         </div>
  55.         <div id="main">
  56.  
  57.           <!-- version -->
  58.           <div id="version">
  59.             <xsl:value-of select="@version"/>
  60.           </div>
  61.  
  62.           <!-- reference title -->
  63.           <div id="title">
  64.             <h1>
  65.               <xsl:value-of select="@name"/>
  66.             </h1>
  67.           </div>
  68.  
  69.           <!-- contents panel -->
  70.           <div id="contentspanel">
  71.             <xsl:if test="t:sections">
  72.               <xsl:for-each select="t:sections/t:section">
  73.                 <xsl:sort select="@name[not(../../@sort) or ../../@sort = 'true' or ../../@sort = '1']"/>
  74.                 <div class="sectiontitle">
  75.                   <a>
  76.                     <xsl:attribute name="href">
  77.                       <xsl:text>#section_</xsl:text>
  78.                       <xsl:value-of select="translate(@name, ' ', '_')"/>
  79.                     </xsl:attribute>
  80.                     <xsl:value-of select="@name"/>
  81.                   </a>
  82.                 </div>
  83.                 <div class="identifiers">
  84.                   <xsl:if test="t:identifiers">
  85.                     <ul>
  86.                       <xsl:for-each select="t:identifiers/*">
  87.                         <xsl:sort select="@name[not(../../@sort) or ../../@sort = 'true' or ../../@sort = '1']"/>
  88.                         <li>
  89.                           <xsl:call-template name="identifierLink"/>
  90.                         </li>
  91.                       </xsl:for-each>
  92.                     </ul>
  93.                   </xsl:if>
  94.                 </div>
  95.               </xsl:for-each>
  96.             </xsl:if>
  97.           </div>
  98.  
  99.           <div id="content">
  100.             
  101.               <!-- contents -->
  102.               <div id="contents">
  103.                 <h2>
  104.                   Contents
  105.                 </h2>
  106.                 <p>
  107.                   <xsl:value-of select="t:description"/>
  108.                 </p>
  109.                 <p>
  110.                   The following sections are available:
  111.                 </p>
  112.                 <ul>
  113.                   <xsl:for-each select="t:sections/t:section">
  114.                     <xsl:sort select="@name[not(../../@sort) or ../../@sort = 'true' or ../../@sort = '1']"/>
  115.                     <li>
  116.                       <a>
  117.                         <xsl:attribute name="href">
  118.                           <xsl:text>#section_</xsl:text>
  119.                           <xsl:value-of select="translate(@name, ' ', '_')"/>
  120.                         </xsl:attribute>
  121.                         <xsl:value-of select="@name"/>
  122.                       </a>
  123.                     </li>
  124.                   </xsl:for-each>
  125.                 </ul>
  126.               </div>
  127.               
  128.               <!-- sections -->
  129.               <xsl:for-each select="t:sections/t:section">
  130.                 <xsl:sort select="@name[not(../../@sort) or ../../@sort = 'true' or ../../@sort = '1']"/>
  131.                 <div class="section">
  132.                   <h2>
  133.                     <!-- section anchor -->
  134.                     <xsl:attribute name="id">
  135.                       <xsl:text>section_</xsl:text>
  136.                       <xsl:value-of select="translate(@name, ' ', '_')"/>
  137.                     </xsl:attribute>
  138.                     <xsl:value-of select="@name"/>
  139.                   </h2>
  140.  
  141.                   <!-- description -->
  142.                   <p>
  143.                     <xsl:value-of select="t:description"/>
  144.                   </p>
  145.                   
  146.                   <!-- identifiers -->
  147.                   <xsl:for-each select="t:identifiers/*">
  148.                     <xsl:sort select="@name[not(../../@sort) or ../../@sort = 'true' or ../../@sort = '1']"/>
  149.                     <xsl:variable name="readOnly" select="t:value/@readOnly and (t:value/@readOnly = 'true' or t:value/@readOnly = '1')"/>
  150.                     
  151.                     <div class="identifier">
  152.                       <!-- identifier anchor -->
  153.                       <xsl:attribute name="id">
  154.                         <xsl:text>identifier_</xsl:text>
  155.                         <xsl:value-of select="translate(@name, ' ', '_')"/>
  156.                       </xsl:attribute> 
  157.                       
  158.                       <!-- display name -->
  159.                       <div class="displayname">
  160.                         <xsl:call-template name="identifierLink"/>
  161.                         <xsl:text> </xsl:text>
  162.                         <xsl:choose>
  163.                           <xsl:when test="t:arguments"><!-- command args -->
  164.                             <xsl:for-each select="t:arguments/*">
  165.                               <xsl:value-of select="@token"/>
  166.                               <xsl:text> </xsl:text>
  167.                             </xsl:for-each>                            
  168.                           </xsl:when>
  169.                           <xsl:when test="t:value and not($readOnly)"><!-- variable value -->
  170.                             <xsl:text> </xsl:text>
  171.                             <xsl:value-of select="t:value/@token"/>  
  172.                           </xsl:when>
  173.                         </xsl:choose>
  174.                       </div>
  175.  
  176.                       <!-- description -->
  177.                       <div class="description">
  178.                         <xsl:value-of select="t:description"/>
  179.                       </div>
  180.  
  181.                       <!-- arguments or value description -->
  182.                       <xsl:choose>
  183.                         <xsl:when test="t:arguments/*"><!-- command args -->
  184.                           <div class="argumentDescriptions">
  185.                             <table>
  186.                               <tr>
  187.                                 <th>Argument</th>
  188.                                 <th>Description</th>
  189.                                 <th>Values</th>
  190.                               </tr>
  191.                               <xsl:for-each select="t:arguments/*">
  192.                                 <tr>
  193.                                   <td class="token">
  194.                                     <xsl:value-of select="@token"/>
  195.                                   </td>
  196.                                   <td class="description">
  197.                                     <xsl:value-of select="@description"/>
  198.                                     <xsl:if test="@optional">
  199.                                       <xsl:text> (optional)</xsl:text>
  200.                                     </xsl:if>
  201.                                   </td>
  202.                                   <td class="values">
  203.                                     <xsl:value-of select="@valueNotes"/>
  204.                                   </td>
  205.                                 </tr>
  206.                               </xsl:for-each>
  207.                             </table>
  208.                           </div>
  209.                         </xsl:when>
  210.                         <xsl:when test="t:value"> <!-- var value -->
  211.                           <div class="valueDescription">
  212.                             <table>
  213.                               <tr>
  214.                                 <xsl:if test="not($readOnly)">
  215.                                   <th>
  216.                                     Token
  217.                                   </th>
  218.                                 </xsl:if>
  219.                                 <th>
  220.                                   Description
  221.                                 </th>
  222.                                 <th>Values</th>
  223.                                 <th>Range</th>
  224.                                 <th>Default</th>
  225.                               </tr>
  226.                               <tr>
  227.                                 <xsl:if test="not($readOnly)">
  228.                                   <td class="token">
  229.                                     <xsl:value-of select="t:value/@token"/>
  230.                                   </td>
  231.                                 </xsl:if>
  232.                                 <td class="description">
  233.                                   <xsl:value-of select="t:value/@description"/>
  234.                                 </td>
  235.                                 <td class="values">
  236.                                   <xsl:value-of select="t:value/@valueNotes"/>
  237.                                 </td>
  238.                                 <td class="range">
  239.                                   <xsl:value-of select="t:value/@minValue"/>
  240.                                   <xsl:text>..</xsl:text>
  241.                                   <xsl:value-of select="t:value/@maxValue"/>
  242.                                 </td>
  243.                                 <td class="defaultValue">
  244.                                   <xsl:value-of select="t:value/@defaultValue"/>
  245.                                 </td>
  246.                               </tr>
  247.                             </table>
  248.                           </div>
  249.                         </xsl:when>
  250.                       </xsl:choose>
  251.                       
  252.                       <!-- remarks -->
  253.                       <xsl:if test="t:remarks">
  254.                         <div class="remarks">
  255.                           <xsl:for-each select="t:remarks/t:remark">
  256.                             <div class="remark">
  257.                               <xsl:value-of select="."/>
  258.                             </div>
  259.                           </xsl:for-each>
  260.                         </div>
  261.                       </xsl:if>
  262.  
  263.                       <!-- examples -->
  264.                       <xsl:if test="t:examples">
  265.                         <div class="examples">
  266.                           <xsl:for-each select="t:examples/t:example">
  267.                             <p>
  268.                               Example:
  269.                               <br/>
  270.                               <span class="code">
  271.                                 <xsl:value-of select="t:code"/>
  272.                               </span>
  273.                               <xsl:if test="t:explanation">
  274.                                 <br/>
  275.                                 <span class="exampleExplanation">
  276.                                   <xsl:value-of select="t:explanation"/>
  277.                                 </span>
  278.                               </xsl:if>
  279.                             </p>
  280.                           </xsl:for-each>
  281.                         </div>
  282.                       </xsl:if>
  283.                       
  284.                       <!-- default keys -->
  285.                       <xsl:if test="t:defaultKeys/*">
  286.                         <div class="defaultKeys">
  287.                           <xsl:choose>
  288.                             <xsl:when test="count(t:defaultKeys/*) = 1">
  289.                               <xsl:text>default key: </xsl:text>
  290.                               <xsl:apply-templates select="t:defaultKeys/*"/>
  291.                             </xsl:when>
  292.                             <xsl:otherwise>
  293.                               <xsl:text>default keys:</xsl:text>
  294.                               <br/>
  295.                               <xsl:for-each select="t:defaultKeys/*">
  296.                                 <xsl:apply-templates select="."/>
  297.                                 <br/>
  298.                               </xsl:for-each>
  299.                             </xsl:otherwise>
  300.                           </xsl:choose>
  301.                         </div>
  302.                       </xsl:if>
  303.                       
  304.                       <!-- references -->
  305.                       <xsl:if test="t:references">
  306.                         <div class="references">
  307.                           see also:
  308.                           <!-- refer to identifiers (identifier anchor) -->
  309.                           <xsl:for-each select="t:references/t:identifierReference">
  310.                             <a>
  311.                               <xsl:attribute name="href">
  312.                                 <xsl:text>#identifier_</xsl:text>
  313.                                 <xsl:value-of select="translate(@identifier, ' ', '_')"/>
  314.                               </xsl:attribute>
  315.                               <xsl:attribute name="class">internal</xsl:attribute>
  316.                               <xsl:choose>
  317.                                 <xsl:when test="@name">
  318.                                   <xsl:value-of select="@name"/>
  319.                                 </xsl:when>
  320.                                 <xsl:otherwise>
  321.                                   <xsl:value-of select="@identifier"/>
  322.                                 </xsl:otherwise>
  323.                               </xsl:choose>
  324.                             </a>
  325.                             <xsl:if test="position() != last()">
  326.                               <xsl:text>, </xsl:text>
  327.                             </xsl:if>
  328.                           </xsl:for-each>
  329.                           <!-- refer to web resources -->
  330.                           <xsl:for-each select="t:references/t:webReference">
  331.                             <a>
  332.                               <xsl:attribute name="href">
  333.                                 <xsl:value-of select="@url"/>
  334.                               </xsl:attribute>
  335.                               <xsl:attribute name="class">external</xsl:attribute>
  336.                               <xsl:attribute name="target">_blank</xsl:attribute>
  337.                               <xsl:value-of select="@name"/>
  338.                             </a>                            
  339.                           </xsl:for-each>
  340.                         </div>
  341.                       </xsl:if>
  342.                     </div>
  343.                   </xsl:for-each>
  344.                 </div>
  345.               </xsl:for-each>
  346.             </div>
  347.           </div>
  348.           <div id="footer"></div>
  349.       </body>
  350.     </html>
  351.   </xsl:template>
  352. </xsl:stylesheet> 
  353.