Help applying XSLT to ebmedded XML within HTML page

J

jackpod

Hi All,

I'm trying to transform xml that is embedded in my html page using
XSLT to display HTML elements. The issue is that somewhere the
transformation strips out some data. If I load the same xml through a
file on my hard-drive, the transformation works fine. Any ideas? Below
is a simplified example of my code.

HTML PAGE:

<html>
....
<a href="javascript:displayResultfromDOM()">Click here</a>
<div id="xmldata">
<car><name>Honda</name><year>1999</year><price>$2000</
price><condition>excellent</condition></car>
</div>
</html>


JAVASCRIPT:
<script>
function displayResultFromDOM(){
xmlT = loadXMLString(document.getElementById
("xmldata").innerHTML);
return applyTransformation(xmlT);
}

function applyTransformation(xmlObj){
xsl=loadXMLDoc("myxsl.xsl");
// code for IE
if (window.ActiveXObject)
{
ex=xmlObj.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(xmlObj,document);
document.getElementById("example").appendChild(resultDocument);
}

OUTPUT:
Only a name and condition are included in the output. The
others were removed at time of transformation.


Your help is much appreciated.

Thanks
 
M

Martin Honnen

jackpod said:
I'm trying to transform xml that is embedded in my html page using
XSLT to display HTML elements. The issue is that somewhere the
transformation strips out some data. If I load the same xml through a
file on my hard-drive, the transformation works fine. Any ideas? Below
is a simplified example of my code.

HTML PAGE:

<html>
...
<a href="javascript:displayResultfromDOM()">Click here</a>
<div id="xmldata">
<car><name>Honda</name><year>1999</year><price>$2000</
price><condition>excellent</condition></car>
</div>

Only a name and condition are included in the output. The
others were removed at time of transformation.

Put the XML into a file served as XML so that it is parsed and treated
as XML. If you put XML into your HTML then the HTML parser parses it and
then innerHTML serializes it back as HTML and not as XML. That way
results are hardly reliable as the case of element or attributes might
be changed from lower case to upper case for instance.
And we would need to see the code of your functions like loadXMLString
and of course of the stylesheet to be able to understand what exactly
goes wrong.
Also tell us which browser you get the wrong result with.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top