Larson Technical Services: Voice Technology Consulting

Exercise 8.4

Repeat exercise 10-3 except confirm each pizza and drink as they are entered.


<?xml version="1.0"?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" 
 "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
 <vxml version="2.0" xmlns = "http://www.w3.org/2001/vxml">

<!-exercise 8.4  get drinks (get pizza oderings not implemented)  -->
<!-- get drink  --> 

<script>
     <![CDATA[

          var drink_size = new Array();
          var drink_content = new Array(); 

     // set listindex
     var drink_list_index  = 0;

     ]]>
</script>

<form id="get_drink"> 
     <field name = "current_drink_size">
          <prompt> Drink size: <break/> small, medium, or large? </prompt>
          <grammar type="application/grammar+xml" root = "drink_glass">
               <rule id = "drink_glass" scope = "public">
                    <one-of>
                         <item> small </item>
                         <item> medium </item>
                         <item> large </item>
                    </one-of>
               </rule>
          </grammar>
     </field>  

     <field name = "current_drink_content">
          <prompt> Which drink? <break/> coke, pepsi, dietpepsi, lemonade, water? </prompt>
          <grammar type="application/grammar+xml" root = "drink_kind">
               <rule id = "drink_kind" scope = "public">
                    <one-of>
                         <item> coke </item>
                         <item> pepsi </item>
                         <item> dietpepsi </item>
                         <item> lemonade </item>
                         <item> water </item>
                    </one-of>
               </rule>
          </grammar>
     </field>

     <field name = "validate" >
          <grammar type = "application/grammar+xml" version = "1.0" root = "yes_no2">
               <rule id = "yes_no2" scope = "public">
                    <one-of>
                         <item>yes</item>
                         <item>no</item>
                    </one-of>
               </rule>
          </grammar>
          <prompt>
               Do you want <value expr = "current_drink_size"/>
                    <value expr = "current_drink_content"/>
          </prompt>
     </field>

     <filled>
          <if cond = "validate == 'no'" >
               <prompt> Let me ask that again  </prompt> 
               <goto next="#another_drink"/>
          </if>
          <script>
               <![CDATA[

                    drink_size[drink_list_index] = current_drink_size;
                    drink_content[drink_list_index] = current_drink_content;
                    drink_list_index = drink_list_index + 1;

               ]]>
          </script>
          <goto next="#another_drink"/>
     </filled>
</form>

<form id="another_drink">
     <field name="more">
          <prompt>do you want another drink? </prompt>
          <grammar type = "application/grammar+xml" root = "yes_no">
               <rule id = "yes_no" scope = "public">
                    <one-of>
                         <item> yes </item>
                         <item> no </item>
                    </one-of>
               </rule>
          </grammar>
          <filled>
               <if cond = "more == 'yes'"> 
                    <goto next="#get_drink"/>
               </if>
               <submit namelist= "drink_list_index drink_size drink_content"/>
          </filled>        
     </field>
</form> 
</vxml>

Return to the Instructor’s Page

Comments are off for this post