Obsolete Pages{{Obsolete}}
The official documentation is at: http://docs.alfresco.com
{{AVMWarning}}
AVM
Once the content data is captured (via XForms) as XML instance documents, it needs to be rendered to site visitors in a human-readable format (typically HTML). This transformation can be done at request time (by converting the XML to HTML on the fly) or at authoring time, via the use of 'renditioning templates'.
Alfresco provides two renditioning engine implementations, one which uses XSL templates, and the other freemarker. In both cases, the form instance data (XML) is passed to the template to be rendered. The following are simple examples of how a simple XML document can be processed by both FreeMarker and XSL.
Given the XML schema:
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'
elementFormDefault='qualified'>
<xs:element name='simple'>
<xs:complexType>
<xs:sequence>
<xs:element name='string' type='xs:normalizedString'/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The user will open an XForm, and fill in one string. The resultant XML is as follows:
<simple>
<string>hello!</string>
</simple>
You can now use the following FreeMarker rendering engine template:
${simple.string}
Alternatively, you could use an XSL rendering engine template:
<xsl:stylesheet version='1'
xmlns:xhtml='http://www.w3.org/1999/xhtml'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
exclude-result-prefixes='xhtml'>
<xsl:output method='html' indent='yes' encoding='UTF-8' version='4.01'
doctype-public='-//W3C//DTD HTML 4.01 Transitional//EN'
doctype-system='http://www.w3.org/TR/html4/loose.dtd'/>
<xsl:template match='/'>
<xhtml:html>
<xhtml:body>
<xsl:value-of select='/simple/string'/>
</xhtml:body>
</xhtml:html>
</xsl:template>
</xsl:stylesheet>
Resulting HTML output rendition (using either FreeMarker or XSL):
hello!
Alfresco makes a set of helper variables and functions available within both FreeMarker and XSL rendering engine templates. These allow the author of a rendering engine template to perform conditional logic, extract content from the repository.
Here's a list of the variables and functions provided:
In Freemarker, all variables and functions are in a hash called alf. For example, to access the value of the parent_path variable, use the FreeMarker expression:
${alf.parent_path}
In XSL, all variables are in the namespace alf. Thus, to access the value of the parent_path, use the XSL expression:
<xsl:value-of select='$alf:parent_path'/>
Examples can be found in the source tree in FTL and in XSL:
HEAD\root\projects\web-client\source\test-resources\xforms\unit-tests\rendering-engine-test\form-data-functions-test.*
Both Freemarker and XSL support including one template (or stylesheet) from another using the #include directive and xsl:include tag respectively. The template to include can be either a path within the virtualized webapp the form is configured for, or secondarily the name of the file to include in the form's folder within the Web Forms space in the Data Dictionary.
NOTE Refer to Freemarker docs for more details.
Schema:
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'
xmlns:si='http://www.alfresco.org/alfresco/simple'
targetNamespace='http://www.alfresco.org/alfresco/simple'
elementFormDefault='qualified'>
<xs:element name='simple'>
<xs:complexType>
<xs:sequence>
<xs:element name='string' type='xs:normalizedString'/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Form instance data:
<si:simple>
<si:string>hello!</si:string>
</si:simple>
FreeMarker template:
HTML output rendition:
hello!
Return to WCM Forms Developer Guide