Export (0) Print
Expand All

elseif

Provides an alternative conditional statement in an if construct.

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

cond

Required. An ECMAScript expression that evaluates to true or false.

If the cond attribute of the containing if and any preceding elseif elements evaluate to false, the cond attribute of the elseif element is evaluated. If the expression evaluates to true, the content between the elseif element and the next conditional element or closing if tag is executed.

To use a less-than (<), greater-than (>), or and (&&) condition in a elseif element, replace the symbols with the &lt; &gt;, or &amp;&amp; entities respectively.

The cond attributes considers expressions that evaluate to 0, -0, null, false, NaN, undefined, and the empty string to be false. All other values, including the strings "0" and "false", are equivalent to true.

The following example requests 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>

Community Additions

ADD
Show:
© 2014 Microsoft