Step 2Parse user input: Client Normalization Function
After the grammar is matched and the SML document is returned, we'll next want to have our server-side code retrieve a list of companies from the database that matches these criteria. However, we'll need to run a different business logic function based on which type of information we have: company or ticker. We need a way to pass some information to our code telling it which SML element was matched.
When we set up the CompanyOrTickerQA, we specified that the value of the answer that was matched should be stored in the siTicker
semantic item (see Figure 6). It will recognize that as a match only if the SML element returned is satisfied by the expression in the XPath Trigger
column. So in our example, the XPath Trigger string "/SML/Ticker | /SML/Company"
signifies that a match has been satisfied if either the SML element "Ticker" has been returned, or the SML element "Company" has been returned.
|Figure 6: The CompanyOrTickerQA Property Pages|
In the Answers tab, we also have a field for "Client Normalization Function." This holds the name of a client-side script function that we want to run when the SML is recognized, before siTicker
is filled. This allows us to query the value returned by the grammar match and manipulate it, and fill in the semantic item with the updated value.
In our case, we use the JScript function "SetResponseType" as our Client Normalization Function for the CompanyOrTickerQA control.
function SetResponseType(smlNode, semanticItem)
Here we set an attribute of the semantic item siTicker
, called "ResponseType," to the node name of the SML returnedwhich will be either "Company" or "Ticker."