Partilhar via


bind Element

  Microsoft Speech Technologies Homepage

Assigns a value from recognition results to an HTML page control or to call a method of an element on the page.

<bind targetelement="element" targetmethod="method" targetattribute="attribute" test="pattern" value="recoResult">

The bind element has the following attributes:

Attributes Description
targetelement Specifies the element of an HTML page where the value attribute of the bind element is assigned.
targetattribute Specifies the attribute or property of the target element to which the value attribute of the bind element is assigned. Optional. If omitted, assignment is made to the value property of the page control.
test Specifies an Extensible Markup Language (XML) pattern that indicates the condition under which the bind element is executed. Optional.
targetmethod Specifies the method of the target element that is called when the bind element is executed. Optional.
value Specifies all or part of a recognition result to be assigned to the targetelement. Optional.

Remarks

The bind element is a child of the dtmf, listen and smex elements.

The result of a successful recognition is an XML document defined using Semantic Markup Language (SML). The SML output labels specific words or phrases within the recognition result.

Using the bind element, a speech application can easily and automatically retrieve the needed text from a recognition result. The retrieved text is then assigned to a page element, such as a text box or label field or to a property or attribute of a page element. This binding is convenient because an application would otherwise need to supply the logic and code to parse the recognition result.

For example, the bind element assigns the value designated as the arrival city in a recognition result to a text box on a Web page. The assignment is automatic after a successful recognition with no additional code needed. For more complex processing, the listen element implements script code in the onreco handler. Allowing event handlers permits programmatic script analysis and post-processing of the recognition return.

The binding operation occurs whenever a recognition result is returned but before an onreco (dtmf or listen) or onreceive (smex) event is raised. When bind is used for assignment, the result of the XML Path Language (XPath) query is copied from the result Document Object Model (DOM) into the page DOM. If the target of assignment targetattribute is a string, the result is converted into a well-formed XML string without loss of information. This feature can be used with a complete recognition result, for instance, to submit the entire result to a Web server. If the targetattribute is an XML DOM Node, assignment follows the copy-of semantics of the XSL Transformations 1.0 specification (XSLT), namely, the DOM node tree returned by the XPath is copied to the targetattribute as a DOM node tree. No events are raised and the binding fails to execute or contains errors in content, no operation is performed.

Each bind element can have, at most, one targetmethod or one targetattribute. Specification of more than one, or both targetmethod and targetattribute is not allowed.

When multiple bind elements return a Boolean true on their respective test conditions, each is executed in document order, that is, the order in which each appears in the HTML document.

If a binding operation fails, no error is raised and the application developer has no easy way to determine how or why an error occurred. An example of this type of failure is an invalid targetelement or targetmethod.

Example

The following code demonstrates the use of the bind element.

<salt:listen id="listen1" mode="automatic" onreco="Handleonreco()" onnoreco="Handleonnoreco()"  onsilence="Handleonsilence()" onerror="Handleonerror()">
  <salt:grammar id="gram1" src="cities.grxml"/> 
  <salt:bind targetelement="boxFromCity" value="//origin_city"/>
  <salt:bind targetelement="boxToCity" value="//destination_city"/>
</salt:listen>

See Also

grammar Element | listen Element | smex Element | bind Element Example