Index

Example: Generate items with strings from various nodes concatenated

This template generates a label listing favorite animals. We use a set of triples to get the human names, the list of animals, and the animal names. In the label, we put a number of variables to display a somewhat formatted string. The ^ symbol means to concatenate without adding a space, and is used here to pluralize the animal name. Naturally, this technique will only work for words for which adding an s is the correct way to pluralize it.

The results are displayed in an arbitrary order since the favorite animals list is not in a sequence. Note that both the human names and the animal names are displayed correctly even though we iterate over the favorite animals. This is because the template builder maintains the variable bindings for each step of the process.

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="?human"/>
          <triple subject="?human"
                  predicate="http://www.some-fictitious-zoo.com/rdf#name"
                  object="?humanname"/>
          <triple subject="?human"
                  predicate="http://www.some-fictitious-zoo.com/rdf#favoriteAnimal"
                  object="?favoriteAnimal"/>
          <triple subject="?favoriteAnimal"
                  predicate="http://www.some-fictitious-zoo.com/rdf#name"
                  object="?animalname"/>
      </conditions>
      <action>
        <label uri="?favoriteAnimal" value="?humanname likes ?animalname^s"/>
      </action>
    </rule>
  </template>
</vbox>
Copyright © 1999 - 2005 XULPlanet.com