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

    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>
    Alan Searle, Nov 19, 2005
    #1
    1. Advertising

  2. Re: Clientside filtering and sorting xml with javascript: Work inIE but not Firefox

    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>
    <http://snapshot.opera.com/unix/u90p1.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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Nov 19, 2005
    #2
    1. Advertising

  3. Alan Searle

    Alan Searle Guest

    Re: Clientside filtering and sorting xml with javascript: Work inIE but not Firefox

    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.
    Alan Searle, Nov 20, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sjaakie
    Replies:
    10
    Views:
    749
    Nick Gilbert
    Sep 21, 2006
  2. snafu7x7

    sorting and filtering oh my!

    snafu7x7, Oct 2, 2007, in forum: XML
    Replies:
    5
    Views:
    539
    Pavel Lepin
    Oct 3, 2007
  3. akineko
    Replies:
    2
    Views:
    786
    akineko
    Jul 5, 2008
  4. Michelle
    Replies:
    1
    Views:
    240
    Elton Wang
    Apr 8, 2005
  5. akineko
    Replies:
    0
    Views:
    119
    akineko
    Jul 5, 2008
Loading...

Share This Page