Activation of a javascript incorporated after initial loading ofthe page

A

Alexandre Damiron

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>
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top