View Full Version : Updating a page using XML & XSLT

Roger Thompson
07-16-2008, 08:12 PM
I'm trying to do a simple task that is well discussed in the literature, but I cannot get it to work. I have a page that has a search box and I want to display the results on that same page. Page 482 in Ajax in Action has the requisite code which I am generally following. The following is the code:

var simple_search_transform;
var simple_record_transform;

function simpleSearchLoad ()
simple_search_transform = '';
simple_record_transform = '';

new Ajax.Request('/theme/simpleResultsList.marcxml.xsl', { method: 'get', onSuccess: get_simple_search_transform, onFailure: failure_fn} );
new Ajax.Request('/theme/simpleRecords.marcxml.xsl', { method: 'get', onSuccess: get_simple_record_transform, onFailure: failure_fn} );

var get_simple_search_transform = function (request)
simple_search_transform = request.responseXML;
//alert("simple_search_transform:+" + simple_search_transform);

var get_simple_record_transform = function (request)
simple_record_transform = request.responseXML;
//alert("simple_record_transform:+" + simple_record_transform);


var search_success_fn = function (request)
var the_xml = request.responseXML;
var the_text = request.responseText;
//alert ("search_success_fn:" + the_xml);
//alert ("search_success_fn:\n" + the_text);

format_search_list(the_xml, 'browsePanel');

function format_search_list (the_stuff, obj_id)
alert("enter format_search_list");
alert("obj id:" + obj_id);
alert("the_stuff:\n" + the_stuff);
alert("simple_search_transform:" + simple_search_transform);

var object_to_be_filled = document.getElementById(obj_id);
alert("obj to be filled:" + object_to_be_filled);
alert("obj to be filled, innerHTML:" + object_to_be_filled.innerHTML);

var fragment;

if (window.ActiveXObject)
alert("We are IE");

fragment = the_stuff.transformNode(simple_search_transform);

alert("fragment (IE)\n" + fragment);
object_to_be_filled.innerHTML = fragment;
alert("We are not IE");
var xslt_processor = new XSLTProcessor ();
alert("format_search_list.xslt_processor:" + xslt_processor);


alert("stylesheet imported");

fragment = xslt_processor.transformToFragment(the_stuff, document);

alert("fragment (not IE)\n" + fragment);

object_to_be_filled.appendChild (fragment);

alert("leave format_search_list");

var failure_fn = function (request) { alert ("failure_fn:" + request.responseText); }

As can be seen this is the usual stuff. When I run the code in Firefox 2, it works up to the point where I try to load the stylesheet into the XSLTProcessor. The alert "stylesheet imported" never fires. I have the error console open and there is nothing reported. Note: I'm using the Prototype 1.6.0 framework for my Ajax calls. The IE part of the code does not work either. My thought is that there might be some sort of type mismatch.

I should add the search_success_fn is called via an Ajax call that does the actual search.

Roger Thompson
07-17-2008, 04:28 PM
duh, found my problem: importStyleSheet should be spelled importStylesheet.