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