
Chapter 9. XUL Templates- P2
Example 9-6. Tree template code of Figure 9-3
<tree datasources="10-4.rdf" flex="1"
ref="urn:root"
containment="http://xfly.mozdev.org/fly-
rdf#list">
<treecols>
<treecol id="LabelCol" flex="1"
sort="rdf:http://xfly.mozdev.org/fly-rdf#label"
class="sortDirectionIndicator"
primary="true" label="Name" />
<treecol id="LoCol" flex="1"
sort="rdf:http://xfly.mozdev.org/fly-rdf#location"
label="Location"/>
<treecol id="ColCol" flex="1"
sort="rdf:http://xfly.mozdev.org/fly-rdf#color"
label="Color"/>
</treecols>

<template>
<rule>
<conditions>
<content uri="?uri"/>
<triple subject="?uri"
predicate="http://xfly.mozdev.org/fly-rdf#list"
object="?list"/>
<member container="?list"
child="?listitem"/>
<triple subject="?listitem"
predicate="http://xfly.mozdev.org/fly-rdf#label"
object="?label"/>
</conditions>
<bindings>
<binding subject="?listitem"
predicate="http://xfly.mozdev.org/fly-rdf#color"
object="?color"/>
<binding subject="?listitem"
predicate="
http://xfly.mozdev.org/fly-rdf#location"

object="?location"/>
</bindings>
<action>
<treechildren>
<treeitem uri="?listitem">
<treerow>
<treecell ref="LabelCol"
label="?label"/>
<treecell ref="LoCol"
label="?location"/>
<treecell ref="ColCol"
label="?color"/>
</treerow>
</treeitem>
</treechildren>
</action>
</rule>
</template>
</tree>
One major difference between this example and earlier ones is that Example
9-6 has three columns. The color data cannot be used for style in this tree
scenario because trees do not support CSS data styling.

All generated data can be sorted automatically by clicking on the column
headers. Besides the tree parent element in the XUL, the other main
difference between this template and the one used with a listbox in Example
9-4 is the structure directly beneath <conditions>, where <content>
is replaced by <treerow>.
9.2.4. Multiple Rules Tree
In Example 9-6, empty cells were left blank. Sometimes situations demand
that missing data be represented by something other than whitespace, such
as a special character or marker. Fortunately, multiple <rule> tags can
exist in a template, as shown in Example 9-7. Alternate rule tags allow the
display of missing data with other, more general rules. Using alternate tags,
you can set up templates that look like conditional blocks; if the first rule is
not satisfied, then the second rule is tried, followed by the third, and so on.
Example 9-7 shows this structure of multiple rules.
Example 9-7. Tree template with rules
<tree datasources="10-4.rdf" flex="1"
ref="urn:root"
containment="http://xfly.mozdev.org/fly-
rdf#list">
<treecols>
<treecol id="LabelCol" flex="1" sort="?label"
label="Name"
primary="true" />

<treecol id="LoCol" flex="1" sort="?location"
label="Location"/>
<treecol id="ColCol" flex="1" sort="?color"
label="Color"/>
</treecols>
<template>
<!-- RULE 1: Row contains both a color and
location. -->
<rule>
<conditions>
<content uri="?uri"/>
<triple subject="?uri"
predicate="http://xfly.mozdev.org/fly-rdf#list"
object="?list"/>
<member container="?list"
child="?listitem"/>
<triple subject="?listitem"
predicate="http://xfly.mozdev.org/fly-rdf#label"
object="?label"/>
<triple subject="?listitem"