Index

Example: Match items from two lists

Here we want to determine which of Robert's pets are also his favorite animals. Essentially, we want to find out what items appear in two lists. The results we desire are 'Chameleon' and 'Tarantula'. To begin, we iterate over Robert's favorite animals using the first triple. Next, we use another triple and a member to iterate over Robert's pets. Both a triple and a member are necessary to get from Robert to the pet container and finally to the pets.

The key here is that both lists use the same variable 'favoriteAnimal'. This causes the template to first generate the list of favorite animals and add them to this variable, since this condition comes first in the list of rules. Then, it builds the list of pets, and adjusts the same variable to filter out the ones that don't match both lists.

View   View Data Source

<vbox datasources="animals.rdf" ref="http://www.some-fictitious-zoo.com/humans/robert">
  <template>
    <rule>
      <conditions>
          <content uri="?uri"/>
          <triple subject="?uri"
                  predicate="http://www.some-fictitious-zoo.com/rdf#favoriteAnimal"
                  object="?favoriteAnimal"/>
          <triple subject="?uri"
                  predicate="http://www.some-fictitious-zoo.com/rdf#pets"
                  object="?pets"/>
          <member container="?pets" child="?favoriteAnimal"/>
          <triple subject="?favoriteAnimal"
                  predicate="http://www.some-fictitious-zoo.com/rdf#name"
                  object="?name"/>
      </conditions>
      <action>
        <label uri="?favoriteAnimal" value="?name"/>
      </action>
    </rule>
  </template>
</vbox>
Copyright © 1999 - 2005 XULPlanet.com