Clientside filtering and sorting xml with javascript: Work in IEbut not Firefox

A

Alan Searle

I would like to use an XSL/HTML template to sort XML data dynamically on
the client side.

As it is, I found a tutorial showing how to do this on the following
site ...

http://www.bayes.co.uk/xml/portal.a...ml&subpage=/xml/tutorial/filtering/filter.xml

I experimented with the examples and found that they would run fine on a
local PC (without installing a web-server). That is just what I need!

However, when I tried to run the same thing with FireFox (under Linux),
I got the following message ...

You will need to have the latest version of MSXML installed in "replace"
*NOT* "side-by-side" mode to view the tutorial. Or IE6+.

This message (and references to 'ActiveX' and 'MSXML' in the javascript
below) shows me that the code I had found is very MicroSoft specific.
Arrgghh!

This combination of JavaScript and XML/XSL/HTML (with client-side
processing) would be perfect for my needs so what I really like to know
is whether there are ways of handling the XML/XSL without dependence on
a Microsoft platform?

I have enclosed an excerpt of the script (below) and hope that someone
out there can help me get this working without needing Bill Gates help.

Regards and thanks,
Alan Searle

Script excerpt:

<script language="javascript" type="text/javascript">

function sort(column){
try{
var s = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
var x = document.XMLDocument;
if (x == null){
x = navigator.XMLDocument;
s.loadXML(navigator.XSLDocument.xml);
}else{
s.loadXML(document.XSLDocument.xml);
}
var tem = new ActiveXObject("MSXML2.XSLTemplate");
tem.stylesheet = s;
var proc = tem.createProcessor();
proc.addParameter("column", column);
proc.input = x;
proc.transform();
var str = proc.output;

var newDoc = document.open("text/html");
newDoc.write(str);
navigator.XMLDocument = x;
navigator.XSLDocument = s;
newDoc.close();
}catch(exception){
}
}
</script>
 
M

Martin Honnen

Alan Searle wrote:

This combination of JavaScript and XML/XSL/HTML (with client-side
processing) would be perfect for my needs so what I really like to know
is whether there are ways of handling the XML/XSL without dependence on
a Microsoft platform?

Mozilla has client-side XSLT support since 1.0 and a frozen API to
script XSLT since 1.2 I think, see here for details:
<http://www.mozilla.org/projects/xslt/>
<http://www.mozilla.org/projects/xslt/js-interface.html>
Safari has client-side XSLT support by now I think based on libxml but I
am not aware on any API exposed to script.
The Opera 9 preview released some weeks ago has client-side XSLT support
based on Opera's own implementation of XSLT but tries to expose the same
API Mozilla exposes:
<http://snapshot.opera.com/windows/w90p1.html>
s.loadXML(document.XSLDocument.xml);

Mozilla does not expose XSLDocument if you let the browser do a
transformation thus if you want to use XSLT and script in Mozilla it is
usually better and easier to start with a HTML document with script that
loads XML and stylesheet as needed and performs the transformation.

The whole IE approach with transforming to a string and inserting that
into an HTML document (or even replacing the complete HTML document) is
caused by the separate DOM implementations of HTML DOM by MSHTML and XML
DOM by MSXML. In Mozilla you can easily transform to a result fragment
with DOM nodes which can directly by inserted into the existing document.

However if you want to use client-side XSLT and script then in both IE
and Mozilla you face the issue to decide how to combine the rather
different APIs and their preferred (DOM result in Mozilla, string result
in IE) but incompatible use.

Currently if the aim is client-side sorting and filtering for a web
application then XSLT might not be the best option to reach a cross
browser compatible solution, you could rather set up appropriate
JavaScript data structures/objects and manipulate the HTML DOM only.
 
A

Alan Searle

Hi Martin,

Thanks for your tips and clarification.
Currently if the aim is client-side sorting and filtering for a web
application then XSLT might not be the best option to reach a cross
browser compatible solution, you could rather set up appropriate
JavaScript data structures/objects and manipulate the HTML DOM only.

This sounds interesting and I will be googling on these keywords.

Indeed, if you know of any tutorials or good sources of information (on
client side processing of structured data) then I'd be interested to hear.

Regards,
Alan Searle.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top