Example: Generate a recursive menu

This template generates a recursive menu. It uses two rules, the first for containers and the second for leaf nodes. The first rule matches all containers as indicated by the iscontainer attribute. The will create a <menupopup> once but repeat a <menu> for every result. For leaf nodes, the second rule is used instead which will generate the <menupopup> but use a <menuitem> inside instead. Both rules have the outer menupopup, yet it will only be generated once since only the content with the uri attribute will be generated for each result.

For the first iteration (the animal classes), all items are containers so a menupopup and five menus are generated. The template builder will recurse to each animal. The animals are all leaf nodes so will use the second rule. This content will be placed inside the parent's container with the uri attribute, in this case, the <menu>. This will result in the second rule's menupopup and menuitem to be added. Again, the menupopup is only generated once for all items.

If a container had some items that are containers and some that are leaves, the menupopup would contain a mix of menus and menuitems. However, again, only one menupopup would be generated.

View   View Data Source

  <button label="Animals" type="menu" datasources="animals.rdf"
      <rule iscontainer="true">
          <menu uri="rdf:*" label="rdf:"/>
          <menuitem uri="rdf:*" label="rdf:"/>
Copyright © 1999 - 2005