You are currently viewing a snapshot of taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to, please file a bug.

<< XULNotes Author: Chris Waterson Other Docs: XUL Template Primer

XUL Template Primer - Multiple Rules


The container and member attributes
Selecting a Rule
Related Documents


This document expands on the XUL Template Primer by illustrating how multiple <rule> elements can interact to create content using the extended XUL template syntax.


To illustrate how multiple <rule> elements interact, we'll examine this XUL document, which builds a simple content model from an RDF/XML file.

<?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin" type="text/css"?> <window xmlns:html="" xmlns="" align="vertical"> <vbox datasources="friends.rdf" ref="urn:root"> <template container="?uri" member="?friend"> <rule> <conditions> <content uri="?uri" /> <triple subject="?uri" predicate="" object="?friends" /> <member container="?friends" child="?friend" /> <triple subject="?friend" predicate="" object="?name" /> <triple subject="?friend" predicate="" object="?addr" /> <triple subject="?addr" predicate="" object="?street" /> </conditions> <action> <hbox uri="?friend"> <label value="?name" /> <label value="?street" /> </hbox> </action> </rule> <rule> <conditions> <content uri="?uri" /> <triple subject="?uri" predicate="" object="?friends" /> <member container="?friends" child="?friend" /> <triple subject="?friend" predicate="" object="?name" /> </conditions> <action> <hbox uri="?friend"> <label value="?name" /> <label value="(Unknown)" /> </hbox> </action> </rule> </template> </vbox> </window>

As you can see, there are two <rule> elements contained within the <template>.

We'll use the same RDF/XML that was used for the bindings example, friends.rdf.

<?xml version="1.0"?> <rdf:RDF xmlns:rdf="" xmlns:nc=""> <rdf:Description about="urn:root"> <nc:friends> <rdf:Seq> <rdf:li> <rdf:Description nc:name="Alison Appel"> <nc:address resource="#home" /> </rdf:Description> </rdf:li> <rdf:li> <rdf:Description nc:name="Jack"> <nc:address resource="#doghouse" /> </rdf:Description> </rdf:li> <rdf:li> <rdf:Description nc:name="Lumpy" /> </rdf:li> </rdf:Seq> </nc:friends> </rdf:Description> <rdf:Description ID="home" nc:street="437 Hoffman" /> <rdf:Description ID="doghouse" nc:street="435 Hoffman" /> </rdf:RDF>

This RDF/XML creates the following model.

RDF Data Model

When thrown together in Mozilla, the following appears:


Lumpy's street address is "unknown"! In this case, the first rule was matched twice: once for Alison and once for Jack, and the second rule (which has no constraints on one being landed gentry) matched once.

The container and member attributes

When more than one rule exists, the <template> should specify a container and member attribute.

<template container="?uri" member="?friend"> ... </template>

These attributes specify which variables correspond to "containerhood" and "membership" in the rules that follow.

Each rule must use these variables consistently.

If these are not specified, then they will be deduced from the first rule.

Selecting a Rule

Even though more than one rule might match for a particular container/member pair, only one rule is allowed to actually build content. When this happens, the selection process is simple: the first rule listed in the <template> is chosen.

In our example, the second rule matches for both Alison and Jack; however, since the first rule also matches, it "masks" the second rule.

XUL Template Primer
XUL template basics.
XUL Template Primer - Bindings
Illustrates how to use the <bindings> tag in your XUL templates.
XUL Template Primer - Nested Content
Illustrates how a template can be used recursively to build nested content.
XUL Template Primer - Outliner
Illustrates how a template can be used as a view for a XUL outliner.
XUL Template Reference
Describes the simple XUL template syntax in detail.