Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with XML client side in non IE browsers 1

Status
Not open for further replies.

Dozzer81

Technical User
Jun 29, 2007
14
GB
I'm completely new to XML and am having a major problem trying to display the content in non IE browsers. I have tried various methods including server side which doesn't work at all for me. I think its the javascript but unfortunately I understand html and css a lot better than xml,xslt and javascript.

I would appreciate any help as I'm completely stuck on this, I have followed the tutorials at w3cschools and think the XSLT and XML is correct.I have supplied the code for my XML, XSLT and javascript below. This works in IE but not in any other browser.

<<<<<<<<<<<<<<< My XML: >>>>>>>>>>>>>>>>>>>>>>

<?xml version="1.0" encoding="ISO-8859-1"?>
<artistlist>
<artist>
<name>Dorian Piaskowski</name>
<address>piaskowski-d.html</address>
</artist>
<artist>
<name>Tom Piaskowski</name>

<address>piaskowski-t.html</address>
</artist>
</artistlist>


<<<<<<<<<<<<<<<< MY XSLT: >>>>>>>>>>>>>>>>>>>>>>>

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl=" version="1.0">
<xsl:template match="/">
<html>
<head>
<title>Solana Gallery - Contemporary russian art</title>
<link href="gallery.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="logo"><a href="index.html"><img src="images/Small_Solana-Logo.png" alt="Solana Gallery Logo" /></a></div>

<div class="container">
<h2>Artist List</h2>
<h3>Title</h3>
<ul class="clientlist">
<xsl:for-each select="artistlist/artist">
<li>
<a href="{address}"><p><xsl:value-of select="name"/></p></a> </li>

</xsl:for-each>
</ul>
</div>
<div class="nav">
<ul>
<li><a href="index.html">Home</a></li>
</ul>
<ul>
<li><a href="artistlist.html">Artists</a></li>

</ul>
<ul>
<li><a>Exhibitions</a>
<ul>
<li><a>Recent</a></li>
<li><a>Future</a></li>
<li><a href="past.html">Past</a></li>

</ul>
</li>
</ul>
<ul>
<li><a href="contactus.html">Contact Us</a></li>
</ul>
<ul>
<li><a>About Us</a>

<ul>
<li><a href="whoweare.html">Who We Are</a></li>
<li><a href="artservices.html">Art Services</a></li>
<li><a href="clients.html">Clients</a></li>
<li><a href="news.html">News</a></li>
</ul>
</li>

</ul>
</div>
<!-- end the menuh div -->

</body>
</html>
</xsl:template>
</xsl:stylesheet>

<<<<<<<<<<<<<<< MY HTML: >>>>>>>>>>>>>>>>>>

<html>
<body>
<script type="text/javascript">
var xmlDoc;
{
// code for IE
if (window.ActiveXObject)
{
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async=false;
xml.load("artistlist.xml");

// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM");
xsl.async = false;
xsl.load("artistlist.xsl");

// Transform
document.write(xml.transformNode(xsl))
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation &&
document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("artistlist.xml");
}
else
{
alert('Your browser cannot handle this script');
}
}

</script>

</body>
</html>
 
Here is an article from the IBM site that covers a lot of this information.

This is a subject that takes a chapter (or more) in most books that cover XML in browsers. Try some of the suggestions in the IBM article and see if that helps.

Tom Morrison
 
Like this.
[tt]
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
[blue]xmlDoc.async=false;[/blue]
xmlDoc.load("artistlist.xml");
[blue]var xsltProc = new XSLTProcessor();
var xsl=document.implementation.createDocument("","",null);
xsl.async=false;
xsl.load("artistlist.xsl");
xsltProc.importStylesheet(xsl);
xmlDoc=xsltProc.transformToDocument(xmlDoc);
var serializer=new XMLSerializer();
document.write(serializer.serializeToString(xmlDoc));[/blue]
}
[/tt]
 
Thanks tsuji this works great!

Kind regards

Dozzer81
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top