admin管理员组文章数量:1317898
I'm using the following javascript code to display xml/xsl:
function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
try {
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}
catch(e)
{
try //Google Chrome
{
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET",file,false);
xmlhttp.send(null);
xmlDoc = xmlhttp.responseXML.documentElement;
return(xmlDoc);
}
catch(e)
{
error=e.message;
}
}
}
function displayResult()
{
xml=loadXMLDoc("report.xml");
xsl=loadXMLDoc("report.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);
}
}
It works find for IE and Firefox but chrome is fail in the line:
document.getElementById("example").appendChild(resultDocument);
Thank you for you help
I'm using the following javascript code to display xml/xsl:
function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
try {
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}
catch(e)
{
try //Google Chrome
{
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET",file,false);
xmlhttp.send(null);
xmlDoc = xmlhttp.responseXML.documentElement;
return(xmlDoc);
}
catch(e)
{
error=e.message;
}
}
}
function displayResult()
{
xml=loadXMLDoc("report.xml");
xsl=loadXMLDoc("report.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);
}
}
It works find for IE and Firefox but chrome is fail in the line:
document.getElementById("example").appendChild(resultDocument);
Thank you for you help
Share Improve this question edited Apr 16, 2010 at 13:42 Kinlan 16.6k5 gold badges58 silver badges88 bronze badges asked Jan 7, 2010 at 13:42 GuyGuy 3252 gold badges6 silver badges14 bronze badges2 Answers
Reset to default 5Google Chrome currently has limited support for XSL. If your XSL refers to any external resources (document()
function, xsl:import
, xsl:include
or external entities), the XSL will run but the result will either be empty or invalid.
If that's not the cause of your problem, the issue can be different: resultDocument
and document
do not share the same root. Try to use importNode or a similar technique. If that fails and you're certain that resultDocument has valid contents, transform it to a string, add a node manually, and set innerHTML
of the new node to the string. I know, it's ugly, but until Chrome bees mature we'll need some workarounds...
I have found that Chrome (for tr and td tags at least), requires well formed html. Eg you cannot start at tr - it must be in a tbody (or thead), but you can't start there either, it must be placed inside a table tag... (I don't think the xslt engine is forgiving on the rules of html - even if you are trying to form a fragment.)
So if you want table from an xslt - do the whole thing, not a part. Ie Do this:
<table><tbody><tr><td></td></tr></tbody></table>
NOT THIS:
<tbody><tr><td></td></tr></tbody>
OR THIS:
<tr><td></td></tr>
Or in my experience, the tr tags got lost and it just looked like a lot of text.
本文标签: xsltjavascript XSL in google chromeStack Overflow
版权声明:本文标题:xslt - javascript XSL in google chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742034572a2417095.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论