Chapter 12. Live search using XSLT

 

This chapter covers

  • Dynamic search techniques
  • Using XSLT to translate XML to HTML
  • Bookmarking dynamic information
  • Building a live search component

With Ajax, it’s easy to perform server-side actions while controlling what is happening on the client. If a process takes an extended period of time, we can show animated GIFs that display messages that let the user know what’s happening. The user can perform other actions while the server-side process is taking place and will be less likely to think that the browser has frozen.

In this chapter, we use this Ajax technique to create a live search. It utilizes Extensible Stylesheet Language Transformations (XSLT) to transform an XML document into an HTML layout. The XSLT translation is easier to maintain than the code to manually parse the XML and produce HTML using JavaScript statements. It uses a tree-oriented transformation on a dynamically generated XML document, which replaces the server-side code and the JavaScript on which the previous projects relied. We are eliminating the hassles of manually making sure that all the HTML elements are formed properly.

As with previous examples, we first develop the code in a straightforward way and then refactor it into a reusable component. By the end of this chapter, you should understand the principles of using XSLT with Ajax and have a ready-rolled search component that you can drop into your own projects.

12.1. Understanding the search techniques

12.2. The client-side code

12.3. The server-side code: PHP

12.4. Combining the XSLT and XML documents

12.5. Completing the search

12.6. Refactoring

12.7. Summary