Index

Example: Recursive tree with a column that uses a source triple

This longer example is used to display a tree of animals where the second column is taken from an incoming arc pointing into a node. This requires two rules, the first when an animal is the favorite of somebody and the other when an animal is not. The first rule iterates over the animals as indicated by the uri attribute. The member tag generates the list of animals and binds the results to the ?animal variable. The first triple in the first rule finds incoming arcs using the 'favoriteAnimal' predicate. Incoming arcs are found because the values for the '?animal' variable were generated by the member tag and the value of the '?human' variable is not known. The result is that the '?human' variable is filled with the humans that have that animal as a favorite. Two additional triples get the names of both the animal and the human. Note that even though two people like the tarantula, only one is displayed. This is because we are iterating over the animals, not the humans. If we wanted to display both, we would need to write additional rules to be able to iterate over the humans.

The first rule will only be able to match when there exists a human which has the animal as a favorite. Thus, a second rule is needed for the other animals. It is similar except it doesn't have the conditions related to retrieving the human data.

View   View Data Source

<tree rows="10" datasources="animals.rdf"
                ref="http://www.some-fictitious-zoo.com/all-animals">
  <treecols>
    <treecol id="name" label="Name" primary="true" flex="1"/>
    <treecol id="favorite" label="Favorite" flex="1"/>
  </treecols>
  <template>
    <rule>
      <conditions>
        <content uri="?uri"/>
        <member container="?uri" child="?animal"/>
        <triple subject="?human"
                predicate="http://www.some-fictitious-zoo.com/rdf#favoriteAnimal"
                object="?animal"/>
        <triple subject="?animal"
                predicate="http://www.some-fictitious-zoo.com/rdf#name"
                object="?name"/>
        <triple subject="?human"
                predicate="http://www.some-fictitious-zoo.com/rdf#name"
                object="?humanname"/>
      </conditions>
      <action>
        <treechildren flex="1">
          <treeitem uri="?animal">
            <treerow>
              <treecell label="?name"/>
              <treecell label="?humanname"/>
            </treerow>
          </treeitem>
        </treechildren>
      </action>
    </rule>
    <rule>
      <conditions>
        <content uri="?uri"/>
        <member container="?uri" child="?animal"/>
        <triple subject="?animal"
                predicate="http://www.some-fictitious-zoo.com/rdf#name"
                object="?name"/>
      </conditions>
      <action>
        <treechildren flex="1">
          <treeitem uri="?animal">
            <treerow>
              <treecell label="?name"/>
              <treecell label=""/>
            </treerow>
          </treeitem>
        </treechildren>
      </action>
    </rule>
  </template>
</tree>
Copyright © 1999 - 2005 XULPlanet.com