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 repeatable="true" undoable="true" label="Convert to Bold"> <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:
Explicitly selecting (using command selectNode) the emphasis
element if such element is implicitly (or explicitly) selected;
OR converting anything else to an emphasis
element, using command convert.
If all alternatives cannot be executed (this is tested before attempting to actually execute the choice construct), the whole choice construct cannot be executed.