Hi all,
Are you familiar with Safari? I have a site that works perfectly in
IE6 IE7 FF2 FF3 but not in the
latest Safari. When I test xsltProcessor, there is a error as
following, I have dealt with this issue for several days, but there is
no result. Could someone help me?
[Code]
<html>
<head>
<title>Enter the title of your HTML document here</title>
<script type="text/javascript">
var xmlDoc;
var xsltDoc;
var xmlFile="Test_x sltProcessor.xm l";
var xsltFile="Test_ xsltProcessor.x sl";
function show_xml()
{
// Firefox, Opera 8.0+, Safari
if(document.imp lementation &&
document.implem entation.create Document)
{
//load xml file
XMLDocument.pro totype.load = function(filePa th)
{
var xmlhttp = new XMLHttpRequest( );
xmlhttp.open("G ET", filePath, false);
xmlhttp.setRequ estHeader("Cont ent-Type","text/xml");
xmlhttp.send(nu ll);
var newDOM = xmlhttp.respons eXML;
if( newDOM )
{
var newElt = this.importNode (newDOM.documen tElement, true);
this.appendChil d(newElt);
return true;
}
}
xmlDoc = document.implem entation.create Document("", "",
null);
xmlDoc.async = false;
xmlDoc.load(xml File);
//load xsl file
var xsltDoc = document.implem entation.create Document("",
"", null);
xsltDoc.async = false;
xsltDoc.load(xs ltFile);
//build the relationship between xml file and xsl file
var xslt = new XSLTProcessor() ;
xslt.importStyl esheet(xsltDoc) ;
//set parameters
xslt.setParamet er( null, 'testDom', xmlDoc);
//transform
var doc = xslt.transformT oFragment(xmlDo c, document);
//append the xml result to the main html file
var target=document .getElementById ("divContent ");
while (target.hasChil dNodes())
{
target.removeCh ild(target.last Child);
}
target.appendCh ild(doc);
}
else if(typeof window.ActiveXO bject != 'undefined')
{
//load xml file
xmlDoc = new ActiveXObject(' Microsoft.XMLDO M');
xmlDoc.async = false;
xmlDoc.load(xml File);
//load xsl file
xsltDoc = new ActiveXObject(' Microsoft.XMLDO M');
xsltDoc.async = false;
xsltDoc.load(xs ltFile);
//append the xml result to the main html file
var target=document .getElementById ("divContent ");
target.innerHTM L = xmlDoc.document Element.transfo rmNode(xsltDoc) ;
}
}
</script>
</head>
<body onload="show_xm l();">
<p>Enter the body text of your HTML document here</p>
<div id="divContent" ></div>
</body>
</html>
The xsl file is as following:
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/
Transform">
<xsl:param name="testDom"/>
<xsl:template match="/">
<div>
<xsl:value-of select="$testDo m"/>
</div>
</xsl:template>
</xsl:stylesheet>
The xml file is as following:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<test>ccc</test>
</root>
In Safari, the output is [object Document] --It changes to
string$B!$(Bb ut in IE and
Firefox, the output is aaa.
Could someone help me? Thanks!
Are you familiar with Safari? I have a site that works perfectly in
IE6 IE7 FF2 FF3 but not in the
latest Safari. When I test xsltProcessor, there is a error as
following, I have dealt with this issue for several days, but there is
no result. Could someone help me?
[Code]
<html>
<head>
<title>Enter the title of your HTML document here</title>
<script type="text/javascript">
var xmlDoc;
var xsltDoc;
var xmlFile="Test_x sltProcessor.xm l";
var xsltFile="Test_ xsltProcessor.x sl";
function show_xml()
{
// Firefox, Opera 8.0+, Safari
if(document.imp lementation &&
document.implem entation.create Document)
{
//load xml file
XMLDocument.pro totype.load = function(filePa th)
{
var xmlhttp = new XMLHttpRequest( );
xmlhttp.open("G ET", filePath, false);
xmlhttp.setRequ estHeader("Cont ent-Type","text/xml");
xmlhttp.send(nu ll);
var newDOM = xmlhttp.respons eXML;
if( newDOM )
{
var newElt = this.importNode (newDOM.documen tElement, true);
this.appendChil d(newElt);
return true;
}
}
xmlDoc = document.implem entation.create Document("", "",
null);
xmlDoc.async = false;
xmlDoc.load(xml File);
//load xsl file
var xsltDoc = document.implem entation.create Document("",
"", null);
xsltDoc.async = false;
xsltDoc.load(xs ltFile);
//build the relationship between xml file and xsl file
var xslt = new XSLTProcessor() ;
xslt.importStyl esheet(xsltDoc) ;
//set parameters
xslt.setParamet er( null, 'testDom', xmlDoc);
//transform
var doc = xslt.transformT oFragment(xmlDo c, document);
//append the xml result to the main html file
var target=document .getElementById ("divContent ");
while (target.hasChil dNodes())
{
target.removeCh ild(target.last Child);
}
target.appendCh ild(doc);
}
else if(typeof window.ActiveXO bject != 'undefined')
{
//load xml file
xmlDoc = new ActiveXObject(' Microsoft.XMLDO M');
xmlDoc.async = false;
xmlDoc.load(xml File);
//load xsl file
xsltDoc = new ActiveXObject(' Microsoft.XMLDO M');
xsltDoc.async = false;
xsltDoc.load(xs ltFile);
//append the xml result to the main html file
var target=document .getElementById ("divContent ");
target.innerHTM L = xmlDoc.document Element.transfo rmNode(xsltDoc) ;
}
}
</script>
</head>
<body onload="show_xm l();">
<p>Enter the body text of your HTML document here</p>
<div id="divContent" ></div>
</body>
</html>
The xsl file is as following:
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/
Transform">
<xsl:param name="testDom"/>
<xsl:template match="/">
<div>
<xsl:value-of select="$testDo m"/>
</div>
</xsl:template>
</xsl:stylesheet>
The xml file is as following:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<test>ccc</test>
</root>
In Safari, the output is [object Document] --It changes to
string$B!$(Bb ut in IE and
Firefox, the output is aaa.
Could someone help me? Thanks!
Comment