When creating recursive menus, you will need to use multiple rules, since leaf items will need to be created differently than non-leaf items. Leaf items will need to use a <menuitem> element whereas non-leaf items will need to use a <menu> element. This will involve at least two rules, although you might use other rules if you had other differences to handle.

<button label="Houses in my Neighbourhood" type="menu"
        datasources="template-guide-streets.rdf"
        ref="http://www.xulplanet.com/rdf/myneighbourhood"
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <template>
    <rule rdf:type="http://www.xulplanet.com/rdf/House">
      <menupopup>
        <menuitem uri="rdf:*" label="rdf:http://www.xulplanet.com/rdf/address"/>
      </menupopup>
    </rule>
    <rule>
      <menupopup>
        <menu uri="rdf:*" label="rdf:http://purl.org/dc/elements/1.1/title"/>
      </menupopup>
    </rule>
  </template>
</button>

The first rule matches all houses, while the second rule is used for streets. The content generated for each rule differs in only two ways. First, the menu tag is different (menuitem versus menu), and the label is taken from a different RDF predicate. In the first pass, the second rule matches the streets, so a <menupopup> and <menu> element are created. The uri attribute is on the <menu> element since we don't want to repeat the popup for every result. After the first pass, the content will be equivalent to the following (ignoring the template related content):

<button label="Houses in my Neighbourhood" type="menu">
  <menupopup>
    <menu uri="http://www.xulplanet.com/rdf/marion" label="Marion Street"/>
    <menu uri="http://www.xulplanet.com/rdf/garden" label="Garden Avenue"/>
  </menupopup>
</button>

The inner pass through the data handles the houses. The houses match the first rule so a <menupopup> and <menuitem> element are generated and inserted inside the street content (the <menu> element). Again, the popup is only created once since the uri attribute is on the <menuitem> element. The effect is a menu with a submenu. There's nothing special about the way menus are handled -- the builder follows the same method for any type of content. However, the nature of menus can make this tricky to follow. Here is the result of the above example after both levels have been handled.

<button label="Houses in my Neighbourhood" type="menu">
  <menupopup>
    <menu uri="http://www.xulplanet.com/rdf/marion" label="Marion Street">
      <menupopup>
        <menuitem uri="http://www.xulplanet.com/rdf/garden/16" label="16"/>
        <menuitem uri="http://www.xulplanet.com/rdf/garden/18" label="18"/>
      </menupopup>
    </menu>
    <menu uri="http://www.xulplanet.com/rdf/garden" label="Garden Avenue">
      <menupopup>
        <menuitem uri="http://www.xulplanet.com/rdf/garden/25" label="25"/>
        <menuitem uri="http://www.xulplanet.com/rdf/garden/37" label="37"/>
      </menupopup>
    </menu>
  </menupopup>
</button>