Home > Tutorials : XUL Tutorial : Template Syntax Examples

## Template Syntax Examples

The following is a reference to the template syntax.

### RDF Resource Substitution

The following provides some examples of RDF substitution inside a template rule. If the value of an attribute on any element inside a rule contains a question mark or the substring 'rdf:', it is parsed and the values of resources from the template's datasource are substituted.

A question mark indicates a variable substitution declared from the conditions or bindings element. Following the question mark should be the variable name. The value of the variable is substituted in place of the question mark and variable. If the variable was not declared, the question mark and variable are simply stripped out.

When using the shorthand rule syntax, text beginning with rdf: indicates the URI of a resource assertion in the datasource. The value of that resource is substituted in place of the 'rdf:*' prefix and the URI. If the value does not exist, the prefix and URI and stripped out.

    <button value="?count"/>

The label on the button will be the value of the variable 'count', which should be defined in the conditions or bindings part of the rule. If not defined, the value will be an empty string.

    <button value="Number: ?count"/>

The label on the button will be the text 'Number:' followed by the value of the variable 'count'.

    <button value="rdf:http://home.netscape.com/NC-rdf#Name"/>

The value of the Name resource is taken and assigned to the value attribute.

    <button value="My name is: rdf:http://home.netscape.com/NC-rdf#Name"/>

The label on the button will be set to the value 'My name is: ' followed by the value of the Name resource. Thus the plain text and the resource are concatenated.

    <button value="rdf:http://home.netscape.com/NC-rdf#Name is my name."/>

The label on the button will be set to the value of the resource followed by ' is my name.' Note that there will be a space in-between.

    <button value="rdf:http://home.netscape.com/NC-rdf#Name^'s my name."/>

The caret (^) after a resource name means concatenate without spaces. In this example, the result will be the resource value followed by the text "'s my name". There will be no spacing between them. The caret only has this special meaning at the end of a resource URI. You can embed a caret in the text by placing two carets in a row.

    <button value="rdf:http://home.netscape.com/NC-rdf#Name rdf:http://home.netscape.com/NC-rdf#URL"/>

The label on the button will be the value of the Name resource followed by the value of the URL resource separated with a space. You can use a caret instead of a space to have no spacing in-between the two values.

Copyright (C) 1999 - 2004 XulPlanet.com