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.
<hbox> <button label="Animals" type="menu" datasources="animals.rdf" ref="http://www.some-fictitious-zoo.com/all-animals"> <template> <rule iscontainer="true"> <menupopup> <menu uri="rdf:*" label="rdf:http://www.some-fictitious-zoo.com/rdf#name"/> </menupopup> </rule> <rule> <menupopup> <menuitem uri="rdf:*" label="rdf:http://www.some-fictitious-zoo.com/rdf#name"/> </menupopup> </rule> </template> </button> </hbox>