Here is an example of a rule set that demonstrates use of many of the tags and operators discussed in this chapter. It also shows how you can form complex rules that combine rules and nest one rule inside another.

The accept rules test whether content that is available and whether the author property of the repository item matches the favoriteAuthor attribute in the source profile.

The reject rules exclude content that is rated R if the user profile’s age is less than 16 and exclude content that is rated X if the user profile’s age is less than 18.

The sorting directive declared in the <sortby> tag specifies that the targeting results are to be sorted first by the lastModified property, from most recent to oldest, and secondarily by the name property of the target objects, in alphabetical order.

When you put it all together, this rule outputs content:

<ruleset>
  <!-- accept rules -->
  <accepts>
    <rule op=and>
      <rule op=eq>
        <valueof target="isAvailable">
        <valueof constant="true">
      </rule>
      <rule op=eq>
        <valueof target="author">
        <valueof bean="Profile.favoriteAuthor">
      </rule>
    </rule>
  </accepts>

  <!-- reject rules -->
  <rejects>
    <rule op=and name="Rated R">
      <rule op=lt>
        <valueof bean="Profile.age">
        <valueof constant="16">
      </rule>
      <rule op=eq>
        <valueof target="rating">
        <valueof constant="R">
      </rule>
    </rule>
    <rule op=and name="Rated X">
      <rule op=lt>
        <valueof bean="Profile.age">
        <valueof constant="18">
      </rule>
      <rule op=eq>
        <valueof target="rating">
        <valueof constant="X">
      </rule>
    </rule>
  </rejects>

  <!-- sorting directives -->
  <sortby>
    <sortbyvalue value="lastModified" dir=descending>
    <sortbyvalue value="name" dir=ascending>
  </sortby>
</ruleset>
 
loading table of contents...