Iterates through an ECMAScript array, executing the contained executable content for each item in the array. Typically, <foreach> is used to concatenate prompts dynamically.
<foreach
array="CDATA"
item="identifier">
<!-- do something -->
</foreach>
Attribute |
Data Type |
Required? |
Default |
Description |
array |
CDATA |
yes |
NA |
ECMAScript expression that must evaluate to an array; otherwise, an error.semantic event is thrown. |
item |
identifier |
yes |
NA |
Variable that stores each array item upon each iteration of the loop. A new variable is declared if it is not already defined within the parent's scope. |
<block>, <catch>, <error>, <filled>, <foreach>, <help>, <if>, <noinput>, <nomatch>, <prompt>
<assign>, <audio>, <clear>, <data>, <disconnect>, <else>, <elseif>, <enumerate>, <exit>, <foreach>, <goto>, <if>, <log>, <prompt>, <reprompt>, <return>, <script>, <submit>, <throw>, <value>, <var>
foreach
<?xml version="1.0"?>
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml">
<script>
var movies = new Array(3);
movies[0] = new Object();
movies[0].audio = "godfather.wav";
movies[0].tts = "the godfather";
movies[1] = new Object();
movies[1].audio = "high_fidelity.wav";
movies[1].tts = "high fidelity";
movies[2] = new Object();
movies[2].audio = "raiders.wav";
movies[2].tts = "raiders of the lost ark";
</script>
<form id="pick_movie">
<field name="movie">
<grammar type="application/srgs+xml" src="movie_names.grxml"/>
<prompt>
<audio src="prelist.wav">
When you hear the name of the movie you want,
just say it.
</audio>
<foreach item="thePrompt" array="movies">
<audio expr="thePrompt.audio">
<value expr="thePrompt.tts"/>
</audio>
<break time="300ms"/>
</foreach>
</prompt>
</field>
</form>
</vxml>