<if>
Specifies a conditional logic expression. The <if> element allows you to change control flow based on the evaluation of a conditional expression.
Attributes
This section describes the attributes you can set for this element.
Name |
Data type |
Default |
---|---|---|
CDATA |
required |
cond
The cond attribute specifies the conditional expression to evaluate, for example:
<if cond="count == 0">
<goto next="#NoOrderMessage" />
</if>
If the conditional expression "count == 0" evaluates to true, no order is placed and execution flow is passed to the NoOrderMessage form.
Note: The <else> and <elseif> elements can be used within the <if> element to specify alternate actions taken if the conditional expression evaluates to false.
Any valid Boolean expression can be specified for the cond attribute. Any null expression evaluates to false, and any defined expression evaluates to true.
Children
- Parsed character data
- <assign>
- <audio>
- <clear>
- <data>
- <disconnect>
- <else>
- <elseif>
- <enumerate>
- <exit>
- <foreach>
- <goto>
- <if>
- <log>
- <prompt>
- <reprompt>
- <return>
- <script>
- <nuance:send>
- <submit>
- <nuance:taskbegin>
- <nuance:taskend>
- <throw>
- <value>
- <var>
Parents
Sample code
<vxml
<form>
<field name="grammar_or_dtmf">
<prompt>Press or say a number between 1 and
3.</prompt>
<grammar> [one two three] </grammar>
<dtmf> [dtmf-1 dtmf-2 dtmf-3] </dtmf>
<filled>
<if cond="grammar_or_dtmf == 'one'">
<prompt>you said one</prompt>
<elseif cond="grammar_or_dtmf == 'two'"/>
<prompt>you said two</prompt>
<elseif cond="grammar_or_dtmf == 'three'"/>
<prompt>you said three</prompt>
<else/>
<prompt>you pressed <value expr=
"grammar_or_dtmf.charAt(5)"/></prompt>
</if>
</filled>
</field>
</form>
</vxml>
For a VoiceXML sample demonstrating the use of the <if> element, see Blackjack.vxml located in the $NVP_HOME/appservice/applications/webapps/BlackJack directory. For information about samples, see Sample applications.