943,693 Members | Top Members by Rank

Ad:
Jan 9th, 2009
0

Regarding xml - html transformation using xslt

Expand Post »
Hi,

I am trying to transform an XML string to HTML page using xslt. But I am getting the following exception :

The stylesheet doesn't contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document. My code is as below :

Test.html
----------------

<html>
<head>
<script>
function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation&& document.implementation.createDocument)
{

xmlDoc=document.implementation.createDocument(""," ",null);
}
else
{
alert('Your browser cannot handle this script');
}


xmlDoc.async=false;
xmlDoc.loadXML(fname);
alert("mozilla document");
return(xmlDoc);
}

function displayResult()
{
alert("suprakash ");

xmlString = "<catalog><cd><title>Empire Burlesque</title><artist>Bob Dylan</artist></cd></catalog>";
alert("suprakash mozilla 1");
xml=loadXMLDoc(xmlString);
alert("suprkash mozilla 2");
xsl=loadXMLDoc("C:\\xmlXslt\\cdCatalog.xsl");
// code for IE
alert("suprakash mozilla 3");
if (xsl.parseError.errorCode != 0) {
error = xsl.parseError;
alert("Error parsing XSLT file:\n" + error.reason + "[" + error.url +
": line " + error.line + ", col " + error.linepos + "]");
}
alert("suprakash 1");
if (window.ActiveXObject)
{
alert("suprakash 2");
ex = xml.transformNode(xsl);
alert("suprakash 3 " + ex );
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("example").appendChild(res ultDocument);
alert(document.getElementById("example"));
}
}
</script>
</head>
<body id="example" onLoad="displayResult()">
</body>
</html>


cdcatalog.xsl
-------------------

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Awaiting for an early response.

Regards

Suprakash
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
suprakash444 is offline Offline
1 posts
since Jan 2009
Jan 22nd, 2009
0

Re: Regarding xml - html transformation using xslt

What Web browser are you using?
Reputation Points: 22
Solved Threads: 11
Junior Poster
fpmurphy is offline Offline
144 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: XSLT IDE's
Next Thread in XML, XSLT and XPATH Forum Timeline: XPath or Xquery for Courses.xml





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC