我认为,最好的办法是将运行使用JavaScript的转变,然后结果添加到DOM。例如,从http://www.w3schools.com/xsl/xsl_client.asp
<html>
<head>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}
function displayResult()
{
xml=loadXMLDoc("cdcatalog.xml");
xsl=loadXMLDoc("cdcatalog.xsl");
// code for IE
if (window.ActiveXObject)
{
ex=xml.transformNode(xsl);
document.getElementById("example").innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("example").appendChild(resultDocument);
}
}
</script>
</head>
<body onload="displayResult()">
<div id="example" />
</body>
</html>
你能告诉我们一个生成的XML(带有样式表处理指令)的例子吗?你如何把它放入iframe?你还使用什么浏览器? – LarsH 2010-08-18 21:03:43
我通过以下方式序列化xml dom: 函数xml2Str(xmlNode){ 尝试//基于Gecko和Webkit的浏览器(Firefox,Chrome),Opera。 return(new XMLSerializer())。serializeToString(xmlNode); (e){ }尝试{//Internet Explorer。 return xmlNode.xml; } catch(e){ //其他没有XML串行器的浏览器 alert('Xmlserializer not supported'); } } return false; } – Jim 2010-08-18 21:51:56
然后我加载到iframe通过: doc = null; doc = document.getElementById('ifrm')。contentDocument; if(doc == undefined || doc == null) { \t doc = document.getElementById('ifrm')。contentWindow.document; } doc.open(); doc.write(xml2Str(myXml)); doc.close(); – Jim 2010-08-18 21:53:42