Sample Chapter: Early Adopter VoiceXML - VoiceXML With XSLT (HTML and WML) (Page 2 of 9 )
This chapter examines the use of the Extensible Stylesheet Language for Transformations (XSLT) as a tool for the generation of VoiceXML. I intend to illustrate a complete, end-to-end example of implementing a voice interface for a client-server database via XML and XSL. The case study will demonstrate the power of XSL for simultaneously delivering multiple interfaces to the same data by developing HTML and WML front-ends also.
Our case study takes us inside the rarified atmosphere of a fictional cash-strapped dot-com called MyRubberBands.com, purporting to be the "premier rubber bands site on the Internet". In the aftermath of the stock market meltdown, where our heroes saw their market valuation drop by over 95%, senior management, led by CEO Dr. Todd, has decreed that adding WML and voice functionality to the existing order status web site is do-or-die. MyRubberband's competitors have just rolled out their own WAP/voice access solution, and an all-out effort is necessary to catch up. Follow the programmers as they embark on their project to quickly roll out an equivalent capability.
Our development team have decided to implement an XSLT-based solution to the problem. XSLT is an XML-based language for transforming input structured according to one XML vocabulary to structured output in another XML vocabulary, or some general text form.
XSLT treats the document to be transformed as a set of nodes. An XSLT stylesheet defines a set of rules, or templates. When a template matches one of the nodes in the source document, the output structure given in the template is created in the transformed document. XSLT uses the W3C XPath specification language to query XML data. XPath is strongly analogous to SQL, and lets us specify complex rules to match nodes in a document.
For a lot of applications, and for getting off to a quick start when processing XML, it is just the ticket – especially when you consider that XSLT is a relatively new technology so that processors should still have plenty of performance improvements possible. Use of an XSLT processor avoids the startup overhead of using a full parser API from a compiled language, making it more suited to dynamic web applications.
MyRubberBands.com – A Case Study Our legacy database is implemented with MySQL, an open source client-server relational database management system. SQL code for the schema and a set of sample data is included in the code download for this book.
An XML schema is used to represent an export of the legacy database instead of a Document Type Definition (DTD) because the schema standard is now complete, and increasing numbers of developers will be looking for the extra power schemas offer, especially as new development tools become available. An excellent primer on schemas is available from the W3C at http://www.w3.org/TR/xmlschema-0/.
Scripts to export the database to XML format have been written using the Perl language, and the Data Base Interface (DBI) library. The Perl script shown was developed on Windows using Active State Perl, but should run on any platform, be it Windows or Unix. Many commercial databases, such as SQLServer 2000, are capable of exporting directly to XML, and so this step could be avoided entirely.
Business Requirements With their competitors rolling out both voice and WAP access to services, MyRubberBands.com has no choice but to follow suit or lose market share in the cutthroat world of elastic band marketing. Due to market pressures, the new system must be up and running as soon as possible, and given this short development cycle, the requirements have been scaled back to providing simply voice and WAP access to a customer's order status data.
However, some thought can still be given to the future. Rather than develop a quick and dirty "throwaway" voice interface, by putting in a little extra work now, the engineers can build a reusable infrastructure. By exporting their database to an XML format, they access the power of XSL to create VoiceXML and WML interfaces, and are able to transparently replace parts of the existing HTML site with dynamically created pages.