client side xslt transformation in Firefox

Discussion in 'XML' started by Zzzbla, Dec 26, 2006.

  1. Zzzbla

    Zzzbla Guest

    Hi all,

    anyone has a live example of loading an xml file from a server, an xslt
    file from the server, then transforming the xml using the xslt and
    outputing the results (preferably with appendChild)?

    I'm trying to write a function to do just that (given url to xml, url
    to xslt and elementid). Works a charm on IE. Can't get it to work with
    Firefox.

    Thanks in advance,
    R. Green
     
    Zzzbla, Dec 26, 2006
    #1
    1. Advertising

  2. Zzzbla wrote:

    > anyone has a live example of loading an xml file from a server, an xslt
    > file from the server, then transforming the xml using the xslt and
    > outputing the results (preferably with appendChild)?


    Here is an example
    <http://home.arcor.de/martin.honnen/javascript/2006/12/test2006122601.html>
    tested with Mozilla, Opera 9, IE 6.




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 26, 2006
    #2
    1. Advertising

  3. Zzzbla

    Zzzbla Guest

    Thank you Martin!!!


    Martin Honnen wrote:
    > Zzzbla wrote:
    >
    > > anyone has a live example of loading an xml file from a server, an xslt
    > > file from the server, then transforming the xml using the xslt and
    > > outputing the results (preferably with appendChild)?

    >
    > Here is an example
    > <http://home.arcor.de/martin.honnen/javascript/2006/12/test2006122601.html>
    > tested with Mozilla, Opera 9, IE 6.
    >
    >
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    Zzzbla, Dec 26, 2006
    #3
  4. Martin Honnen <> wrote:

    > Here is an example
    > <http://home.arcor.de/martin.honnen/javascript/2006/12/test2006122601.html>
    > tested with Mozilla, Opera 9, IE 6.


    Fine thanks !

    this example works also on Mac OS X 10.4.8 with :

    WebKit (latest nightly)
    Firefox 2.0.x
    Flock 0.7.8
    Opera 9.10
    Camino 1.1a1+

    don't work with :
    Safari 2.0.4
    Shiira 2.0b1
    SunRiseBrowser 0.895 (latest)
    TrailBlazer 0.5


    may be that's only a question of javascript core version ???

    how to get that version number ?
    --
    Père Noël
     
    =?ISO-8859-1?Q?P=E8re_No=EBl?=, Dec 26, 2006
    #4
  5. Zzzbla

    VK Guest

    Zzzbla wrote:
    > anyone has a live example of loading an xml file from a server, an xslt
    > file from the server, then transforming the xml using the xslt and
    > outputing the results (preferably with appendChild)?
    >
    > I'm trying to write a function to do just that (given url to xml, url
    > to xslt and elementid). Works a charm on IE. Can't get it to work with
    > Firefox.


    (One more sample besides the one by Martin Honnen)

    Full sample at <http://jsnet.sourceforge.net/tmp/xslt/dxslt.html>

    That may be confusing because MSXML and Gecko are using different
    patterns.

    In MSXML you
    1) obtaining XML data
    2) obtaining XSL template
    3) applying XSL template onto XML data; this automatically invokes
    XSLT processor

    // 1
    var xml = new ActiveXObject('Microsoft.XMLDOM');
    xml.async = false;
    xml.load('demo.xml');
    // 2
    var xsl = new ActiveXObject('Microsoft.XMLDOM');
    xsl.async = false;
    xsl.load('demo.xsl');
    // 3
    document.body.
    insertAdjacentHTML('beforeEnd',
    xml.transformNode(xsl));

    In Gecko you
    1) creating an instance of XSLT processor
    2) loading XML data to be processed
    3) loading XSL template to be used
    4) "charging" the processor with XSL template
    5) passing XML data through the processor.

    // 1
    var XSLT = new XSLTProcessor;

    // 2
    var $xml = new XMLHttpRequest;
    $xml.open('GET', 'demo.xml', false);
    $xml.overrideMimeType('text/xml');
    $xml.send(null);
    var xml = $xml.responseXML;

    // 3
    var $xsl = new XMLHttpRequest;
    $xsl.open('GET', 'demo.xsl', false);
    $xsl.overrideMimeType('text/xml');
    $xsl.send(null);
    var xsl = $xsl.responseXML;

    // 4
    XSLT.importStylesheet(xsl);

    // 5
    document.body.
    appendChild(XSLT.transformToFragment(xml, document));

    Full sample at <http://jsnet.sourceforge.net/tmp/xslt/dxslt.html>

    P.S. I wanted to reference a MDC source first - this raised again my
    suspicion that there is some kind of sabotage by anonymous Wiki
    editors. Way too many - IMHO - articles are not just not full or
    erroneous. Not just that: they are rather sophistically written with a
    lot of convincing code samples but with a few key errors or omissions
    well hidden here and there.
    <http://developer.mozilla.org/en/docs/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations>
    is very demonstrative in this aspect.
    That can a winter paranoia from my side of course.
     
    VK, Dec 26, 2006
    #5
  6. VK <> wrote:

    >
    > (One more sample besides the one by Martin Honnen)


    have used the way of Martin to build a menu, here :

    <www.yvon-thoraval.com/Canvas/menu.html>

    a screenshot of it :

    <www.yvon-thoraval.com/Canvas/menu.png>

    it works with Opera 9.1 and Firefox 2 but not with WebKit (latest
    nightly).

    WebKit is able to work with the example of martin i've reproduced here :

    <www.yvon-thoraval.com/JS/xslt>

    i think for the menu case the prob comes from my xsl sheet :

    <xsl:variable name="href"><xsl:value-of select="link"/></xsl:variable>
    <li class="local"><a
    href="javasript:setPage(&quot;{$href}&quot;);"><xsl:value-of
    select="label"/></a></li>

    --
    Père Noël
     
    =?ISO-8859-1?Q?P=E8re_No=EBl?=, Dec 26, 2006
    #6
  7. Zzzbla

    VK Guest

    Père Noël wrote:
    > href="javasript:setPage(&quot;{$href}&quot;);"


    OT to XSLT, but should be "javascript" - unless a typo in the post.

    Also if you are not resolving entities, in HTML it will be as it is
    href="javascript:setPage(&quot;URL&quot;);"
    which is not a valid JavaScript call.

    if you are resolving entities, then in HTML it will be
    href="javasript:setPage("URL");"
    with nested quotes and UA going nuts.

    If entities are resolved on parsing then should be:
    href="javasript:setPage(&apos;{$href}&apos;);"
     
    VK, Dec 26, 2006
    #7
  8. VK <> wrote:

    > OT to XSLT, but should be "javascript" - unless a typo in the post.


    that was a typo of me ))

    > if you are resolving entities, then in HTML it will be
    > href="javasript:setPage("URL");"
    > with nested quotes and UA going nuts.


    i get that output in HTML : verified by DOM Inspector and Firefox.

    --
    Père Noël
     
    =?ISO-8859-1?Q?P=E8re_No=EBl?=, Dec 27, 2006
    #8
    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. =?Utf-8?B?UGF0Qw==?=

    Xslt Transformation getting &lt; and &gt;

    =?Utf-8?B?UGF0Qw==?=, May 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    879
    Steven Cheng[MSFT]
    May 19, 2004
  2. clogwog
    Replies:
    0
    Views:
    444
    clogwog
    Oct 20, 2004
  3. Boss302
    Replies:
    0
    Views:
    1,103
    Boss302
    Nov 21, 2006
  4. Bogdan
    Replies:
    2
    Views:
    686
    Bogdan
    Jun 9, 2008
  5. Zoe Hart
    Replies:
    1
    Views:
    401
    Scott Wisniewski
    Jan 8, 2004
Loading...

Share This Page