Thursday, April 12, 2007

Circumventing the standards


Recently I encountered an annoyance with the VXML standard. I was unable to use <if> within a <prompt>. The reason why I wanted to do this was to adjust the prompt based on a variable. The prompt was fairly long with just some variance based on the value of this variable. It was possible to do <if><prompt>...</prompt><else if/><prompt>...</prompt><else if/> etc etc. But this just made the document bigger and bigger and it just seemed to me that this abitrary limitation was ridiculous.
So imagine my surprise when I was able to circumvent this limitation while remaining within the standard. How was this possible? Simple, I used the <foreach> tag which is allowed to be a child of <prompt>. I created a dummy array of one element enabling me to do the following:

<prompt>
   this is the start of this prompt
   <foreach array="dummyArrayOfOneElement" item="foo">
      <if cond="cond1">
         middle prompt 1
      <elseif cond="cond2"/>
         middle prompt 2
      <else/>
         middle prompt default
      </if>
   </foreach>
   this is the end of this prompt
</prompt>

Can someone tell me why the limitation exists on <if> and why the limitation is pointless if it can be circumvented and still remain within the standard?

2 Comments:

Anonymous Anonymous said...

You can only have Executable Content (if, ...) within execusion elements (block, filled, event handlers).

However, to get condition over a prompt, you may use the cond attribute such as follow:

[prompt cond="cond1"][/prompt]
[prompt cond="cond2"][/prompt]
[prompt cond="cond3"][/prompt]

(replace [] with <>)

Could that be easier? Hope this help.

7:26 PM  
Blogger Brian OConnor said...

Thanks for your comment Pascal. Your solution really doesn't provide much benefit over doing <if><prompt>. What I was really trying to point out though was the ridiculousness of the standard. As you say you can only have Executable Content (if, ...) within execusion elements (block, filled, event handlers), yet as I have shown you can with a workaround circumvent this. Thus making your statement moot since in practice you really can use <if> within an element that the standard is suppose to prevent.

1:46 AM  

Post a Comment

<< Home