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 / forms-page-styling.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  10.8 KB  |  332 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:fi="http://apache.org/cocoon/forms/1.0#instance"
  20.                 exclude-result-prefixes="fi">
  21.   <!--+
  22.       | This stylesheet is designed to be included by 'forms-samples-styling.xsl'.
  23.       +-->
  24.   <xsl:template match="head" mode="forms-page">
  25.     <!--+ 'forms-page-styling.xsl' relies on 'forms-field-styling.xsl' for the
  26.         | inclusion of the correct JS and CSS files. To fix it, we have to
  27.         | separate the page specific parts into their own files.
  28.         +-->
  29.   </xsl:template>
  30.  
  31.   <xsl:template match="body" mode="forms-page"/>
  32.  
  33.   <!--
  34.     fi:group : default is to enclose items in a div
  35.   -->
  36.   <xsl:template match="fi:group">
  37.     <div title="{fi:hint}">
  38.       <xsl:copy-of select="@*"/>
  39.       <xsl:apply-templates mode="group-layout" select="."/>
  40.     </div>
  41.   </xsl:template>
  42.  
  43.   <!--
  44.     fi:group of type tabs
  45.   -->
  46.   <xsl:template match="fi:group[fi:styling/@type='tabs']">
  47.     <!-- find the currently selected tab.
  48.          Thoughts still needed here, such as autogenerating a field in the
  49.          forms transformer to hold this state.
  50.     -->
  51.     <xsl:variable name="active">
  52.       <xsl:variable name="value" select="normalize-space(fi:state/fi:*/fi:value)"/>
  53.       <xsl:choose>
  54.         <xsl:when test="$value">
  55.           <xsl:value-of select="$value"/>
  56.         </xsl:when>
  57.         <xsl:otherwise>0</xsl:otherwise>
  58.       </xsl:choose>
  59.     </xsl:variable>
  60.     <!-- copy the "state-widget" attribute for use in for-each -->
  61.     <xsl:variable name="state-widget" select="fi:state/fi:*/@id"/>
  62.     <xsl:variable name="id" select="generate-id()"/>
  63.  
  64.     <div id="{$id}" title="{fi:hint}">
  65.       <!-- add an hidden input for the state -->
  66.       <xsl:if test="$state-widget">
  67.         <input type="hidden" name="{$state-widget}" value="{$active}"/>
  68.       </xsl:if>
  69.       <!-- div containing the tabs -->
  70.       <div class="forms-tabArea">
  71.         <xsl:for-each select="fi:items/fi:*">
  72.           <xsl:variable name="pos" select="position() - 1"/>
  73.           <span id="{$id}_tab_{$pos}" onclick="forms_showTab('{$id}', {$pos}, {last()}, '{$state-widget}')">
  74.             <xsl:attribute name="class">
  75.               <xsl:text>forms-tab</xsl:text>
  76.               <xsl:if test="$active = $pos"> forms-activeTab</xsl:if>
  77.             </xsl:attribute>
  78.             <xsl:copy-of select="fi:label/node()"/>
  79.             <xsl:if test="fi:items/*//fi:validation-message">
  80.               <span class="forms-validation-message"> ! </span>
  81.             </xsl:if>
  82.           </span>
  83.         </xsl:for-each>
  84.       </div>
  85.       <!-- a div for each of the items -->
  86.       <xsl:for-each select="fi:items/fi:*">
  87.         <xsl:variable name="pos" select="position() - 1"/>
  88.         <div class="forms-tabContent" id="{$id}_items_{$pos}">
  89.           <xsl:if test="$active != $pos">
  90.             <xsl:attribute name="style">display:none</xsl:attribute>
  91.           </xsl:if>
  92.           <xsl:apply-templates select="."/>
  93.         </div>
  94.       </xsl:for-each>
  95.     </div>
  96.   </xsl:template>
  97.  
  98.   <!--
  99.     fi:group of type choice : a popup is used instead of tabs
  100.   -->
  101.   <xsl:template match="fi:group[fi:styling/@type='choice']">
  102.     <!-- find the currently selected tab.
  103.          Thoughts still needed here, such as autogenerating a field in the formstransformer
  104.          to hold this state.
  105.     -->
  106.     <xsl:variable name="active">
  107.       <xsl:variable name="value" select="normalize-space(fi:state/fi:*/fi:value)"/>
  108.       <xsl:choose>
  109.         <xsl:when test="$value">
  110.           <xsl:value-of select="$value"/>
  111.         </xsl:when>
  112.         <xsl:otherwise>0</xsl:otherwise>
  113.       </xsl:choose>
  114.     </xsl:variable>
  115.     <!-- copy the "state-widget" attribute for use in for-each -->
  116.     <xsl:variable name="state-widget" select="fi:state/fi:*/@id"/>
  117.     <xsl:variable name="id" select="generate-id()"/>
  118.  
  119.     <fieldset id="{$id}">
  120.       <legend title="{fi:hint}">
  121.         <xsl:apply-templates select="fi:label/node()"/>
  122.         <select name="{$state-widget}" onchange="forms_showTab('{$id}', this.selectedIndex, {count(fi:items/*)}, '{$state-widget}')">
  123.           <xsl:for-each select="fi:items/fi:*">
  124.             <xsl:variable name="pos" select="position() - 1"/>
  125.             <option>
  126.               <xsl:attribute name="value">
  127.                 <xsl:choose>
  128.                   <xsl:when test="fi:value">
  129.                     <xsl:value-of select="fi:value"/>
  130.                   </xsl:when>
  131.                   <xsl:otherwise>
  132.                     <xsl:value-of select="$pos"/>
  133.                   </xsl:otherwise>
  134.                 </xsl:choose>
  135.               </xsl:attribute>
  136.               <xsl:if test="$active = $pos">
  137.                 <xsl:attribute name="selected">selected</xsl:attribute>
  138.               </xsl:if>
  139.               <xsl:copy-of select="fi:label/node()"/>
  140.             </option>
  141.           </xsl:for-each>
  142.         </select>
  143.         <xsl:if test="fi:items/*//fi:validation-message">
  144.           <span class="forms-validation-message"> ! </span>
  145.         </xsl:if>
  146.       </legend>
  147.       <!-- a div for each of the items -->
  148.       <xsl:for-each select="fi:items/fi:*">
  149.         <xsl:variable name="pos" select="position() - 1"/>
  150.         <div id="{$id}_items_{$pos}">
  151.           <xsl:if test="$active != $pos">
  152.             <xsl:attribute name="style">display:none</xsl:attribute>
  153.           </xsl:if>
  154.           <xsl:apply-templates select="."/>
  155.         </div>
  156.       </xsl:for-each>
  157.     </fieldset>
  158.   </xsl:template>
  159.  
  160.   <!--
  161.     fi:group of type fieldset : enclose items in a fieldset frame
  162.   -->
  163.   <xsl:template match="fi:group[fi:styling/@type='fieldset']">
  164.     <fieldset>
  165.       <xsl:apply-templates select="." mode="styling"/>
  166.       <legend title="{fi:hint}"><xsl:copy-of select="fi:label/node()"/></legend>
  167.       <xsl:apply-templates mode="group-layout" select="."/>
  168.     </fieldset>
  169.   </xsl:template>
  170.  
  171.   <!--
  172.     Group items layout : default is no layout
  173.   -->
  174.   <xsl:template match="fi:group" mode="group-layout">
  175.     <xsl:apply-templates select="fi:items/*"/>
  176.   </xsl:template>
  177.  
  178.   <!--
  179.     Column group items layout
  180.   -->
  181.   <xsl:template match="fi:group[fi:styling/@layout='column']" mode="group-layout">
  182.     <table border="0" summary="{fi:hint}">
  183.       <tbody>
  184.         <xsl:apply-templates select="fi:items/*" mode="group-column-content"/>
  185.       </tbody>
  186.     </table>
  187.   </xsl:template>
  188.  
  189.   <!--
  190.     Default column layout : label above and input below
  191.   -->
  192.   <xsl:template match="fi:*" mode="group-column-content">
  193.     <tr>
  194.       <td><xsl:apply-templates select="." mode="label"/></td>
  195.     </tr>
  196.     <tr>
  197.       <td><xsl:apply-templates select="."/></td>
  198.     </tr>
  199.   </xsl:template>
  200.  
  201.   <xsl:template match="fi:action" mode="group-column-content">
  202.     <tr>
  203.       <td><xsl:apply-templates select="."/></td>
  204.     </tr>
  205.   </xsl:template>
  206.  
  207.   <!--
  208.     Columns group items layout
  209.   -->
  210.   <xsl:template match="fi:group[fi:styling/@layout='columns']" mode="group-layout">
  211.     <table border="0" summary="{fi:hint}">
  212.       <tbody>
  213.         <xsl:apply-templates select="fi:items/*" mode="group-columns-content"/>
  214.       </tbody>
  215.     </table>
  216.   </xsl:template>
  217.  
  218.   <!--
  219.     Default columns layout : label left and input right
  220.   -->
  221.   <xsl:template match="fi:*" mode="group-columns-content">
  222.     <tr>
  223.       <td><xsl:apply-templates select="." mode="label"/></td>
  224.       <td><xsl:apply-templates select="."/></td>
  225.     </tr>
  226.   </xsl:template>
  227.  
  228.   <!--
  229.     Row group items layout
  230.   -->
  231.   <xsl:template match="fi:group[fi:styling/@layout='row']" mode="group-layout">
  232.     <table border="0" summary="{fi:hint}">
  233.       <tbody>
  234.         <tr>
  235.           <xsl:apply-templates select="fi:items/*" mode="group-row-content"/>
  236.         </tr>
  237.       </tbody>
  238.     </table>
  239.   </xsl:template>
  240.  
  241.   <!--
  242.     Default row layout : label left and input right
  243.   -->
  244.   <xsl:template match="fi:*" mode="group-row-content">
  245.     <td><xsl:apply-templates select="." mode="label"/></td>
  246.     <td><xsl:apply-templates select="."/></td>
  247.   </xsl:template>
  248.  
  249.   <xsl:template match="fi:action" mode="group-row-content">
  250.     <td><xsl:apply-templates select="."/></td>
  251.   </xsl:template>
  252.   <!--
  253.     Rows group items layout
  254.   -->
  255.   <xsl:template match="fi:group[fi:styling/@layout='rows']" mode="group-layout">
  256.     <table border="0" summary="{fi:hint}">
  257.       <tbody>
  258.         <tr>
  259.           <xsl:apply-templates select="fi:items/*" mode="group-rows-labels"/>
  260.         </tr>
  261.         <tr>
  262.           <xsl:apply-templates select="fi:items/*" mode="group-rows-content"/>
  263.         </tr>
  264.       </tbody>
  265.     </table>
  266.   </xsl:template>
  267.  
  268.   <!--
  269.     Default rows layout : label above and input below
  270.   -->
  271.   <xsl:template match="fi:*" mode="group-rows-labels">
  272.     <td><xsl:apply-templates select="." mode="label"/></td>
  273.   </xsl:template>
  274.  
  275.   <xsl:template match="fi:action" mode="group-rows-labels">
  276.     <td> </td>
  277.   </xsl:template>
  278.  
  279.   <xsl:template match="fi:*" mode="group-rows-content">
  280.     <td><xsl:apply-templates select="."/></td>
  281.   </xsl:template>
  282.  
  283.   <!-- boolean field : checkbox and label on a single line -->
  284.   <xsl:template match="fi:booleanfield" mode="group-columns-content">
  285.     <tr>
  286.       <td colspan="2">
  287.         <xsl:apply-templates select="."/>
  288.         <xsl:apply-templates select="." mode="label"/>
  289.       </td>
  290.     </tr>
  291.   </xsl:template>
  292.  
  293.   <!-- action : on a single line -->
  294.   <xsl:template match="fi:action" mode="group-columns-content">
  295.     <tr>
  296.       <td colspan="2"><xsl:apply-templates select="."/></td>
  297.     </tr>
  298.   </xsl:template>
  299.  
  300.   <!-- any other element : on a single line -->
  301.   <xsl:template match="*" mode="group-columns-content">
  302.     <tr>
  303.       <td colspan="2"><xsl:apply-templates select="."/></td>
  304.     </tr>
  305.   </xsl:template>
  306.  
  307.   <!-- double-list multivaluefield : lists under the label -->
  308.   <xsl:template match="fi:multivaluefield[fi:styling/@list-type='double-listbox']"
  309.                 mode="group-columns-content">
  310.     <tr>
  311.       <td colspan="2"><xsl:apply-templates select="." mode="label"/></td>
  312.     </tr>
  313.     <tr>
  314.       <td colspan="2"><xsl:apply-templates select="."/></td>
  315.     </tr>
  316.   </xsl:template>
  317.  
  318.   <!-- nested group -->
  319.   <xsl:template match="fi:group" mode="group-columns-content">
  320.     <tr>
  321.       <td colspan="2"><xsl:apply-templates select="."/></td>
  322.     </tr>
  323.   </xsl:template>
  324.  
  325.   <xsl:template match="@*|node()" priority="-1">
  326.     <xsl:copy>
  327.       <xsl:apply-templates select="@*|node()"/>
  328.     </xsl:copy>
  329.   </xsl:template>
  330.  
  331. </xsl:stylesheet>
  332.