Larson Technical Services: Voice Technology Consulting

Exercise 9.3

Construct a VoiceXML form that presents the result of the query of exercise 9-2 to the caller.

The VoiceXML code in Figure 4.9 enables callers to browse a list of call rings, we will modify that code to browse a list of employees returned by the database management system.


<?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">

<!-- Example data    --> 
<!-- Exercise 9.3 --> 

<script>

     <![CDATA[

          var name = new Array()

          name[0] = "Able"; 
          name[1] = "Baker"
          name[2] = "Carson"; 

          var ID = new Array()

          ID[0] = "001"; 
          ID[1] = "002";
          ID[2] = "003";

          var salary = new Array()

          salary[0] = "87000"; 
          salary[1] = "94000";
          salary[2] = "53000";

          var address = new Array()

          address[0] = "Anchorage Avenue"; 
          address[1] = "Brookhaven Street";
          address[2] = "Carlisle Drive";

          var city = new Array()

          city[0] = "Seattle"; 
          city[1] = "Portland";
          city[2] = "Seattle";

          var state = new Array()

          state[0] = "Washington"; 
          state[1] = "Oregon";
          state[2] = "Washington";

          var zip = new Array()

          zip[0] = "98766"; 
          zip[1] = "97012";
          zip[2] = "98763";

          // set listindex
          var listindex = 0;
          var listlength = name.length;

          //set current as first list element
          var current_name = name[listindex];
          var current_ID = ID[listindex];
          var current_salary = salary[listindex];
          var current_address = address [listindex];
          var current_city = city[listindex];
          var current_state = state[listindex];
          var current_zip = zip[listindex];
     ]]>

</script>

<form id="start"> 
     <block>
          <prompt> There are <value expr="listlength"/> employees satisfying your query </prompt>
          <prompt>To hear them, say repeat, next, or previous </prompt>
          <goto next="#navchoice"/>
     </block>
</form>

<menu id="navchoice">
     <prompt>
          the employee name is <value expr="current_name"/>.
          the employee number is <value expr="current_ID"/>.
          the employee salary is <value expr="current_salary"/>.
          the employee address is <value expr="current_address"/>.
          the employee city <value expr="current_city"/>.
          the employee state is <value expr="current_state"/>.
          the employee zip code is <value expr="current_zip"/>.
     </prompt>
     <choice next="#next">
          <grammar type="application/grammar+xml" version="1.0"
               root = "choose_next">
          <rule id = "choose_next" scope = "public">
               <item> next </item>
          </rule>
     </grammar>
     </choice>
     <choice next="#previous">
          <grammar type="application/grammar+xml" version="1.0"
               root = "choose_previous">
          <rule id = "choose_previous" scope = "public">
               <item> previous </item>
          </rule>
          </grammar>
     </choice>
     <choice next="#navchoice">
          <grammar type="application/grammar+xml" version="1.0"
               root = "choose_repeat">
          <rule id = "choose_repeat" scope = "public">
               <item> repeat </item>
          </rule>
          </grammar> 
     </choice>
</menu>

<form id="previous">
     <block>
          <script>

          <![CDATA[  

               if (listindex > 0)
                    {
                         listindex--;
                         current_name = name[listindex];
                         current_ID = ID[listindex];
                         current_salary = salary[listindex];
                         current_address = address [listindex];
                         current_city = city[listindex];
                         current_state = state[listindex];
                         current_zip = zip[listindex];
                    }
               else
                    {  
                         listindex = listlength - 1;
                         current_name = name[listindex];
                         current_ID = ID[listindex];
                         current_salary = salary[listindex];
                         current_address = address [listindex];
                         current_city = city[listindex];
                         current_state = state[listindex];
                         current_zip = zip[listindex];
                    }
          ]]>

          </script>
     <goto next="#navchoice"/>
     </block>
</form>

<form id="next">
     <block>
          <script>

          <![CDATA[
                         listindex++;
                         if (listindex < listlength)
                    {
                         current_name = name[listindex];
                         current_ID = ID[listindex];
                         current_salary = salary[listindex];
                         current_address = address [listindex];
                         current_city = city[listindex];
                         current_state = state[listindex];
                         current_zip = zip[listindex];
                    }
               else
                    {
                         listindex = 0;
                         current_name = name[listindex];
                         current_ID = ID[listindex];
                         current_salary = salary[listindex];
                         current_address = address [listindex];
                         current_city = city[listindex];
                         current_state = state[listindex];
                         current_zip = zip[listindex];
                    }
          ]]>

          </script>

          <goto next="#navchoice"/>
     </block>
</form>
</vxml>

Return to the Instructor’s Page

Comments are off for this post