3. Alternative commands

The above macro needs to be refined. If an emphasis element is implicitly or explicitly selected and this element has no role attribute or a role different from bold, we would like to add to it attribute role with value bold.

The following macro uses a choice element to do this:

  <command name="convertToBold2">
    <macro>
      <sequence>
        <choice>
          <command name="selectNode" 
                   parameter="self[implicitElement] emphasis" />
          <command name="convert" 
                   parameter="[implicitElement] emphasis" />
        </choice>

        <command name="putAttribute" parameter="role bold" />
      </sequence>
    </macro>
  </command>

The choice element will execute the first alternative which can be executed:

If all alternatives cannot be executed (this is tested before attempting to actually execute the choice construct), the whole choice construct cannot be executed.