The workflow is:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<workflow xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" wfd_version="1.0" reporting="false"
          id="choice" name="choice" descriptor="Choice component" startstep="choose"
          xsi:noNamespaceSchemaLocation="../../../configuration/workflow.xsd">

    <steps>
        <step id="choose" descriptor="the user selects between two options" uitemplate="ChoiceScreen">
            <states>
                <onevent>
                    <rule id="menu_button_selection">
                        <expression>#{event:command} == 'APPLE' || #{event:command} == 'PEAR'</expression>
                        <actions>
                            <finish_workflow id="finish_workflow">
                                <output>
                                    <param name="selected_button" type="string">#{event:command}</param>
                                </output>
                            </finish_workflow>
                        </actions>
                    </rule>
                </onevent>
            </states>
        </step>
    </steps>
</workflow>

Explanation of the workflow

1. The workflow tag contains an attribute startstep="choose". This is used to select which step will be performed first after initializing the component.

2. <step id="choose"... is used to refer to a choice that will be further displayed using uitemplate="ChoiceScreen". ChoiceScreen is a file that defines what is displayed on the screen while we are in this step.

As explained, the behavior of a component is defined using rules. A rule consists of an expression (or condition) and which action to take when that condition is True. Each rule is assigned to one of the states <onenter>,  <onresume><onleave> , <onevent> or  <onpause> . Rules will only be checked when the component is in that state (e.g., onenter - when the component is first started).

3.  The <rule id="menu_button_selection"> is assigned to the <onevent> state. Whenever an event occurs, all rules given to this state will be checked. Here, <expression>#{event:command} == 'APPLE' || #{event:command} == 'PEAR'</expression> checks whether the event contains a specific command. Such an event would be activated when a button with the name "APPLE" or "PEAR" is triggered either by voice command or pressing it on the screen.

4. If a rule expression evaluates to true, the set of actions in the rule's <actions> tag is executed. In this example, the finish_workflow action is used. This immediately leaves the component once the user has chosen one of the two options, and passes on which choice was made in a <output> parameter so that we can create different transitions in the workflow diagram based on that choice.