Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 9th, 2009, 11:44 PM
Registered User
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


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 :


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);
alert('Your browser cannot handle this script');

alert("mozilla document");

function displayResult()
alert("suprakash ");

xmlString = "<catalog><cd><title>Empire Burlesque</title><artist>Bob Dylan</artist></cd></catalog>";
alert("suprakash mozilla 1");
alert("suprkash mozilla 2");
// 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();
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("example").appendChild(res ultDocument);
<body id="example" onLoad="displayResult()">


<xsl:stylesheet version="1.0"
<xsl:template match="/">
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
<xsl:for-each select="catalog/cd">
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>

Awaiting for an early response.


Old January 12th, 2009, 01:23 AM
Friend of Wrox
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts

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.

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

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