WARNING: Most of this content (with the exception of the Mozilla 1.9 XPCOM reference) is very old, and can be expected to be out of date and possibly obsolete. For better XUL documentation, please visit the XUL hub at the Mozilla Developer Center.

Index

Example: Generate descendants depending on the parent

In this example, we want to display a set of labels for all animals except mammals which we want to display in a menu button. For this, four rules are used, the first two for containers and the other two for the leaf nodes. In the first rule, a condition filters out all animal classes that are non mammals. Those other types will fall through to the second rule. For mammals, a menu button is used. For other types, an hbox with a label in used instead.

When recursing into the leaf animal nodes, the third rule is used for mammals and the fourth rule for other types. The third rule uses a parent attribute which causes the rule to only match when the contents would be inserted into a button tag. This will only apply to the mammals since the mammals container generated a button. The others would be inserted into an hbox tag so the fourth rule is used instead. This last rule generates a label.

View   View Data Source

<vbox align="start" datasources="animals.rdf"
      ref="http://www.some-fictitious-zoo.com/all-animals"
      xmlns:animals="http://www.some-fictitious-zoo.com/rdf#">
  <template>
    <rule iscontainer="true" animals:name="Mammals">
      <button type="menu" uri="rdf:*" label="rdf:http://www.some-fictitious-zoo.com/rdf#name"/>
    </rule>
    <rule iscontainer="true">
      <hbox uri="rdf:*">
        <label class="header" value="rdf:http://www.some-fictitious-zoo.com/rdf#name"/>
      </hbox>
    </rule>
    <rule parent="button">
      <menupopup>
        <menuitem uri="rdf:*" label="rdf:http://www.some-fictitious-zoo.com/rdf#name"/>
      </menupopup>
    </rule>
    <rule>
      <label class="indent" uri="rdf:*" value="rdf:http://www.some-fictitious-zoo.com/rdf#name"/>
    </rule>
  </template>
</vbox>