home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / hanoi.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  6.7 KB  |  202 lines

  1. <?xml version="1.0"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17. <xsl:stylesheet version="1.0" 
  18.   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  19.   xmlns:hn="http://apache.org/cocoon/apples/samples/hanoi">
  20.  
  21.  
  22.  
  23.  
  24.   <xsl:template match="hn:hanoi">
  25.  
  26.     <xsl:variable name="stacks" select="hn:stacks"/> 
  27.     <xsl:variable name="height" select="@height"/>
  28.     <xsl:variable name="cols-per-stack" select="($height)*2 + 1"/>
  29.     <xsl:variable name="cols-total" select="($cols-per-stack)*3"/>
  30.     <xsl:variable name="on-the-move" select="boolean(hn:float/@size != '')"/>
  31.     
  32.     <center>
  33.       <table border="0">
  34.         <!-- fixing col-widths row -->
  35.         <tr>
  36.       <xsl:call-template name="fix-cells" >
  37.         <xsl:with-param name="remaining" select="$cols-total" />
  38.       </xsl:call-template>
  39.         </tr>
  40.         <!-- /fixing col-widths row -->
  41.         
  42.         <!-- title-row -->
  43.         <tr>
  44.           <td colspan="{$cols-total}">
  45.             <center>-- Towers of Hanoi Puzzle --</center>            
  46.             <hr width="70%" />
  47.           </td>
  48.         </tr>
  49.         <!-- /title-row -->
  50.         
  51.         <!-- moving-disc-row -->
  52.         <tr>
  53.           <td colspan="{$cols-total}"><center>Disc on the move:</center></td>
  54.         </tr>
  55.         <tr bgcolor="#ffffff" height="5px">
  56.           <td colspan="{$cols-per-stack}"/>          
  57.           <xsl:call-template name="disc">
  58.             <xsl:with-param name="disc" select="hn:float" />
  59.             <xsl:with-param name="max_size" select="$height"/>
  60.             <xsl:with-param name="disc_color">#996633</xsl:with-param>
  61.           </xsl:call-template>
  62.           <td colspan="{$cols-per-stack}"/>
  63.         </tr>
  64.  
  65.         <tr>
  66.           <td colspan="{$cols-total}"><hr width="70%"/></td>
  67.         </tr>        
  68.     <!-- /moving-disc-row -->
  69.     
  70.     <!-- stack-header-row -->
  71.       <tr>
  72.         <xsl:choose>
  73.           <xsl:when test="$on-the-move" >
  74.           <td colspan="{$cols-per-stack}"><center><a href="?stack=0">Drop It!</a></center></td>
  75.           <td colspan="{$cols-per-stack}"><center><a href="?stack=1">Drop It!</a></center></td>
  76.           <td colspan="{$cols-per-stack}"><center><a href="?stack=2">Drop It!</a></center></td>
  77.           </xsl:when>
  78.           <xsl:otherwise>
  79.           <td colspan="{$cols-per-stack}"><center><a href="?stack=0">Lift It!</a></center></td>
  80.           <td colspan="{$cols-per-stack}"><center><a href="?stack=1">Lift It!</a></center></td>
  81.           <td colspan="{$cols-per-stack}"><center><a href="?stack=2">Lift It!</a></center></td>
  82.           </xsl:otherwise>
  83.         </xsl:choose>
  84.       </tr>
  85.     <!-- /stack-header-row -->
  86.   
  87.     
  88.         <!-- stack-rows -->
  89.         <xsl:call-template name="remaining-stack-rows">
  90.           <xsl:with-param name="remaining" select="$height"/>
  91.           <xsl:with-param name="max_size" select="$height"/>
  92.           <xsl:with-param name="cols-per-stack" select="$cols-per-stack"/>
  93.           <xsl:with-param name="stacks" select="$stacks"/>
  94.         </xsl:call-template>        
  95.         <!-- /stack-rows -->
  96.                         
  97.       </table>
  98.     </center>
  99.   </xsl:template>
  100.  
  101.  
  102.   <xsl:template name="remaining-stack-rows">
  103.     <xsl:param name="remaining"/>
  104.     <xsl:param name="max_size"/>
  105.     <xsl:param name="cols-per-stack"/>
  106.     <xsl:param name="stacks"/>
  107.  
  108.     <xsl:call-template name="stack-row">
  109.       <xsl:with-param name="row-number" select="$remaining"/>
  110.       <xsl:with-param name="max_size" select="$max_size"/>
  111.       <xsl:with-param name="cols-per-stack" select="$cols-per-stack"/>
  112.       <xsl:with-param name="stacks" select="$stacks"/>
  113.     </xsl:call-template>
  114.  
  115.     <xsl:if test="$remaining > 1">
  116.       <xsl:call-template name="remaining-stack-rows">
  117.         <xsl:with-param name="remaining" select="$remaining - 1"/>
  118.         <xsl:with-param name="max_size" select="$max_size"/>
  119.         <xsl:with-param name="cols-per-stack" select="$cols-per-stack"/>
  120.         <xsl:with-param name="stacks" select="$stacks"/>
  121.       </xsl:call-template>
  122.     </xsl:if>
  123.   </xsl:template>
  124.  
  125.  
  126.   <xsl:template name="stack-row">
  127.     <xsl:param name="row-number"/>
  128.     <xsl:param name="max_size"/>
  129.     <xsl:param name="cols-per-stack"/>
  130.     <xsl:param name="stacks"/>
  131.  
  132.   <tr height="5px" bgcolor="#ffffff">  
  133.       <xsl:for-each select="$stacks/hn:stack">
  134.         <xsl:variable name="stack-ndx" select="position()"/>
  135.  
  136.         <xsl:call-template name="disc">
  137.           <xsl:with-param name="disc" select="hn:disc[number($row-number)]" />
  138.           <xsl:with-param name="max_size" select="$max_size"/>
  139.           <xsl:with-param name="disc_color">#2C6D91</xsl:with-param>
  140.         </xsl:call-template>
  141.       </xsl:for-each>
  142.     </tr>
  143.   </xsl:template>
  144.  
  145.  
  146.  
  147.   <xsl:template name="disc">
  148.     <xsl:param name="disc" />
  149.     <xsl:param name="max_size" />
  150.     <xsl:param name="disc_color" />
  151.     
  152.     <xsl:variable name="size" select="$disc/@size" />
  153.  
  154.   <xsl:choose>
  155.       <xsl:when test="$size > 0" >
  156.         <xsl:choose>
  157.           <xsl:when test="($max_size - $size) > 0" >
  158.             <td colspan="{$max_size - $size}" bgcolor="#ffffff"/>
  159.             <td colspan="{$size}"             bgcolor="{$disc_color}"/>
  160.             <td                               bgcolor="#000000"/>
  161.             <td colspan="{$size}"             bgcolor="{$disc_color}"/>
  162.             <td colspan="{$max_size - $size}" bgcolor="#ffffff"/>
  163.           </xsl:when>
  164.           <xsl:otherwise>
  165.             <td colspan="{$size}"             bgcolor="{$disc_color}"/>
  166.             <td                               bgcolor="#000000"/>
  167.             <td colspan="{$size}"             bgcolor="{$disc_color}"/>
  168.           </xsl:otherwise>
  169.         </xsl:choose>
  170.       </xsl:when>
  171.     <xsl:otherwise>
  172.       <td colspan="{$max_size}" bgcolor="#ffffff"/>
  173.       <td                       bgcolor="#000000"/>
  174.       <td colspan="{$max_size}" bgcolor="#ffffff"/>
  175.     </xsl:otherwise>
  176.   </xsl:choose>    
  177.  
  178.   </xsl:template>
  179.  
  180.  
  181.   <xsl:template name="fix-cells">
  182.     <xsl:param name="remaining"/>
  183.  
  184.   <td width="5px" />
  185.  
  186.     <xsl:if test="$remaining > 1">
  187.       <xsl:call-template name="fix-cells">
  188.         <xsl:with-param name="remaining" select="$remaining - 1"/>
  189.       </xsl:call-template>
  190.     </xsl:if>
  191.   </xsl:template>
  192.  
  193.  
  194.   <xsl:template match="@*|node()">
  195.     <xsl:copy>
  196.       <xsl:apply-templates select="@*|node()"/>
  197.     </xsl:copy>
  198.   </xsl:template>
  199.  
  200.  
  201. </xsl:stylesheet>
  202.