post a parameter dom to xsl for Safari

J

Jason

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_xsltProcessor.xml";
var xsltFile="Test_xsltProcessor.xsl";

function show_xml()
{
// Firefox, Opera 8.0+, Safari
if(document.implementation &&
document.implementation.createDocument)
{
//load xml file
XMLDocument.prototype.load = function(filePath)
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", filePath, false);
xmlhttp.setRequestHeader("Content-Type","text/xml");
xmlhttp.send(null);
var newDOM = xmlhttp.responseXML;
if( newDOM )
{
var newElt = this.importNode(newDOM.documentElement, true);
this.appendChild(newElt);
return true;
}
}
xmlDoc = document.implementation.createDocument("", "",
null);
xmlDoc.async = false;
xmlDoc.load(xmlFile);

//load xsl file
var xsltDoc =  document.implementation.createDocument("",
"", null);
xsltDoc.async = false;
xsltDoc.load(xsltFile);

//build the relationship between xml file and xsl file
var xslt = new XSLTProcessor();
xslt.importStylesheet(xsltDoc);

//set parameters
xslt.setParameter( null, 'testDom', xmlDoc);

//transform
var doc =  xslt.transformToFragment(xmlDoc, document);
//append the xml result to the main html file
var target=document.getElementById("divContent");
while (target.hasChildNodes())
{
target.removeChild(target.lastChild);
}
target.appendChild(doc);
}
else if(typeof window.ActiveXObject != 'undefined')
{
//load xml file
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
xmlDoc.load(xmlFile);

//load xsl file
xsltDoc = new ActiveXObject('Microsoft.XMLDOM');
xsltDoc.async = false;
xsltDoc.load(xsltFile);

//append the xml result to the main html file
var target=document.getElementById("divContent");
target.innerHTML = xmlDoc.documentElement.transformNode(xsltDoc);
}
}
</script>
</head>
<body onload="show_xml();">
<p>Enter the body text of your HTML document here</p>
<div id="divContent"></div>
</body>
</html>

The xsl file is as following:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:param name="testDom"/>
<xsl:template match="/">
<div>
<xsl:value-of select="$testDom"/>
</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!$(Bbut in IE and
Firefox, the output is aaa.

Could someone help me? Thanks!
 
M

Martin Honnen

Jason said:
The xsl file is as following:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:param name="testDom"/>
<xsl:template match="/">
<div>
<xsl:value-of select="$testDom"/>
</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!$(Bbut in IE and
Firefox, the output is aaa.

For you IE you do not even set the parameter testDom before the
transformation so why should IE output something for <xsl:value-of
select="$testDom"/>? That does not make sense.
And why should Firefox output 'aaa' if the 'test' element in the
document contains 'ccc'? That does not make sense either.

What exactly is it that you want to achieve? If you have a primary input
document for your XSLT transformation then why do you want to pass the
same document as a parameter? That does not make much sense either,
unless you want to test whether the XSLT implementation supports passing
in a DOM document as the parameter.
 
J

Jason

Jason said:
The xsl file is as following:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:param name="testDom"/>
<xsl:template match="/">
<div>
<xsl:value-of select="$testDom"/>
</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£¬but in IE and
Firefox, the output is aaa.

For you IE you do not even set the parameter testDom before the
transformation so why should IE output something for <xsl:value-of
select="$testDom"/>? That does not make sense.
And why should Firefox output 'aaa' if the 'test' element in the
document contains 'ccc'? That does not make sense either.

What exactly is it that you want to achieve? If you have a primary input
document for your XSLT transformation then why do you want to pass the
same document as a parameter? That does not make much sense either,
unless you want to test whether the XSLT implementation supports passing
in a DOM document as the parameter.

--

Martin Honnen
http://JavaScript.FAQTs.com/- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -

Hi,
I'm sorry,the xml file should be as following:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<test>aaa</test>
</root>

You are right. I want to test whether the XSLT implementation supports
passing
in a DOM document as the parameter.
Could you help me have a look at the issue? Any help will be much
appreciated.
 
J

Jason

Jason said:
The xsl file is as following:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:param name="testDom"/>
<xsl:template match="/">
<div>
<xsl:value-of select="$testDom"/>
</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£¬but in IE and
Firefox, the output is aaa.
For you IE you do not even set the parameter testDom before the
transformation so why should IE output something for <xsl:value-of
select="$testDom"/>? That does not make sense.
And why should Firefox output 'aaa' if the 'test' element in the
document contains 'ccc'? That does not make sense either.
What exactly is it that you want to achieve? If you have a primary input
document for your XSLT transformation then why do you want to pass the
same document as a parameter? That does not make much sense either,
unless you want to test whether the XSLT implementation supports passing
in a DOM document as the parameter.

Martin Honnen
http://JavaScript.FAQTs.com/-Òþ²Ø±»ÒýÓÃÎÄ×Ö -
- ÏÔʾÒýÓõÄÎÄ×Ö -

Hi,
I'm sorry,the xml file should be as following:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<test>aaa</test>
</root>

You are right. I want to test whether the XSLT implementation supports
passing
in a DOM document as the parameter.
Could you help me have a look at the issue? Any help will be much
appreciated.- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -

And the html should be like as following:
Code:
<html>
<head>
<title>Enter the title of your HTML document here</title>
<script type="text/javascript">
var xmlDoc;
var xsltDoc;
var xmlFile="Test_xsltProcessor.xml";
var xsltFile="Test_xsltProcessor.xsl";


function show_xml()
{
// Firefox, Opera 8.0+, Safari
if(document.implementation &&
document.implementation.createDocument)
{
//load xml file
XMLDocument.prototype.load = function(filePath)
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", filePath, false);
xmlhttp.setRequestHeader("Content-Type","text/xml");
xmlhttp.send(null);
var newDOM = xmlhttp.responseXML;
if( newDOM )
{
var newElt = this.importNode(newDOM.documentElement,
true);
this.appendChild(newElt);
return true;
}
}
xmlDoc = document.implementation.createDocument("", "",
null);
xmlDoc.async = false;
xmlDoc.load(xmlFile);


//load xsl file
var xsltDoc =  document.implementation.createDocument("",
"", null);
xsltDoc.async = false;
xsltDoc.load(xsltFile);


//build the relationship between xml file and xsl file
var xslt = new XSLTProcessor();
xslt.importStylesheet(xsltDoc);


//set parameters
xslt.setParameter( null, 'testDom', xmlDoc);


//transform
var doc =  xslt.transformToFragment(xmlDoc, document);
//append the xml result to the main html file
var target=document.getElementById("divContent");
while (target.hasChildNodes())
{
target.removeChild(target.lastChild);
}
target.appendChild(doc);
}
else if(typeof window.ActiveXObject != 'undefined')
{
//load xml file
xmlDoc = new ActiveXObject( "MSXML2.FreeThreadedDomDocument.
3.0" );
xmlDoc.async = false;
xmlDoc.load(xmlFile);


//load xsl file
xsltDoc = new ActiveXObject( "MSXML2.FreeThreadedDomDocument.
3.0" );
xsltDoc.async = false;
xsltDoc.load(xsltFile);

var template = new ActiveXObject( "MSXML2.XSLTemplate.
3.0" );
template.stylesheet = xsltDoc;
var processor = template.createProcessor();
processor.input = xmlDoc;
processor.addParameter("testDom",xmlDoc);
processor.transform();

//append the xml result to the main html file
var target=document.getElementById("divContent");
target.innerHTML = processor.output;;
}
}
</script>
</head>
<body onload="show_xml();">
<p>Enter the body text of your HTML document here</p>
<div id="divContent"></div>
</body>
</html>
 
M

Martin Honnen

Jason said:
You are right. I want to test whether the XSLT implementation supports
passing
in a DOM document as the parameter.
Could you help me have a look at the issue? Any help will be much
appreciated.

Based on your test result it sounds as if Safari converts the DOM
document node to a string and passes that string in.
 
J

Jason

Based on your test result it sounds as if Safari converts the DOM
document node to a string and passes that string in.

Hi Martin,
Yes, Safari converts the DOM document node to a string and passes the
string in. I can use the following code to test it.
Code:
var testDom = xslt.getParameter(null,'testDom')
alert(typeof(testDom))

It ouputs string.
 

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

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top