Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 9th, 2009, 11:44 PM
Registered User
Points: 11, Level: 1
Points: 11, Level: 1 Points: 11, Level: 1 Points: 11, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regarding xml-html transformation of an xml string using xslt and javascript

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

<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
Reply With Quote
  #2 (permalink)  
Old January 12th, 2009, 01:23 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Try to google for the exception "The stylesheet doesn't contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document.". You can find solution.
__________________
Rummy
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Transformation - General HTML Issue tclotworthy XSLT 2 February 27th, 2007 03:42 PM
Is XML supports transformation of HTML to XML? zeeonline XSLT 1 July 28th, 2006 05:13 PM
XSLT transformation from XML buffer and XSL file sundaramkumar Javascript 1 September 5th, 2005 02:11 AM
Xml to Xml Transformation using xslt ShaileshShinde XSLT 1 July 20th, 2005 01:20 AM
XML to XML transformation using XSLT karjagis XSLT 3 July 30th, 2004 06:13 AM



All times are GMT -4. The time now is 11:53 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.