HighDots Forums  

Help applying XSLT to ebmedded XML within HTML page

Javascript JavaScript language (comp.lang.javascript)


Discuss Help applying XSLT to ebmedded XML within HTML page in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jackpod
 
Posts: n/a

Default Help applying XSLT to ebmedded XML within HTML page - 11-05-2009 , 08:28 AM






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(res ultDocument);
}

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

Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: Help applying XSLT to ebmedded XML within HTML page - 11-05-2009 , 09:15 AM






jackpod wrote:

Quote:
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

Quote:
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.

--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.