?readviewentries and xsl and Mozilla

I am playing around with using xml generated by ?readviewentries and xsl to display view data. What I have works well with IE. But, the xsl is not applied to the xml in Mozilla and what is returned is a long text string with the view data. I am just getting started with xml/xsl and I have just pieced some things together. Can anyone help me get this to work in non IE browsers? Below is my xsl. Thanks, David.

<?xml version="1.0"?>

<xsl:stylesheet version=“1” xmlns:xsl=“XSLT Namespace”>

<xsl:template match=“/” >

<xsl:for-each select=“/viewentries/viewentry”>

</xsl:for-each>

Title

Published

</xsl:template>

</xsl:stylesheet>

Subject: RE: ?readviewentries and xsl and Mozilla

Can’t be sure that your XSL file is the problem. You may want to post the javascript used to do the transformation. The two browsers use different methods with XSLT.

Subject: RE: ?readviewentries and xsl and Mozilla

I have a select field with this in the onchange event:var xmlurl=‘VBalDept?readviewentries&RestrictToCategory=’+this[this.selectedIndex].text+ ‘&count=-1’;

xmlGet(xmlurl, tableResponseHandler)

Here is javascript that is used. I got it from this article:http://devzone.skillfusion.com/ajaxArticle1.php. I get no errors.

var xslurl=‘xsltest2.xsl’;

// Immediately try to load the xsl file asynchronously

var xsldocloaded = false;

var xsldoc;

if (window.XSLTProcessor)

{

 // support Mozilla/Gecko based browsers

 xsldoc = document.implementation.createDocument("", "", null);

 xsldoc.addEventListener("load", onXslLoad, false);

 xsldoc.load(xslurl);

}

else if(window.ActiveXObject)

{

 // support Windows / ActiveX

 xsldoc = new ActiveXObject("Microsoft.XMLDOM");

 xsldoc.ondataavailable = onXslLoad;

 xsldoc.load(xslurl);

}

function onXslLoad()

{

 // flag that the xsl is loaded

 xsldocloaded = true;

}

/**

  • Open a connection to the specified URL, which is

  • intended to provide an XML message. No other data is

  • sent to the server. This is the same as calling

  • xmlOpen(“GET”, url, null, responseHandler).

  • @param string url The URL to connect to.

  • @param function responseHandler The Javascript function handling server response.

*/

function xmlGet(url, responseHandler)

{

xmlOpen("GET", url, null, responseHandler);

}

/**

  • Open a connection to the specified URL, which is

  • intended to respond with an XML message.

  • @param string method The connection method; either “GET” or “POST”.

  • @param string url The URL to connect to.

  • @param string toSend The data to send to the server; must be URL encoded.

  • @param function responseHandler The Javascript function handling server response.

*/

function xmlOpen(method, url, toSend, responseHandler)

{

if (window.XMLHttpRequest)

{

    // browser has native support for XMLHttpRequest object

    req = new XMLHttpRequest();

}

else if (window.ActiveXObject)

{

    // try XMLHTTP ActiveX (Internet Explorer) version

    req = new ActiveXObject("Microsoft.XMLHTTP");

}



if(req)

{

    req.onreadystatechange = responseHandler;

    req.open(method, url, true);

    req.setRequestHeader("content-type","application/x-www-form-urlencoded");

    req.send(toSend);

}

else

{

    alert('Your browser does not seem to support XMLHttpRequest.');

}

}

function tableResponseHandler()

{

 // Make sure the request is loaded (readyState = 4)

 if (req.readyState == 4)

 {

     // Make sure the status is "OK"

     if (req.status == 200)

     {

         // Make sure the XSL document is loaded

         if (!xsldocloaded)

         {

             alert("Unable to transform data.  XSL is not yet loaded.");

             // break out of the function

             return;

         }

         

         var swappableSection = document.getElementById("TheList");

         

         if (window.XSLTProcessor)

         {

             // support Mozilla/Gecko based browsers

             var xsltProcessor = new XSLTProcessor();

             xsltProcessor.importStylesheet(xsldoc);

             var outputXHTML = xsltProcessor.transformToFragment(req.responseXML, document);

             swappableSection.innerHTML = "";

             swappableSection.appendChild(outputXHTML);

         }

         else if(window.ActiveXObject)

         {

             // support Windows/ActiveX enabled browsers

             var outputXHTML = req.responseXML.transformNode(xsldoc);

             swappableSection.innerHTML = outputXHTML;

         }

     }

     else

     {

         alert("There was a problem retrieving the XML data:\n" +

             req.statusText);

     }

 }

}

Subject: RE: ?readviewentries and xsl and Mozilla

Jeff’s code should work. The problem, as near as I can tell, is the appendChild() being used to fill the swappable section in the Moz version you have. appendChild() takes a DOM node as an argument, and the output of the transform is not a DOM node. That sets the “implicit conversion” trigger to the default node type: a data node (text or CDATA, depending on the content). You would need to get the output of the tranform (which is default DOM parsed) and find the root node in order to use appendChild(). However, since innerHTML has almost-universal support (even if it is proprietary juju), it’s much simpler to simply use that than to fumble around with the DOM.

Subject: RE: ?readviewentries and xsl and Mozilla

BTW, this is the function I use to do multi-browser transforms.

function xslt(xmlDoc,xslDoc) {

	var transform;

	

	if (typeof ActiveXObject != 'undefined') {

		transform = xmlDoc.transformNode(xslDoc);

	}

	else {

		var xsl = new XSLTProcessor();

		

		xsl.importStylesheet(xslDoc);

		var fragment=xsl.transformToFragment(xmlDoc, document);

		if( fragment.childNodes.length>0 ){

			transform = fragment.childNodes[0].innerHTML;

		}else{

			alert("error");

		}

	}

	return transform;

}