In this section we'll see how attributes can be inherited.
Inherited Attributes
XBL allows us to build composite widgets while hiding their actual implementation. However, with the features mentioned so far, the anonymous content is always created in the same way. It would be useful to add attributes to the bound elements that modify the inner elements. For example:
XUL:
<searchbox/>
XBL:
<binding id="searchBinding">
  <content>
    <xul:textbox/>
    <xul:button label="Search"/>
  </content>
</binding>
In the example, the labelbuttoninherits attribute which can be used to inherit attributes from the bound element. It should be placed on the element that should inherit an attribute from the outer element, in this case the button. Its value should be set to a comma-separated list of attribute names that are to be inherited.
<xul:textbox xbl:inherits="flex"/> <xul:button xbl:inherits="label"/>
When the content is generated, the textboxflex attribute from the searchbox and the buttonlabelinherits attribute to as many elements as you wish, to inherit any number of attributes.
Note how the inherits attribute has been placed in the XBL namespace, by prefixing it with 'xbl:'. The namespace should be declared somewhere earlier, usually on the bindings
<bindings xmlns:xbl="http://www.mozilla.org/xbl"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<xbl:binding id="buttonBinding">
  <xbl:content>
    <xul:button label="OK" xbl:inherits="label"/>
  </xbl:content>
</xbl:binding>
In this example, the button inherits the labellabellabelOK.
There may be times where two generated elements need to inherit from an attribute that has the same name. For example, to create a labeled textbox (a textbox with a text description beside it) out of a labeltextboxvaluevalue
XUL:
<box class="labeledtextbox" title="Enter some text:" value="OK"/>
CSS:
box.labeledtextbox {
    -moz-binding: url('chrome://example/skin/example.xml#labeledtextbox');
}
XBL: 
<binding id="labeledtextbox">
  <content>
    <xul:label xbl:inherits="value=title"/>
    <xul:textbox xbl:inherits="value"/>
  </content>
</binding>
The textboxvaluevalueinherits attribute on the label grabs the title attribute from the labeledtextbox and maps it to the valuelabel<inner attribute>=<outer attribute> is used to map one attribute to another. Here is another example:
XUL:
<box class="okcancel" oktitle="OK" canceltitle="Cancel" image="happy.png"/>
CSS:
box.okcancel {
    -moz-binding: url('chrome://example/skin/example.xml#okcancel');
}
XBL:
<binding id="okcancel">
  <content>
    <xul:button xbl:inherits="label=oktitle,image"/>
    <xul:button xbl:inherits="label=canceltitle"/>
  </content>
</binding>
The value of the oktitle attribute is mapped to the labelcanceltitle attribute is mapped to the labelimage
<box class="okcancel" oktitle="OK" canceltitle="Cancel" image="happy.png"> <button label="OK" image="happy.png"/> <button label="Cancel"/> </box>
Note that the attributes are duplicated on the inner (anonymous) content. Changing the attributes on the box with the okcancel class will automatically change the values on the buttons. You may also have noticed that we just made up our own attribute names. This is valid in XUL.
If you need to map an attribute to the text content of the node, use "xbl:text" as the inner attribute, eg:
<xul:description xbl:inherits="xbl:text=value"/>
In the next section, we look at adding properties, methods and events to a binding.