Links

A link specifies a grammar that is independent of any particular dialog, but that is active in the scope of the element that contains the <link> element.

A link can specify one of two possible actions to take if NVP detects a match:

  • The link can cause a transition to a different location, in much the same way as a menu <choice> or a <goto> element (see Transitions).

    When used this way, the link’s “next” attribute specifies the destination of the transition. Links can cause transitions to other dialogs or documents.

  • The link can throw an event. In this case, the link’s expr attribute specifies the event to throw. The event handler must be coded separately (see Events).

After the event is handled, execution resumes with the element that was being executed when the link grammar was matched.

As with other components of an application, this scope is based on the level where the link is declared—within an individual field (including an <initial> element), a form, or at the document level (within a <vxml> element).

For example, links can be used to implement universal commands that apply within the scope. The root document of the PizzaTalk application (pizza.vxml) defines four universal commands that can be used at any point in the dialog:

<link event="help">
  <grammar src="../grammars/universals.grxml#Help" weight="0.01"/>
</link>
<link event="repeat">
  <grammar src="../grammars/universals.grxml#Repeat" weight="0.01"/>
</link>
<link next="Goodbye.vxml">
  <grammar src="../grammars/universals.grxml#Goodbye" weight="0.01"/>
</link>
<link next="pizza.vxml">
  <grammar src="../grammars/universals.grxml#Cancel" weight="0.01"/>
</link>

Here, the link throws events for some commands (help, repeat), but transitions to other parts of the application for others (goodbye, cancel).

Note that a weight of 0.01 is assigned to each of these links. The low value is intended to keep the links from being triggered accidentally.