Overview

Syntax

A HTML template must be both valid HTML and valid XML. Hence it should be conform to the XHTML specification.

Your static XHTML web page can be dynamically modified by adding some attributes that will be interpreted by the HTML template code generator, in order to create a dynamic web page that can be interpreted either by your web browser (default), or by the Lavoisier HTML renderer (add "accept=html" in your URL).

In order to be recognized by the code generator, these attributes must belong to the HTML Template Language namespace: http://software.in2p3.fr/lavoisier/template.xsd

For example:

<div xmlns:tpl="http://software.in2p3.fr/lavoisier/template.xsd" tpl:text="'new value'">Example</div>

Almost all attributes of this language (except macros) take a XPath expression as value. A few of them also require a key name, which has to be set in the attribute name, after character ".".

For example:

<div xmlns:tpl="http://software.in2p3.fr/lavoisier/template.xsd" tpl:variable.myVar="'my value'"/>

Any unknown template attribute will be converted to an HTML attribute with the same name.

The short notation with double-braces "{{}}" can be used to set HTML attributes or text. For example, the two following notations are equivalent:

  • Plain notation:
    <a tpl:href="XPath1" tpl:text="XPath2"/>
  • Short notation:
    <a href="{{XPath1}}">{{XPath2}}</a>

Examples

List of keywords

Macros attributes

The macros are evaluated at code generation time. They do not take a XPath as value.

  • extends: Current HTML template extends the HTML web page located by the URL argument.
  • include: Current HTML template includes the HTML web page located by the URL argument.
  • duplicate: Current HTML template duplicated the HTML section contained within this template, and referenced by the element-id argument.

Content attributes

The following attributes generate HTML content:

  • *: Generate an HTML attribute with the same name as current attribute.
  • text: Generate a text content.
  • xml: Generate escaped XML.
  • copy-of: Generate unescaped XML.

Execution control attributes

The following attributes control code execution:

  • foreach: Iterates on selected nodes. This attribute CAN be associated with attribute with-order.
  • foreach-token: Iterates on string tokens. This attribute MUST be associated with attribute with-delimiter, which contains a string argument. Then, current token, current position and last position can be accessed through the following variables, respectively:
    • $token
    • $position
    • $last
  • if: This section will be executed only if the XPath expression evaluates to "true".
  • else: This section will be executed only if preceding if attributes are not. If the argument contains an XPath, then this attribute behaves as a else-if attributes.
  • call-template: Calls the XSL named template referenced by the template name argument (the argument of this attribute is not a XPath). This attribute CAN be associated with attribute with-param._. This can be used when you need to implement a recursive processing for example.

Content removal attributes

The following attributes remove current HTML node if the XPath argument evaluates to "true":

  • remove-tag: May removes current HTML element node.
  • remove-text: May removes current HTML text node.
  • remove-attribute._: May removes the HTML attribute node, which name is defined after the dot ("."). Example:
    <a tpl:remove-attribute.href="XPath" href="this may be removed"/>

Declaration attributes

The following attributes declare variables that can later be used with notation "$myVar":

  • variable._: Declares a variable, which name is defined after the dot ("."). Example:
    <div tpl:variable.myVar="XPath">myVar = {{$myVar}}</div>
  • parameter._: Declares a template parameter, which name is defined after the dot ('.'). The parameter name MUST be declared on the root element of the HTML template. The parameter value MUST be set (or forwarded) in the renderer configuration.