RSS Forums RSS

Regarding xml - html transformation using xslt

Please support our XML, XSLT and XPATH advertiser: Programming Forums
Reply
Posts: 1
Reputation: suprakash444 is an unknown quantity at this point 
Solved Threads: 0
suprakash444 suprakash444 is offline Offline
Newbie Poster

Regarding xml - html transformation using xslt

  #1  
Jan 9th, 2009
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
AddThis Social Bookmark Button
Reply With Quote  
Posts: 78
Reputation: fpmurphy is an unknown quantity at this point 
Solved Threads: 4
fpmurphy fpmurphy is offline Offline
Junior Poster in Training

Re: Regarding xml - html transformation using xslt

  #2  
Jan 22nd, 2009
What Web browser are you using?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the XML, XSLT and XPATH Forum
Views: 685 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:17 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC