Return-Path:
This page contains information on the default XSLT's provided by CFo=
rms, and
--- the fi:styling directives they support. Be sure to read first about the
--- templating mechanism.Intro
=20
There are basically 3 XSLTs:
+++As specified in templating mechanism (be s= ure to read +++ about it), the form template file is transformed in a form instance xml= file. +++ This file contains all the data needed to properly display a form. An X= SLT must +++ then be used to transform the form instance to an HTML to be displayed = in a +++ browser.
=20 +++This XSLT does not need to create also all the page layout (that can= be added +++ by other XSLT, or aggregating the form with other markup), it should on= ly format +++ the forms field and the form layout.
+++=20 +++Cocoon forms already a set of XSLTs that does exactly this, they are +++ "library" stylesheets :
+++=20Additionally there are 2 XSLTs for advanced widget styling:
---=20 ---From the sitemap you only need to reference the first one, for examp= le as --- follows:
+++If you have a look at samples, you'll see also another XSLT, +++ forms-samples-styling.xsl. This stylesheet includes other two +++ stylesheets from the default set. Usually, you will make a clone of thi= s +++ stylesheet for your own project, have it include the library XSLTs, and +++ customize what you need by writing templates in this XSLT by giving tem= plates +++ higher priority than those in the library ones.
=20 ---<map:transform src=3D"context://samples/forms/resources/forms-s= amples-styling.xsl"/>+++
From the sitemap you only need to reference only your custom XSLT, f= or +++ example as follows:
=20 +++<map:transform src=3D"context://forms/resources/myproject-forms= -styling.xsl"/>+++=20
The fi:styling elements are specified in the template, and offer a w= ay to +++ customize the way the library XSLTs render widgets. For example :
+++=20 +++<ft:widget id=3D"preferredBeer"> +++ =C2=A0 <fi:styling list-type=3D"radio"/> +++ </ft:widget> ++++++=20
The fi:styling options for the different widgets are documented in t= he respective sections about those widgets.
=20No documentation yet, checkout the samples and the source of --- forms-page-styling.xsl.
+++It's quite common to want to layout the form. For example, have part= of the +++ form displayed in a table with two columns, one with labels the other o= ne with +++ actual fields, while in another part have a single colum with labels fo= llowed by +++ fields, and in another part some tabs to group together fields.
=20 ---For storing the state of a tab or choice selection server-side just = add a --- field to the form definition that shall hold this value:
+++We could do this simply writing HTML in the template file, but this = is +++ verbose, non reusable, and not easy to style. That's why fi:groups are = there. +++ You can layout your form with fi:groups in a simple, efficient, extensi= ble and +++ easy to style way. For example :
=20 ---<fd:field id=3D"state"> +++<ft:form-template .... > +++ =C2=A0 <fi:group> +++ <fi:styling layout=3D"columns"> +++ =C2=A0=C2=A0=C2=A0 <fi:items> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <ft:widget id=3D"name"/> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <ft:widget id=3D"surname"/> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <ft:widget id=3D"birthday"/> +++ =C2=A0=C2=A0=C2=A0 </fi:items> +++ =C2=A0 </fi:group> +++ </ft:form-template> ++++++=20 +++Will produce a table with two columns, like the following :
+++=20 +++
+++ Name +++ |
+++
+++ [_______] +++ |
+++
+++ Surname +++ |
+++
+++ [_______] +++ |
+++
+++ Birthday +++ |
+++
+++ [_______] +++ |
+++
The fi:group accept either a layout or a type<= /tt> +++ attribute in its fi:styling element to specify the layout we w= ant. This +++ difference is because the "layout based" groups are quite lightweight, = while the +++ "type based" groups are more sophisticated and usually contains other g= roups. +++
+++=20 +++<fi:group layout=3D"column"> will format its items in= a single +++ column. One row will contain the label, the following row the input fie= ld.
+++=20 +++<fi:group layout=3D"columns"> will format its items i= n two +++ columns. For each item a row is created, the first column will contain = the +++ label, and the second column the input field.
+++=20 +++<fi:group layout=3D"row"> will format its items in a = single row. +++ One cell will contain the label, the following cell the input field.
+++=20 +++<fi:group layout=3D"rows"> will format its items in t= wo rows. +++ The first row will contain all the labels, one each cell, the second ro= w all the +++ input fields, again one each cell.
+++=20 +++Some input fields will have a special layout when inside a certain g= roup : +++
+++=20 +++Also layout fi:group can contain other fi:group be= tween +++ their items, and can be used to create quite complex layouts.
+++=20 +++There are currently two "type" groups : tabs and choice= . +++
+++=20 +++The tabs group will display some tabs, every tab is (usually) a fi:g= roup. For +++ example :
+++=20 +++<fi:group> +++ =C2=A0 <fi:styling type=3D"tabs"/> +++ =C2=A0 <fi:items> +++ =C2=A0=C2=A0=C2=A0 <fi:group> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <fi:label>Personal info</fi:lab= el> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <fi:styling layout=3D"columns"/> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <fi:items> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <ft:widget id=3D"name"/&g= t; +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <ft:widget id=3D"surname"= /> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </fi:items> +++ =C2=A0=C2=A0=C2=A0 </fi:group> +++ =C2=A0=C2=A0=C2=A0 <fi:group> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <fi:label>Iternet data</fi:labe= l> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <fi:styling layout=3D"columns"/> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <fi:items> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <ft:widget id=3D"email"/&= gt; +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <ft:widget id=3D"icqaccou= nt"/> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </fi:items> +++ =C2=A0=C2=A0=C2=A0 </fi:group> +++ =C2=A0 </fi:items> +++ </fi:group>+++=20 +++
Will display two tabs, one called "Personal info" and the other one = "Internet +++ data". When the user clicks on "Personal info" the field name and surna= me will +++ be displayed, while when the user clicks on "Internet data" the field e= mail and +++ icqaccount will be displayed.
+++=20 +++You can specify a widget that will be used to store and retrieve whi= ch tab is +++ curently active. This way you can control from the flow which tab will = be active +++ when the form will be displayed, or check which tab was active when the= user +++ submitted the form. To specify this special field use :
+++=20 +++<fi:group> +++ =C2=A0 <fi:styling type=3D"tabs"/> +++ =C2=A0 <fi:state> +++ =C2=A0=C2=A0=C2=A0 <ft:widget id=3D"activetab"/> +++ =C2=A0 </fi:state> +++ .... +++ </fi:group>+++=20 +++
Obviously you can call the widget whatever you want, and the suggest= ed +++ datatype is integer, since the field will contain a number indicating t= he active +++ tab, the field must be declared in the definition, and can be used in b= inding if +++ needed. For example :
+++=20 +++<fd:field id=3D"activetab"> <fd:datatype base=3D"integer"/> </fd:field>=20 ---
Bind this value to whatever you want. In the form template you need = then --- following code:
+++The group of type choice is identical to the tabs = group, +++ but instead of a row of tabs, a drop down is displayed, and selecting o= ne +++ element of the drop down will display the relative group.
=20 +++You can specify a client side javascript that will be executed when = a tab is +++ clicked or when an option of the choice drop down is selected.= This is +++ done simply adding an attribute to the items of the group, for example = :
+++=20<fi:group> --- <fi:styling type=3D"choice"/> --- <fi:state> --- <ft:widget id=3D"state"/> <!-- refering to the above defin= ed field --> --- </fi:state> --- <fi:items> --- ... --- </fi:items> +++ =C2=A0 <fi:styling type=3D"tabs"/> +++ =C2=A0 <fi:items> +++ =C2=A0=C2=A0=C2=A0 <fi:group formsOnShow=3D"personalSelected()"> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <fi:label>Personal info</fi:lab= el> +++ ... +++ =C2=A0=C2=A0=C2=A0 </fi:group> +++ =C2=A0=C2=A0=C2=A0 <fi:group formsOnShow=3D"internetSelected()"> +++ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <fi:label>Iternet data</fi:labe= l> +++ ... +++ =C2=A0=C2=A0=C2=A0 </fi:group> +++ =C2=A0 </fi:items> </fi:group>=20 +++
Have a look at forms-page-styling.xsl , all fi:groups= tt> are +++ formatted there.
+++=20