p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 9th, 2009, 11:44 PM
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 1
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old January 12th, 2009, 01:23 AM
Friend of Wrox
Points: 949, Level: 11
Points: 949, Level: 11 Points: 949, Level: 11 Points: 949, Level: 11
Activity: 31%
Activity: 31% Activity: 31% Activity: 31%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 205
Thanks: 9
Thanked 22 Times in 22 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 06:13 PM
XSLT transformation from XML buffer and XSL file sundaramkumar Javascript 1 September 5th, 2005 03:11 AM
Xml to Xml Transformation using xslt ShaileshShinde XSLT 1 July 20th, 2005 02:20 AM
XML to XML transformation using XSLT karjagis XSLT 3 July 30th, 2004 07:13 AM



All times are GMT -4. The time now is 02:13 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc