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 / ps-cforms-default.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  11.4 KB  |  291 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
  18.     version="1.0"
  19.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  20.     xmlns:fi="http://apache.org/cocoon/forms/1.0#instance">
  21.  
  22.     <xsl:template match="fi:field">
  23.  
  24.         <xsl:choose>
  25.             <xsl:when test="fi:selection-list">
  26.                 <xsl:call-template name="field-with-selection-list">
  27.                     <xsl:with-param name="fieldelement" select="."/>
  28.                 </xsl:call-template>
  29.             </xsl:when>
  30.             <xsl:otherwise>
  31.                 <xsl:call-template name="field">
  32.                     <xsl:with-param name="fieldelement" select="."/>
  33.                 </xsl:call-template>
  34.             </xsl:otherwise>
  35.         </xsl:choose>
  36.  
  37.         <xsl:if test="fi:validation-message">
  38.             <xsl:call-template name="validation-message">
  39.                 <xsl:with-param name="message" select="fi:validation-message"/>
  40.             </xsl:call-template>
  41.         </xsl:if>
  42.         <xsl:if test="@required='true'">
  43.              <b>*</b>
  44.         </xsl:if>
  45.     </xsl:template>
  46.  
  47.     <xsl:template name="field">
  48.         <xsl:param name="fieldelement"/>
  49.         <input name="{$fieldelement/@id}" value="{$fieldelement/fi:value}">
  50.             <xsl:if test="fi:styling">
  51.                 <xsl:copy-of select="fi:styling/@*"/>
  52.             </xsl:if>
  53.         </input>
  54.     </xsl:template>
  55.  
  56.     <xsl:template name="field-with-selection-list">
  57.         <xsl:param name="fieldelement"/>
  58.  
  59.         <xsl:variable name="value" select="$fieldelement/fi:value"/>
  60.         <xsl:variable name="liststyle" select="$fieldelement/fi:styling/list-style/text()"/>
  61.  
  62.         <xsl:choose>
  63.             <xsl:when test="$liststyle='radio'">
  64.                 <xsl:for-each select="$fieldelement/fi:selection-list/fi:item">
  65.                     <input type="radio" name="{$fieldelement/@id}" value="{@value}">
  66.                         <xsl:if test="@value = $value">
  67.                             <xsl:attribute name="checked">true</xsl:attribute>
  68.                         </xsl:if>
  69.                     </input>
  70.                     <xsl:copy-of select="fi:label/node()"/><br/>
  71.                 </xsl:for-each>
  72.             </xsl:when>
  73.             <xsl:otherwise>
  74.                 <!-- default: dropdown box -->
  75.                 <select name="{$fieldelement/@id}">
  76.                     <xsl:if test="$liststyle='listbox'">
  77.                         <xsl:attribute name="size">
  78.                             <xsl:choose>
  79.                                 <xsl:when test="$fieldelement/fi:styling/listbox-size">
  80.                                     <xsl:value-of select="$fieldelement/fi:styling/listbox-size"/>
  81.                                 </xsl:when>
  82.                                 <xsl:otherwise>
  83.                                     <xsl:text>5</xsl:text>
  84.                                 </xsl:otherwise>
  85.                             </xsl:choose>
  86.                         </xsl:attribute>
  87.                     </xsl:if>
  88.                     <xsl:for-each select="$fieldelement/fi:selection-list/fi:item">
  89.                         <option value="{@value}">
  90.                             <xsl:if test="@value = $value">
  91.                                 <xsl:attribute name="selected">selected</xsl:attribute>
  92.                             </xsl:if>
  93.                             <xsl:copy-of select="fi:label/node()"/>
  94.                         </option>
  95.                     </xsl:for-each>
  96.                 </select>
  97.             </xsl:otherwise>
  98.         </xsl:choose>
  99.     </xsl:template>
  100.  
  101.     <xsl:template name="validation-message">
  102.         <xsl:param name="message"/>
  103.          <a href="#" style="color:RED; font-weight: bold; font-size: 24px;" onclick="alert('{normalize-space($message)}')">!</a>
  104.     </xsl:template>
  105.  
  106.     <xsl:template match="fi:output">
  107.         <xsl:copy-of select="fi:value/node()"/>
  108.     </xsl:template>
  109.  
  110.     <xsl:template match="fi:booleanfield">
  111.         <input type="checkbox" value="true" name="{@id}">
  112.             <xsl:if test="fi:value/text() = 'true'">
  113.                 <xsl:attribute name="checked">true</xsl:attribute>
  114.             </xsl:if>
  115.         </input>
  116.     </xsl:template>
  117.  
  118.     <xsl:template match="fi:action">
  119.         <input type="submit" name="{@id}">
  120.             <xsl:attribute name="value"><xsl:value-of select="fi:label/node()"/></xsl:attribute>
  121.         </input>
  122.     </xsl:template>
  123.  
  124.     <xsl:template match="fi:continuation-id">
  125.         <xsl:choose>
  126.             <xsl:when test="@name">
  127.                 <input name="{@name}" type="hidden" value="{.}"/>
  128.             </xsl:when>
  129.             <xsl:otherwise>
  130.                 <input name="continuation-id" type="hidden" value="{.}"/>
  131.             </xsl:otherwise>
  132.         </xsl:choose>
  133.     </xsl:template>
  134.  
  135.     <xsl:template match="fi:multivaluefield">
  136.         <xsl:if test="fi:validation-message">
  137.             <xsl:call-template name="validation-message">
  138.                 <xsl:with-param name="message" select="fi:validation-message"/>
  139.             </xsl:call-template>
  140.         </xsl:if>
  141.         <xsl:variable name="id" select="@id"/>
  142.         <xsl:variable name="values" select="fi:values/fi:value/text()"/>
  143.         <xsl:for-each select="fi:selection-list/fi:item">
  144.             <xsl:variable name="value" select="@value"/>
  145.             <input type="checkbox" value="{@value}" name="{$id}">
  146.                 <xsl:if test="$values[.=$value]">
  147.                     <xsl:attribute name="checked">true</xsl:attribute>
  148.                 </xsl:if>
  149.             </input>
  150.             <xsl:copy-of select="fi:label/node()"/>
  151.             <br/>
  152.         </xsl:for-each>
  153.     </xsl:template>
  154.  
  155.     <xsl:template match="fi:repeater">
  156.         <input type="hidden" name="{@id}.size" value="{@size}"/>
  157.         <table border="1">
  158.             <tr>
  159.                 <xsl:for-each select="fi:headings/fi:heading">
  160.                     <th><xsl:value-of select="."/></th>
  161.                 </xsl:for-each>
  162.             </tr>
  163.             <xsl:apply-templates select="fi:repeater-row"/>
  164.         </table>
  165.     </xsl:template>
  166.  
  167.     <xsl:template match="fi:repeater-row">
  168.         <tr>
  169.             <xsl:for-each select="*">
  170.                 <td>
  171.                     <xsl:apply-templates select="."/>
  172.                 </td>
  173.             </xsl:for-each>
  174.         </tr>
  175.     </xsl:template>
  176.  
  177.     <xsl:template match="fi:repeater-size">
  178.         <input type="hidden" name="{@id}.size" value="{@size}"/>
  179.     </xsl:template>
  180.  
  181.     <xsl:template match="fi:form-template">
  182.         <form>
  183.             <xsl:apply-templates select="@*|node()"/>
  184.         </form>
  185.     </xsl:template>
  186.     
  187.     <xsl:template match="fi:form[@layout='grey']">
  188.         <table cellpadding="10" cellspacing="0" align="center" border="1" bgcolor="#dddddd">
  189.             <tr>
  190.                 <td>
  191.                     <xsl:for-each select="fi:group">
  192.                         <font color="darkgreen"><h3><xsl:value-of select="fi:label"/></h3></font>
  193.                         <table bgcolor="#008800" border="0" cellpadding="3" cellspacing="1">
  194.                             <xsl:call-template name="processWidgets" />
  195.                         </table>
  196.                     </xsl:for-each>
  197.                 </td>
  198.             </tr>
  199.         </table>
  200.     </xsl:template>
  201.  
  202.     <xsl:template match="fi:form[@layout='yellow']">
  203.         <table bgcolor="#008800" border="0" cellpadding="3" cellspacing="1">
  204.             <xsl:for-each select="fi:group">
  205.                 <tr bgcolor="#FFFF88">
  206.                     <td colspan="2"><font color="GREEN" size="4"><b><xsl:value-of select="fi:label"/></b></font></td>
  207.                 </tr>
  208.                 <xsl:call-template name="processWidgets" />
  209.             </xsl:for-each>
  210.         </table>
  211.     </xsl:template>
  212.  
  213.  
  214.  
  215.     <xsl:template name="processWidgets">
  216.             <xsl:for-each select="fi:widgets/*">
  217.                     <xsl:choose>
  218.                         <xsl:when test="local-name(.) = 'repeater'">
  219.                             <tr bgcolor="#FFFF88">
  220.                                 <td colspan="2"><xsl:apply-templates select="."/></td>
  221.                             </tr>
  222.                         </xsl:when>
  223.                         <xsl:when test="local-name(.) = 'booleanfield'">
  224.                             <tr bgcolor="#FFFF88">
  225.                                 <td colspan="2">
  226.                                     <xsl:apply-templates select="."/>
  227.                                     <xsl:text> </xsl:text>
  228.                                     <xsl:copy-of select="fi:label"/>
  229.                                 </td>
  230.                             </tr>
  231.                         </xsl:when>
  232.                         <xsl:when test="fi:styling/@class = 'output'">
  233.                             <tr bgcolor="#FFFF88">
  234.                                 <td>
  235.                                     <xsl:value-of select="fi:label"/>
  236.                                 </td>
  237.                                 <td>
  238.                                     <xsl:value-of select="fi:value"/><input type="hidden" name="{@id}" value="{fi:value}" />
  239.                                 </td>
  240.                             </tr>
  241.                         </xsl:when>
  242.                         <xsl:when test="fi:styling/@class = 'warnoutput'">
  243.                             <xsl:variable name="tmp">
  244.                                 <xsl:value-of select="fi:value"/>
  245.                             </xsl:variable> 
  246.                             <xsl:if test="boolean(normalize-space($tmp))"> 
  247.                                 <tr bgcolor="#FFFF88">
  248.                                     <td>
  249.                                         <xsl:value-of select="fi:label"/>
  250.                                     </td>
  251.                                     <td>
  252.                                         <b><font color="RED"><xsl:value-of select="fi:value"/></font></b>
  253.                                     </td>
  254.                                 </tr>
  255.                             </xsl:if> 
  256.                         </xsl:when>
  257.                         <xsl:otherwise>
  258.                             <tr bgcolor="#FFFF88">
  259.                                 <td>
  260.                                     <xsl:value-of select="fi:label"/>
  261.                                 </td>
  262.                                 <td>
  263.                                     <xsl:apply-templates select="."/>
  264.                                 </td>
  265.                             </tr>
  266.                         </xsl:otherwise>
  267.                     </xsl:choose>
  268.                     </xsl:for-each>
  269.     </xsl:template>
  270.  
  271.  
  272.  
  273.     <xsl:template match="fi:aggregatefield">
  274.         <input name="{@id}" value="{fi:value}"/>
  275.  
  276.         <xsl:if test="fi:validation-message">
  277.             <xsl:call-template name="validation-message">
  278.                 <xsl:with-param name="message" select="fi:validation-message"/>
  279.             </xsl:call-template>
  280.         </xsl:if>
  281.         <xsl:if test="@required='true'">
  282.             <b>*</b>
  283.         </xsl:if>
  284.     </xsl:template>
  285.     <xsl:template match="@*|node()" priority="-1">
  286.         <xsl:copy>
  287.             <xsl:apply-templates select="@*|node()"/>
  288.         </xsl:copy>
  289.     </xsl:template>
  290. </xsl:stylesheet>
  291.