问题
How to concat varible in VXML. consider following example VXML,
<?xml version="1.0" encoding="UTF-8"?>
<vxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3.org/2001/vxml" version="2.0" xsi:schemaLocation="http://www.w3.org/2001/vxml http://www.w3.org/TR/voicexml20/vxml.xsd">
<form>
<block>
<audio src="{url1}"/>
<audio src="{url2}"/>
</block>
<field name="dtmf">
<option dtmf="1" value="1"/>
<option dtmf="2" value="2"/>
<option dtmf="2" value="3"/>
<filled>
<submit next="{url3}" namelist="action toneId dtmf" method="get"/>
</filled>
</field>
<noinput>
<reprompt/>
</noinput>
<nomatch>
<reprompt/>
</nomatch>
</form>
</vxml>
{url3} = {some string} + {some variable=value}, I want to get like this, There are url3 get concating two value.
回答1:
Change:
<submit next="{url3}" namelist="action toneId dtmf" method="get"/>
to
<submit expr="{some string} + {some variable=value}" namelist="action toneId dtmf" method="get"/>
or for a more concrete example:
<submit expr="'http://yourserver.com/api/' + servletName" namelist="action toneId dtmf" method="get"/>
回答2:
The previous answer is correct, but let me add an additional line or two that shows how to use namelist
and field
.
<field name="dtmf">
That name is a bit confusing.You're defining a variable name, and "dtmf" is used elsewhere in the document; let's call it "response" instead to avoid problems.
<field name="response">
You allow for options, which is fine:
<option dtmf="1" value="1"/>
<option dtmf="2" value="2"/>
<option dtmf="2" value="3"/>
Of course the values can be anything, such as
<option dtmf="1" value="meat"/>
<option dtmf="2" value="fish"/>
<option dtmf="2" value="dairy"/>
and I want to point out here that the value
above does not accept an ECMAScript value; it's just plain text, one of the oddities of VoiceXML.
Set up the values of the other variables you want to send:
<var name="toneId" expr="12"/>
<var name="action" expr="'scream'"/>
And expr
does require an ECMAScript expression. "toneID" is set to a Number and "action" has been set to a String. You can also do this instead, if you need to:
<var name="foo" expr="'scream'"/>
<var name="action" expr="foo"/>
The field "response" will be filled in automatically with the value the user selected. You can also use the so-called "shadow variables" if you like and send them instead; see the VoiceXML spec http://www.w3.org/TR/2004/REC-voicexml20-20040316/#dml2.3.1.
Finally, as Jim says,
<submit expr="'http://example.com/api/' + servletName" namelist="action toneId response" method="get"/>
Hope this helps.
来源:https://stackoverflow.com/questions/32351207/how-to-concat-varible-in-vxml