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 / def2binding.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  3.2 KB  |  83 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. <!--
  18.   Transforms a form definition file into a binding file. This is an attempt at merging
  19.   these two files in only one.
  20.   To use it, simply load the form bindings from a cocoon: pipeline that applies this stylesheet
  21.   on a form definition. Next step will by to rewrite this directly into Cocoon Forms binding system.
  22.   
  23.   The binding is created according to the following rules :
  24.   - fb:* attributes on widget definitions lead to the creation of
  25.     - <fb:context> if a @fb:context attribute is found
  26.     - <fb:simple-repeater> if a @fb:parent-path is found on a <fd:repeater>
  27.     - <fb:value> if a @fb:path is found on any fd:* element    
  28.   - if a <fd:binding> is present, its content is copied as is with the @id of the enclosing widget
  29.   
  30.   @author Sylvain Wallez
  31.   @version CVS $Id: def2binding.xsl,v 1.2 2004/03/11 02:56:31 joerg Exp $
  32. -->
  33.  
  34. <xsl:stylesheet
  35.   version="1.0"
  36.   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  37.   xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
  38.   xmlns:fb="http://apache.org/cocoon/forms/1.0#binding">
  39.   
  40. <xsl:template match="fd:*[@fb:context]">
  41.   <fb:context path="{@fb:context}">
  42.     <xsl:for-each select="@*[(local-name(.) != 'context') and (namespace-uri() = 'http://apache.org/cocoon/forms/1.0#binding')]">
  43.       <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
  44.     </xsl:for-each>
  45.     <xsl:apply-templates/>
  46.   </fb:context>
  47. </xsl:template>
  48.  
  49. <xsl:template match="fd:*[@fb:path]">
  50.   <fb:value id="{@id}">
  51.     <xsl:for-each select="@*[namespace-uri() = 'http://apache.org/cocoon/forms/1.0#binding']">
  52.       <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
  53.     </xsl:for-each>
  54.     <xsl:apply-templates/>
  55.   </fb:value>
  56. </xsl:template>
  57.  
  58. <xsl:template match="fd:repeater[@fb:parent-path]">
  59.   <fb:simple-repeater id="{@id}">
  60.     <xsl:for-each select="@*[namespace-uri() = 'http://apache.org/cocoon/forms/1.0#binding']">
  61.       <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
  62.     </xsl:for-each>
  63.     <xsl:apply-templates/>
  64.   </fb:simple-repeater>
  65. </xsl:template>
  66.  
  67. <xsl:template match="fd:*[fd:binding]">
  68.   <!-- copy the binding element -->
  69.   <xsl:variable name="binding" select="fd:binding/fb:*[1]"/>
  70.   <xsl:element name="{local-name($binding)}" namespace="{namespace-uri($binding)}">
  71.     <xsl:copy-of select="$binding/@*"/>
  72.     <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
  73.     <xsl:copy-of select="$binding/node()"/>
  74.     <!-- and recurse in the widgets while in the binding element -->
  75.     <xsl:apply-templates/>
  76.   </xsl:element>
  77. </xsl:template>
  78.  
  79. <!-- avoid copying text -->
  80. <xsl:template match="text()|@*"/>
  81.  
  82. </xsl:stylesheet>
  83.