else element
VoiceXML 2.0
Provides the final alternative in an if construct.

Syntax

<if cond="ECMAScript_Expression">
   <!-- executable content -->
<elseif cond="ECMAScript_Expression"/>
   <!-- executable content -->
<elseif cond="ECMAScript_Expression"/>
   <!-- executable content -->
<else/>
   <!-- executable content -->
</if>

Parents
if

Children
None.

Remarks
If the cond attributes of the containing if and preceding elseif elements evaluate to false, the content between the else element and the closing if tag is executed.
Examples

The following example request the name of a flower from the user, compares the value returned by the grammar, and plays back audio about the flower.

<?xml version="1.0"?>
<vxml version="2.1"
 xmlns="http://www.w3.org/2001/vxml">
   <link event="event.exit">
   
   <grammar mode="voice"
         root="root_rule"
         tag-format="semantics/1.0"
         type="application/srgs+xml"
         version="1.0"
         xml:lang="en-US">
      <rule id="root_rule" scope="public">
         <one-of>
            <item>
               quit
            </item>
         </one-of>
      </rule>

   </grammar>

   
   <grammar mode="dtmf"
         root="root_rule"
         tag-format="semantics/1.0"
         type="application/srgs+xml"
         version="1.0">
      <rule id="root_rule" scope="public">
         <one-of>
            <item>
               *
               *
            </item>
         </one-of>
      </rule>

   </grammar>

   </link>

   <catch event="event.exit">
      <exit />
   </catch>

   <link event="help">
   
   <grammar mode="voice"
         root="root_rule"
         tag-format="semantics/1.0"
         type="application/srgs+xml"
         version="1.0"
         xml:lang="en-US">
      <rule id="root_rule" scope="public">
         <one-of>
            <item weight="0.5">
               help
            </item>
            <item weight="0.5">
               mercy
            </item>
         </one-of>
      </rule>

   </grammar>

   
   <grammar mode="dtmf"
         root="root_rule"
         tag-format="semantics/1.0"
         type="application/srgs+xml"
         version="1.0">
      <rule id="root_rule" scope="public">
         <one-of>
            <item>
               0
            </item>
         </one-of>
      </rule>

   </grammar>

   </link>

   <form id="pick_flower">
   <field name="flower">
      <prompt>
      Pick a flower
      </prompt>

      
      <grammar mode="voice"
         root="root_rule"
         tag-format="semantics/1.0"
         type="application/srgs+xml"
         version="1.0"
         xml:lang="en-US">
            <rule id="root_rule" scope="public">
                  <one-of>
                        <item>
                              <one-of>
                                    <item>
                                          rose
                                    </item>
                                    <item>
                                          roses
                                    </item>
                              </one-of>
                              <tag>out.flower = "rose";</tag>
                        </item>
                        <item>
                              <one-of>
                                    <item>
                                          violet
                                    </item>
                                    <item>
                                          violets
                                    </item>
                              </one-of>
                              <tag>out.flower = "violet";</tag>
                        </item>
                        <item>
                              <one-of>
                                    <item>
                                          grass
                                    </item>
                                    <item>
                                          grasses
                                    </item>
                              </one-of>
                              <tag>out.flower = "grass";</tag>
                        </item>
                        <item>
                              <one-of>
                                    <item>
                                          tulip
                                    </item>
                              </one-of>
                              <tag>out.flower = "tulip";</tag>
                        </item>
                  </one-of>
            </rule>

      </grammar>


      <!-- handle the first noinput for this field -->
      <catch event="noinput nomatch">
         I'm sorry. I didn't get that.
         <throw event="help"/>
      </catch>

      <!-- handle all help events for this field -->
      <help>
         Say rose, violet, grass, tulip. Say quit at any time to exit.
      </help>

      <filled>
         <if cond="'rose' == flower">
            roses are red
         <elseif cond="'violet' == flower"/>
            violets are blue
         <elseif cond="'tulip' == flower"/>
            tulips come in many colors
         <else/>      
            the grass is greener over here.
         </if>
         <clear/>
      </filled>

      </field>
   </form>
</vxml>



[24]7 Inc.| Terms of Service| Privacy Policy| General Disclaimers