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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top