Tal4Rdf Silex team 

Short introduction to T4R

T4R is a template language: the rendering of the underlying data (RDF in our case) is done accordingly to a template: a document that is a mock up of the desired output.

To achieve that, the template must contain:

  • processing instructions specifying how the template is to be altered by the rendering,
  • expressions specifying what data has to be used by and rendered by the template.

T4R processing instructions

T4R is based on TAL_(Template Attribute Language), a template language introduced by the Zope framework. Since TAL processing instructions are used as is by T4R, this documentation only provide a brief description of them. For a complete documentation, see the TAL reference documents.

TAL processing instructions, as the name of the language implies, are all contained in HTML/XML attributes. Furthermore, those attributes belong to a specific namespace (usually associated with the tal prefix), so that they are ignored by other parsers. This is how TAL manages not to break templates with respect to their original format.

TAL provides instructions to replace the content of an element (tal:content), its attributes (tal:attributes) or the element itself (tal:replace). It provides conditional (tal:condition) and iterative (tal:repeat) constructs. It also allows the definition of variables (tal:define) and the processing of errors (tal:on-error).

It is worth noting, since T4R uses this distinction, that TAL has two kinds of variables: global and local. Local variables (the default kind) are only valid inside the element defining them, while global variables are valid from their definition to the end of the template, regardless of the element structure.

Tal Expressions

TAL expression syntax (a.k.a. TALES) uses slash-separated paths to access the underlying data, e.g. a/b/c. A good intuition of the meaning of a path can be given by replacing the slashes by “ ‘s”. While standard TALES expressions are still valid in T4R, we introduce a special kind of paths, involving CURIEs, to traverse the RDF graph and retrieve data. CURIEs in T4R represent URI references, as is usual in RDF[1].

Typically, a T4R template describes one resource. The first CURIE of a paths interpreted as an RDF property of that resource. For example, the simple paths foaf:name or foaf:knows retrieve the value(s) of the corresponding properties for the resource being rendered. Since properties in RDF may have multiple values, the result of those paths is called a node list, and may always contain zero, one or several RDF nodes.

Appending further CURIEs to a path will traverse that property for all the nodes in the node list. E.g. foaf:knows/foaf:name will evaluate to all the names of the people known by the current resource. It is also possible to traverse a property backward, by appending :- to its CURIE. For example, foaf:knows:- evaluates to all the persons knowing the current resource.

Node lists behave well with TAL processing instructions. They can of course be iterated with tal:repeat. An empty list will evaluate to false in a tal:condition. In other contexts, a non-empty list will render simply as the value of one of the nodes, such that tal:content="foaf:name" will replace the content of the element by one name, and tal:attributes="href foaf:homepage" will generate a link with one URL (see why).

In some situations, it may be useful to start a path at another resource than the one being described by the template. This kind of path is called an absolute path (it is not relative to the resources described with the template). An absolute path starts with a leading slash, just like file or URL absolute paths. Its first CURIE is not interpreted as a property, but as a resource. For example, /foaf:Person/rdf:type:- will evaluate to all the instances if the class foaf:Person in the current graph.

Finally, CURIE paths can include non-CURIE keywords that perform special operations on node lists. One can for example count the nodes in a list, test the type (URI-ref, blank or literal) of a node, check that a node list contains a particular node... A complete list list can be found here.

Now, you are ready to try the online demo/tutorial.

Footnotes

[1]We will see later how the CURIE prefix is associated with a namespace in T4R.
[2]More precisely: as a node list containing a single node.