Activation of a javascript incorporated after initial loading ofthe page

Discussion in 'Javascript' started by Alexandre Damiron, Nov 29, 2005.

  1. Hi, I send an intial js loader to the browser, namely htmlOutput

    function htmlOutput(xmlUri, xslUri){

    var xmlHttp = XmlHttp.create(); //XmlHttp is a cross-browser
    httpRequest Class. We load the xml file
    var async = true;
    xmlHttp.open("GET", xmlUri, async);
    xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4){ //Once loaded, the xsl stylesheet is
    loaded too, then imported into the xslt processor
    // TODO error control
    var processor = new XSLTProcessor();
    var xslHttp = XmlHttp.create();
    var xslasync = true;
    xslHttp.open("GET", xslUri, xslasync);
    xslHttp.onreadystatechange = function () {
    if (xslHttp.readyState == 4){
    processor.importStylesheet(xslHttp.responseXML);
    var newDocument =
    processor.transformToDocument(xmlHttp.responseXML); //xslt produce a DomDoc
    var bodyChildren = new Array();
    bodyChildren = newDocument.getElementsByTagName("body")[0].childNodes;
    for (var i = 0; i < bodyChildren.length; i++) { //each part of the
    body is imported into the displayed doc, namely document

    document.getElementsByTagName("body")[0].appendChild(document.importNode(bodyChildren,
    true));
    }
    var bodyChildren = new Array();
    headChildren = newDocument.getElementsByTagName("head")[0].childNodes;
    for (var i = 0; i < headChildren.length; i++) { //same for each
    part of the head is imported into the displayed doc, namely document

    document.getElementsByTagName("head")[0].appendChild(document.importNode(headChildren,
    true));
    }
    }
    }
    xslHttp.send(null);
    }
    }
    xmlHttp.send(null);

    }

    This is very classical. Xml is loaded, then Xsl, XsltProcessor is
    instanciated, filled with the stylesheet, the transformation is made.
    Finally, I import into the displayed document every node which interest
    me, in the body then in the head section. In that case, every node of
    the XHTML output produced. It works. I am happy, because everything is
    loaded just once, and my xmlHttp.responseXML is ready to be worked on,
    while the nodes are displayed and present in the DOM inspector.
    But There is a problem: The script node I add via xslt does not seem to
    be evaluated. Its functions are not taken into consideration. Any ideas ?

    The xsl: add_user_input() is in add.js. But clicking the button throw
    that there is no such function. An alert('test') in that js does not
    work either.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <xsl:template match="/">
    <html>
    <head>
    <title>Gestion des droits trac: Interface</title>
    <link type="image/x-icon" href="/favicon.ico" rel="shortcut
    icon"></link>
    <link href="URI/dev.css" type="text/css" rel="stylesheet"></link>
    <meta content="text/html; charset=ISO-8859-1"
    http-equiv="Content-Type"></meta>
    <meta content ="" name="keywords"></meta>
    <meta content ="" name="description"></meta>
    <meta http-equiv = "content-language" content = "fr-FR, en-US"></meta>
    <meta http-equiv = "cache-control" content = "no-cache"></meta>
    <meta name = "author" content = "Alexandre Damiron"></meta>
    <script type='text/javascript' src='URI/javascripts/add.js'>
    </script>
    </head>
    <body>

    <table>
    <xsl:for-each select="/Repositories/Repository">
    <tr>
    <td>
    <div><xsl:value-of select="Path"/></div><input type="button"
    value="Ajouter un utilisateur" onclick="javascript:add_user_input()" />
    <br/>
    <table>
    <xsl:for-each select="Users/User">
    <tr>
    <td>
    <i><xsl:value-of select="."/></i>
    </td>
    </tr>
    </xsl:for-each>
    </table>
    </td>
    </tr>
    </xsl:for-each>
    </table>

    </body>
    </html>

    </xsl:template>

    </xsl:stylesheet>
    Alexandre Damiron, Nov 29, 2005
    #1
    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. Marine
    Replies:
    3
    Views:
    23,602
    Marine
    Feb 15, 2006
  2. Andrew Thompson

    When was 'sound.jar incorporated in JRE?

    Andrew Thompson, Sep 17, 2006, in forum: Java
    Replies:
    1
    Views:
    1,335
    Andrew Thompson
    Sep 17, 2006
  3. robert
    Replies:
    16
    Views:
    1,181
  4. bhabs
    Replies:
    2
    Views:
    369
    Tad J McClellan
    Feb 13, 2008
  5. TPK
    Replies:
    1
    Views:
    295
    Tim Slattery
    Aug 27, 2010
Loading...

Share This Page