| VoiceXML 2.1 Development Guide | Home | Frameset Home |
| cond | Data Type: CDATA | Default: Required |
| The cond attribute specifies any valid expression, which equates to the value to be evaluated. | ||
| <?xml version="1.0" encoding="UTF-8"?>
<vxml version = "2.1" xmlns="http://www.w3.org/2001/06/grammar"> <meta name="copyright" content="2012 voxeo corporation"/> <meta name="maintainer" content="YOUR_EMAIL@HERE.COM"/> <form id="F1"> <field name="F_1"> <prompt> who would win in a fist fight, Oprah, Madonna, or James Brown? </prompt> <grammar xml:lang="en-us" root="myrule"> <rule id="myrule"> <one-of> <item> Oprah </item> <item> Madonna </item> <item> James Brown </item> </one-of> </rule> </grammar> <filled> <if cond="F_1=='Oprah'"> <prompt> You really think Oprah could duke it out with the Godfather of soul? </prompt> <elseif cond="F_1=='Madonna'"/> <prompt> Madonna would get creamed, who do you think you are kidding? </prompt> <else/> <prompt> James Brown would whip up on both Oprah and Madonna. </prompt> </if> </filled> </field> </form> </vxml> |
| ANNOTATIONS: EXISTING POSTS |
DaveMorris
|
|
| You should mention that to use a less-than (<), greater-than (>), or and (&&) condition in a if element, you must replace the symbols with the escaped versions, i.e. ampersand LT semicolon, etc. Otherwise you'll get a error.semantic XML parse error at runtime. Took me 8 hours of wasted time to discover this.
Dave |
|
kevinlim
|
|
| Dave,
Thanks for the input. We will look into compiling a list of common practices. As with any other markup languages that use special characters, escape characters are necessary to disambiguate your code. A complete specification of this is found in the W3C XML page: http://www.w3.org/TR/REC-xml/#syntax When generating VoiceXML, it's always good to view the source produced in a webbrowser, so you can see what the VoiceXML browser sees. If you have any other comments or questions, feel free to contact us: support@voxeo.com Best, Kevin |
|
lambchops7
|
|
| What if we wanted the if to satisfy any number of conditions.
Will this suffice? It doesn't seem to work for me. <filled> <if cond="F_1=='oprah' || 'one' || 'DTMF-1'"> <prompt> you really think Oprah could duke it out with the Godfather of soul? </prompt> </if> </filled> |
|
voxeojeff
|
|
| Hi there,
This is certainly possible. I'll attach a sample script below that will allow such a condition: <?xml version="1.0" encoding="UTF-8"?> <vxml version = "2.1"> <form id="F1"> <field name="F_1"> <prompt> Please pick a number between one and six </prompt> <grammar type="text/gsl">[ one two three four five six ] </grammar> <filled> <if cond="F_1=='one' || F_1=='two' || F_1=='three'"> <prompt> You said <value expr="F_1"/> </prompt> </if> </filled> </field> </form> </vxml> I hope this helps! Cheers, Jeff Menkel Voxeo Corporation |
|
lambchops7
|
|
| How would you write the logic if you want two conditions to be true. I don't understand the first response about replacing it with the escaped versions "ampersand".
You can imagine here that I'm getting someone's username: <filled namelist="u_check"> <if cond="u_check=='1' ampersand usr=='1234'"><goto next="#Password"/> <elseif cond="u_check=='2'"/> <goto next="#Username"/> <else/> <prompt> This is an incorrect username. Please try again. </prompt> <goto next="#Username"/> </if> </filled> usr is a variable that I declared at the beginning of the document to keep track of the usrname. I tried && or ampersand or ampersandampersand, and I can't figure it out. How do you write the logic? |
|
mikethompson
|
|
| Hello Lambchop,
If you would like more than one condition to be met in order to have the content be executed, you want to structure your if statement like so: <if cond="F_1=='one' || F_1=='two' || F_1=='three'"> As for ampersand encoding, if && does not work, you can try "&&". Hope this helps, Mike Thompson Voxeo Corporation |
|
n2731568
|
|
| Is it possible make your condition in the "if" tag be "not equal to" i.e. somthing like !=. I can't seem to find this type of condition anywhere.
Cheers Chris |
|
voxeojeremy
|
|
| Hey Chris!
Here's how to do is not equal to - Let's say we want to exit on every condition where F_1 is not equal to "moo". Here's the code for it: ----------------------------------------------- <field name="F_1"> <prompt> are cows great? </prompt> <grammar type="text/gsl">[ moo boo foo ] </grammar> <filled> <if cond="F_1=='moo'"> <prompt> well moo to you. </prompt> <else/> <exit/> </if> </filled> </field> ----------------------------------------------- |
|
chuchoomar
|
|
| <filled>
<if cond="confirm=='si'"> can i do that? <prompt xml:lang="es-es"> lindo muņeco </prompt> /else> <goto nextitem="nombre_usuario"/> </if> hey i need to know which are the diferents cojunctions....for instance how i can do ...the and, or and diferent condition in the element if.... ||....what is the meaning? &&& what is the meaning? |
|
voxeoblehn
|
|
| Hello,
This -[code] <if cond="confirm=='si'">[/code] - simply checks if the value of confirm is equal to the string 'si', which is fine. Your syntax should work, except for the missing bracket in your <else/> statement :) As for the ampersand (&&) and ||, these are conditional operators in ECMAScript. && is the AND operator, meaning that both conditions must evaluate to true for the statement to be true. For example: [code] <if cond="1 && 1 == 1"> <!-- this is true, as both 1 and 1 are equal to 1 --> <if cond="1 && 2 == 1"> <!-- this is fale, as 1 is equal to 1, but 2 is not equal to 1 --> [/code] || is the OR operator, meaning that if either condition evaluates to true, then the statement is true. For example: [code] <if cond="1 || 2 == 1"> <!-- this will evaluate to true. 2 does not equal 1, but 1 does, so at least one of our conditions is met. --> <if cond="2 || 3 == 1"> <!-- this is false, as neither 2 or 3 equal 1. --> [/code] One of the great things about CCXML and VoiceXML is the integration of ECMAScript(or JavaScript). You can find more operators and more info on them here: http://www.w3schools.com/js/js_operators.asp http://www.w3schools.com/js/js_comparisons.asp http://www.w3schools.com/js/js_if_else.asp Best Regards, Brian Lehnen Voxeo Support |
|
jefo12
|
|
| <if cond="callerid.length == 10 && callerid != 'restricted'">
<log expr="'***** CALLER ID: ' + callerid"/> <submit next="mydoc.jsp" namelist="callerid"/> <else/> <log expr="'***** CALLER ID NOT PRESENT'"/> <goto nextitem="enterPhone"/> </if> if cond="callerid.length == 10 && callerid i can't understand this can u plz explain it clearlly |
|
voxeojohnq
|
|
| Hello,
<if cond="callerid.length == 10 && callerid != 'restricted'"> <log expr="'***** CALLER ID: ' + callerid"/> <submit next="mydoc.jsp" namelist="callerid"/> <else/> <log expr="'***** CALLER ID NOT PRESENT'"/> <goto nextitem="enterPhone"/> </if> What's happening here is some fancy conditional logic. We have two conditions that BOTH need to be met in order to successfully execute a piece of code with some specific requirements. In this case, "mydoc.jsp" needs the variable "callerid" to have a specific string length and it also must not be equal to the string "restricted". If both of those conditions are not met, the next point in the program that will be executed is what is in between the <else /> and the </if> elements. The <else> section will now goto the next <form> or <block> element labeled "enterPhone". Pretty easy eh? OK, to add a little more clarification to the above code. == is the equality operator. This will test to see if the left side is equal to the right side of the equation. != is the inequality operator. This will test to see if the left side is NOT equal to the right side of the equation. && is the AND operator. This will test to see if the results of the two, (or more), equality tests are both met. Since this code is formatted in a well-formed XML document, we need to encode the ampersands as & You may want to read a little bit about boolean logic. The wikipedia is a good place to start for a thorough overview of what it is. http://en.wikipedia.org/wiki/Boolean_logic Regards, John Quinn Voxeo Support |
|
jefo12
|
|
| Thank u very much john .. | |
jefo12
|
|
| HI JOHN CAN U PLZ CHECK THIS OUT
<vxml> <var name="callerid" expr="session.callerid"/> <form id = "callerid"> <field name="caller"> <grammar type= text/gsl mode="dtmf"> [dtmf-1 dtmf-2] </grammar> <prompt> if you are a new user press 1 else if u hav already an appointment press 2 </prompt> <filled> <block> <If cond="caller=='dtmf-1'"> <goto next="F1"> <else/ > <goto next ="welcome"> </filled> <form id="welcome"> <field name="cancelres"> <grammar type="text/gsl"> [cancel reschedule]</grammar> <prompt > wat do u want to cancel or reschedule the appointment </prompt> <filled> <block> <subdialog name="getdetails" src="mydoc.jsp"/> //WHERE TO STORE THE VALUES COMING FROM JSP AND HOW TO PLAY THE CORRESPONDING DATE AND TIME.. </block> </field> </form> <form id ="newapp"> <field name="consult"> <prompt bargein="false"> welcome to abc phone appointmentscheduling.please request the date for your appointment. To request an appointment this week you can say today,tomorrow ,day after tomorrow or a specific day such as this Friday.you can also request the day next week such as next Friday.plz make ur request now Such as today,tomorrow,day after tomorrow,this Friday or next Friday. </prompt> <grammar type="text.gsl"> [today tomorrow dayaftertommorrow Sunday Monday Tuesday Wednesday Thursday Friday Saturday (next Sunday) (next Monday) (next Tuesday) (next Wednesday) (next Thursday) (next Friday) (next Saturday) morning afternoon evening] </grammar> //IS THERE ANY EASY WAY WITHOUT WRITING ALL THESE DAYS... //IF THE USER SAYS A SPECIFIC DATE SUCH AS MARCH 2ND HOW TO INCLUDE GRAMMAR FOR THAT <filled> <block> <goto nextitem="day"> </block> <filled> <field name="day"> <grammar type="text.gsl"> [morning evening] </grammar> <prompt>please indicate your time facult by saying morning or afternoon</prompt> <filled> <subdialog name="availabletimes" src="mypage.jsp">//HOW TO play all available timings on that date.. </subdialog> <field name="confirm" type="boolean"> </filled> <block> <if cond="confirm=='yes'"> Then play the exact appointment day,date and time.. <elseif cond="confirm='no'"> <goto nextitem="day"> </block> </field> </form> </vxml> ABOVE IS THE CODE FOR APPOINTMENT SCHEDULING PLZ VERIFY WHETHER IT IS VALID OR NOT ..IF NOT GIV ME THE EFFICIENT VXMLCODE. |
|
VoxeoDustin
|
|
| Hey Jefo,
Attached is grammar that supports date entry, including day of the week, day, month and year. Give this a try and let us know if it's what you're looking for. Cheers, Dustin |
|
mtatum111
|
|
| I am trying to do a comparison with greater than sign.
I understand that for greater than, I am to use > However, when I put this into voxeo it converts it to > and gives an error. For example <filled> <if cond="parent_age≤15> <clear namelist="parent_age" /> </if> </filled> when I type this into my script under Files,Logs and save it, it converts it to <filled> <if cond="parent_age<=15> <clear namelist="parent_age" /> </if> </filled> and I get an error when calling the app. Is this the correct way? |
|
jdyer
|
|
| Hi,
If you are having issues with which operators to use in your application take a look at this [url=http://www.w3schools.com/js/js_comparisons.asp]link.[/url] It may help you out a bit, but in this case you can see that it looks like you are using [b]≤[/b] or [b]& l e ;[/b], this is not going to be parsed out as valid XML, can you please try [b]>=[/b] or [b] & g t ; =[/b] Please let us know if you need any additional assistance on this , we are certainly always more then happy to help our developers! Regards, John Customer Engineer |
|
mtatum111
|
|
| I found the following while reviewing the 2.0 spec
I am thinking the first if is incorrect. Shouldn't it be <if cond="total > 1000"> instead of what it has for the first line below? Thanks for any clarification. <if cond="total > 1000"> <prompt>This is way too much to spend.</prompt> <throw event="com.xyzcorp.acct.toomuchspent"/> </if> <if cond="amount < 29.95"> <assign name="x" expr="amount"/> <else/> <assign name="x" expr="29.95"/> </if> <if cond="flavor == 'vanilla'"> <assign name="flavor_code" expr="'v'"/> <elseif cond="flavor == 'chocolate'"/> <assign name="flavor_code" expr="'h'"/> <elseif cond="flavor == 'strawberry'"/> <assign name="flavor_code" expr="'b'"/> <else/> <assign name="flavor_code" expr="'?'"/> </if> |
|
jdyer
|
|
| Hi Mellisa,
I am sorry but I am not seeing what you are asking here. I looked the the w3c spec and I see the second <if> statement as the > as the escaped value ( & l t ; ), is this what is confusing you? Our forum system will parse this so I had to space it out, but that's the only difference I noticed. Please let us know, we are certainly more then happy to offer any assistance you may require! Regards, John D. Customer Engineer Voxeo Support |
|
mtatum111
|
|
| John, my question was simply this.
In the spec, there is the statement <if cond="total > 1000"> I thought though that this should be <if cond="total > 1000"> Am I mistaken here? Thanks |
|
jdyer
|
|
| Hi,
It looks like our forum system parsed out both of your examples. However I see what you are asking about now. You will want to use the ASCII equivalent for all operators here. I have typed them out here but put a space in them to ensure that they are not rendered by your browser. & l e ; = < & g t ; = > Hope that helps! Regards, John D. Customer Engineer Voxeo Support |
|
mtatum111
|
|
| John, that does answer my question. As always, thanks for your help. | |
shawnaslam1
|
|
| Hello,
What i need to use for "not equal".Is that != operator is correct for this. <if cond="AgentFirstDigit != '1' || AgentFirstDigit != '2' || AgentFirstDigit != '3' "> Am I using this operator correctly above. Pelase advice. Shawn |
|
VoxeoDustin
|
|
| Hey Shawn,
Correct. The != is the operator to use for 'does not equal.' Cheers, Dustin |
|
chakri.950
|
|
| <var name="temp1" expr="catOptions1" />
<var name="temp2" expr="catOptions2" /> <value expr="temp1" /> <value expr="temp2" /> <if cond=" temp1 == temp2 "> Entered into IF loop Kalyan Chakravarthy <else/> Entered into ELSE loop KALYAN CHAKRAVARTHy </if> I am having 2 variables temp1 and temp2 which were assigned with 2 field values catOptions1 and catOptions2. I want to check whether value in both the temp variables are same or not. I am getting error when i am inserting the above statements. I want to confirm whehter the implementation of if condition is right or wrong. If it is wrong could you please suggest the right way to compare two variables. Thanks in advnce. Kalyan M |
|
VoxeoDustin
|
|
| Hey Kalyan,
In order to get a better idea of what's happening, would you mind opening the Application Debugger and placing a call into your application? If you could submit these logs along with your full application, we'd be happy to assist you. http://www.vxml.org/loggerfeatures.htm Cheers, Dustin Hayre Customer Support Engineer 2 Voxeo Support |
|
chakri.950
|
|
| Hi Dustin,
I am using this code in my application, I cant deploy my application and I cant place the debugger. Without the if statement and assign statement the code is getting executed sucessfully. But I require the if condition to be placed there. So could you please assist me from the above code. THanks in advance Kalyan M |
|
voxeojeremyr
|
|
| Hello Kalyan,
There could be several different reasons why the <if...> is not behaving as you expect. Normally this is because of where the <if> tag is placed. You can view the Parent-Child relationships of the <if> element here: http://www.vxml.org/if.htm Your code snippet looks correct, however without a context into where this is placed in the code I cannot give you a definitive answer. You mentioned that you cannot deploy the application, can you give more details as to what you mean by this? Is your application a plain text file or is this code being generated by a 3rd party IDE of some sort? Also, you mention that you are getting an error when you try to insert the <if>, can you tell us the error code and where it is coming from? If you are more comfortable moving this information to a private account ticket, we could certainly do that. Standing by, Jeremy Richmond Voxeo Support |
|
kunalp25
|
|
| Is there a way to use the if condition to test to see if a var is set as undefined or not? | |
voxeo_chris
|
|
| Hello,
This would be very simple operation by setting the condition to undefined. As shown in the example listed below, when the variable does not have its expression set, the variable is undefined and we catch this in the if statement. [code] <?xml version="1.0" encoding="UTF-8"?> <vxml version = "2.1"> <var name="myVar"/> <form> <block> <prompt> we will now begin the test </prompt> <if cond="myVar==undefined"> <prompt> the variable is undefined </prompt> <else/> <prompt> This is the else statement </prompt> </if> </block> </form> </vxml> [/code] Let me know if this makes sense and if you have any questions as we would be happy to help. Regards, Chris Bruckart Customer Engineer Voxeo Support |
|
tleezer
|
|
| How can you use >= (greater than or equal to) and <= (less than or equal to) in the condition?
An earlier post suggested using: & l e ; If you use & l e ; the vxml document fails to load... invalid content message. If you use &le; the vxml document loads but produces a runtime error. I've tried various other methods resulting in everything from a failed document, to a runtime error, and even a hangup (the call just disconnects without notice or reason). |
|
jdyer
|
|
| Hello,
With out log's of the issue, or sample code, this is only an educated guess; Are you putting the characters in with the spaces in your code? If so this is the issue, we only put the spaces in our examples because with out then the forum system will in fact parse it out, resulting in > and not & lt; So in short these are the characters with only one space: > = & lt; < = & gt; & = & amp; You only need to remove the space between the & and the 2nd character to make it parse correctly in your document. I do hope that helps, and please let us know if are any other questions, as our team is always standing by to offer any help our developers may require! Regards, John Dyer Customer Engineer Voxeo Support |
|
aditya175
|
|
| I was trying to add a default goto statement i.e. a form to go to if the input from the user doesn't match any of the words indicated in the grammar. Should I add that goto statement in the <catch> block or should I add it at the end of the <if> statements under <else/> or is there some other way. | |
VoxeoDustin
|
|
| Hello,
If you wish to perform an action when a users utterance does not match the given grammar, you will want to do so in the <nomatch> handler itself, as this is where execution will transition to in this particular scenario. Let me know if we can be of further assistance. Regards, Dustin Hayre Customer Support Engineer II Voxeo Support |
|
jeremykentc
|
|
| Are nested 'if' statements permitted?
ex: <if cond="1 == 1"> <if cond="2 == 2"> One is in fact equal to one and Two is in fact equal to two <else/> One is in fact equal to one but Two is never not equal to two </if> <else/> One is never not equal to one </if> I realize I could rewrite this condition with an '&&' statement but the logic that I am trying to do would be messy to keep repeating in the chain of if elseifs that it would have to be. Thanks-jc |
|
jeremykentc
|
|
| Found the answer to my question at the top of the page - children ... <if>.
|
|
VoxeoBrian
|
|
| Hello,
This is certainly valid, I wrote a simple example to illustrate this for all to see. [code]<?xml version="1.0" encoding="UTF-8"?> <vxml version="2.1" xmlns="http://www.w3.org/2001/vxml"> <var name="myVar" expr="'foo'"/> <var name="myVar1" expr="'bar'"/> <form id="test"> <block> <if cond="myVar == 'foo1'"> <if cond="myVar1 == 'bar'"> <log expr="'myVar is equal to foo, and myVar1 is equal to bar'"/> <else/> <log expr="'myVar is equal to foo, and myVar1 is not equal to bar'"/> </if> <else/> <log expr="'myVar is does not equal foo'"/> </if> </block> </form> </vxml>[/code] Regards, Brian F. |
|
patatas
|
|
| Hi!
Can i use <audio> instead of <prompt> inside forms? Here's my xml <?xml version="1.0" encoding="UTF-8"?> <vxml version = "2.1"> <form id="pressForm"> <field name="pressed"> <grammar type="text/gsl" mode="dtmf"> [dtmf-1 dtmf-2 dtmf-3 dtmf-4 dtmf-5 dtmf-6 dtmf-6 dtmf-7 dtmf-8 dtmf-9] </grammar> <audio src="1.gsm" /> </field> <filled namelist="pressed" mode="dtmf"> <if cond="pressed == 'dtmf-1'" > <audio src="2.gsm" /> <elseif cond="pressed == 'dtmf-2'" /> <audio src="3.gsm" /> <else /> <audio src="4.gsm" /> </if> </filled> </form> </vxml> but what's happening is..yes it waits for me to input a digit after playing, it also recognizes the digit that i pressed (debug in asterisk CLI), but after i press a digit, it plays recordings 2,3 and 4, what am i doing wrong? |
|
VoxeoTony
|
|
| Hello,
Yes, you can use audio inside a form as field is a parent. In your case, I think the issue is the logic being processed in your IF statement. In your statement you are looking for the match of DTMF-1, but since the result of pressing 1 is not returning DTMF-1 your result is not matching. I added the following to your sample to illustrate what is being returned to filled when you press 1 on your phone. [code] <filled namelist="pressed" mode="any"> <log expr="'**********************************************'"/> <log expr="'CONFIDENCE = ' +lastresult$.confidence"/> <log expr="'UTTERANCE = ' + lastresult$.utterance"/> <log expr="'INPUTMODE = ' + lastresult$.inputmode"/> <log expr="'INTERPRETATION = ' + lastresult$.interpretation.pressed"/> <log expr="'**********************************************'"/> [/code] With the debugger log open you will find that the result is not DTMF-1, but 1 alone. So, changing the IF to [code]<if cond="pressed == '1'" >[/code] Enabled the IF to catch on the correct audio file. I hope this information is helpful to your testing. Regards, Anthony James Customer Engineer Voxeo Ready to go Pro? sales@voxeo.com |
|
patatas
|
|
| Just what i needed! Thanks Anthony for the big help, Merry Christmas! | |
bobby.christensen
|
|
| Is there a way to implement a conditional statement, similar to that in java, that allows the use of a statement as such:
if ( condition1 && ( condition2 || condition3 )) I am assuming the following will not work: <if cond="condition1 && ( condition2 || condition3 )"> Thanks in advance, Bobby |
|
jdyer
|
|
| Hello Bobbi,
Yes, you can most certainly use this type of boolean logic in your conditionals, however you must make sure to encode the ampersands in your application. I have attached an example below, but please be aware that our forum system will render the encoded ampersands, as will our VoiceXML browser: [code] <?xml version="1.0" encoding="UTF-8"?> <vxml version="2.1"> <form id="Form1"> <var name="condition1" expr="true"/> <var name="condition2" expr="false"/> <var name="condition3" expr="true"/> <block> <if cond="condition1&&(condition2||condition3)"> <log expr="'@@@@ EVALUATED TO TRUE'"/> <else/> <log expr="'@@@@ EVALUATED TO FALSE'"/> </if> </block> </form> </vxml>[code] I do hope this helps, and if there are any other questions please let us know, as our team is most certainly always standing by to be of service! Regards, John Dyer Customer Engineer Voxeo Support |
|
samipry
|
|
| Hi,
I am priya. After I am pressing 1 ,it is not go to filled tag. It is shows error in call what is problem of my code? Thanks , Priya <?xml version="1.0" encoding="UTF-8"?> <vxml version="2.1"> <form id="frm_Greeting"> <field name="fld_Greeting"> <grammar>[dtmf-1] [dtmf-2] </grammar> <prompt bargein="false" timeout="5s"> Barclays Language Selection. Press 1 for Arabic Press 2 for English </prompt> <filled> <if cond="fld_Greeting=='1'"> <prompt> It is filled if </prompt> <goto next="#frm_Arabic" /> </if> </filled> </field> </form> </vxml> |
|
VoxeoDante
|
|
| Hello Priya,
Can you tell us what the error is that you are getting in this application, or send over a set of logs from a failed call? With that, we should be able to help out much more quickly. Regards, Dante Vitulano Hosted Solutions Engineer |
| login |