Index

Example: Generate a list of items using source and type checks

This template iterates over the list of humans, then recurses to iterate over their favorite animals. The animals are displayed along with their class. The class needs to be retrieved using an inner arc pointing to the animal. This is done using the member tag in the second rule. Given the list of animals stored in the ?animal variable, the ?animalClass variable will be given the value of any parent resources of each animal. The next triple filters out all nodes which are not class types. This is necessary because some of the animals have multiple parents since they are children of the class and of the list of pets.

Note that the variable ?animal is used in the uri attribute for both rules, even though the first rule generates a list of humans. This is needed because the variable used in uri attribute must be the same in all rules, although each rule will generate different data for the variable.

View   View Data Source

<vbox datasources="animals.rdf" ref="http://www.some-fictitious-zoo.com/humans">
  <template>
    <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>
        <vbox uri="?animal">
          <label class="header" value="The favorite animals of ?name"/>
        </vbox>
      </action>
    </rule>
    <rule>
      <conditions>
          <content uri="?uri"/>
          <triple subject="?uri"
                  predicate="http://www.some-fictitious-zoo.com/rdf#favoriteAnimal"
                  object="?animal"/>
          <member container="?animalClass" child="?animal"/>
          <triple subject="?animalClass"
                  predicate="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
                  object="http://www.some-fictitious-zoo.com/rdf#Class"/>
          <triple subject="?animal"
                  predicate="http://www.some-fictitious-zoo.com/rdf#name"
                  object="?name"/>
          <triple subject="?animalClass"
                  predicate="http://www.some-fictitious-zoo.com/rdf#name"
                  object="?animalClassName"/>
      </conditions>
      <action>
        <label uri="?animal" class="indent" value="?name which belongs to the class ?animalClassName"/>
      </action>
    </rule>
  </template>
</vbox>
Copyright © 1999 - 2005 XULPlanet.com