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

Discussion in 'XML' started by Alan Searle, Nov 19, 2005.

  1. Alan Searle

    Alan Searle Guest

    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 ...

    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.

    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){
    var s = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
    var x = document.XMLDocument;
    if (x == null){
    x = navigator.XMLDocument;
    var tem = new ActiveXObject("MSXML2.XSLTemplate");
    tem.stylesheet = s;
    var proc = tem.createProcessor();
    proc.addParameter("column", column);
    proc.input = x;
    var str = proc.output;

    var newDoc ="text/html");
    navigator.XMLDocument = x;
    navigator.XSLDocument = s;
    Alan Searle, Nov 19, 2005
    1. Advertisements

  2. Alan Searle wrote:

    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:
    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:
    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.
    Martin Honnen, Nov 19, 2005
    1. Advertisements

  3. Alan Searle

    Alan Searle Guest

    Hi Martin,

    Thanks for your tips and clarification.
    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.

    Alan Searle.
    Alan Searle, Nov 20, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.