// Place the resulting information in an XML document.
var ProcDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
XSLTData.async = false;
The next step is a little tricky and definitely Windows specific. The code creates an instance of the Microsoft XML component. The ActiveXObject() function performs this task. The Msxml2 .DOMDocument.4.0 string identifies the component. You might have to use Msxml2.DOMDocument.5.0 on newer machines with Microsoft Office 2003 or another new product loaded—the last part of the string identifies the component version number. Setting the async property to false is important because you don’t want the call to load the XML to return until the browser actually receives this file. Finally, the ProcDoc.loadXML() function loads the response from Google Web Services. Notice that the code uses the loadXML() function to load text formatted as XML, rather than XML from a file.
NOTE Most versions of MSXML work fine for this example. However, you’ll probably want to get MSXML Version 4.0 Service Pack 2 (SP2) from http://www.microsoft.com/downloads/ details.aspx?FamilyID=3144b72b-b4f2-46da-b4b6-c5d7485f2b42&DisplayLang=en.
|USING GOOGLE TO CREATE A SITE SEARCH||247|
The code now has a local copy of the data from Google. This local copy will disappear as soon as the function ends, so you don’t have to worry about update requirements, but it’s important to under-stand that the copy resides in memory on your machine somewhere.
At this point, the code has data to work with, but no XSLT file. The next step loads the XSLT file defined by the XslFile variable. Notice that the code uses the XSLTData.load() function because the XML appears in a file that the application must load into memory. The coupling between the XML response and the XSLT occurs in the XMLData.transformNode() function call. This call produces output that the document.write() function then sends to the current page. The result is that you see the transformed XML on screen, as shown in Figure 8.12. Notice that the URL doesn’t change, even though the content differs, because you’re still theoretically on the same Web page.