« ajaxslt 0.2 and IE6.0 | Main | IE script tag »
Thursday, July 14, 2005
xmlhttprequest.js and http-xslt.html
---
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Simple XSLT test</title>
<script src="misc.js" type="text/javascript"></script>
<script src="dom.js" type="text/javascript"></script>
<script src="xpath.js" type="text/javascript"></script>
<script src="xslt.js" type="text/javascript"></script>
<script type="text/javascript" src="xmlhttprequest.js"></script>
<script type="text/javascript">
var xslt;
var xml;
logging__ = true;
xsltdebug__ = true;
function test_xslt() {
var xml = xmlParse(el('xml').value);
var xslt = xmlParse(el('xslt').value);
var html = xsltProcess(xml, xslt);
el('html').value = html;
el('htmldisplay').innerHTML = html;
}
function cleanxml() {
var req = new XMLHttpRequest();
if (req) {
req.onreadystatechange = function() {
//alert( req.readyState+","+req.status);
//if (req.readyState == 4 && req.status == 200)
if (req.readyState == 4 ) //for local
{
el('xml').value=req.responseText;
cleanvalue('xml');
}
};
req.open('GET', 'xml.xml');
req.send(null);
}
var req2 = new XMLHttpRequest();
if (req2) {
req2.onreadystatechange = function() {
//alert( req.readyState+","+req.status);
//if (req.readyState == 4 && req.status == 200)
if (req2.readyState == 4 ) //for local
{
el('xslt').value=req2.responseText;
cleanvalue('xslt');
}
};
req2.open('GET', 'xslt.xml');
req2.send(null);
}
}
function cleanvalue(id) {
var x = el(id);
x.value = x.value.replace(/^\s*/, '').replace(/\n\s*/g, '\n');
}
</script>
<link rel="stylesheet" href="test.css"/>
</head>
<body onload="cleanxml()">
<form onsubmit="test_xslt();return false">
<table>
<tr>
<td>
<textarea id="xml" cols="40" rows="10">
</textarea>
</td>
<td>
<textarea id="xslt" cols="40" rows="10">
</textarea>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="process"/>
</td>
</tr>
<tr>
<td>
<textarea id="html" cols="40" rows="10">
</textarea>
</td>
<td>
<div id="htmldisplay"></div>
</td>
</tr>
</table>
</form>
</body>
</html>