Solved

Errror: "Only one top level element is allowed in an XML document"???????

Posted on 2006-10-24
2
8,087 Views
Last Modified: 2008-01-09
Hello

I have just start working with XSLT files and make a sample XSLT file. With following code fo "helloworld.xslt"
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">></xsl:stylesheet>
<xsl:template match="/">
      <html>
            <head>
                  <title>First Sample</title>
            </head>
            <body>
                  <p><xsl:value-of select="greeting"/></p>
            </body>
      </html>
</xsl:template>

my XML file is like as

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="D:\Testing XSLs\helloworld.xslt" ?>
<greeting>Hello, world!</greeting>

When i try to run the XML file a error message is coming just as follow

Error in helloworld.xslt
Only one top level element is allowed in an XML document

Please tell why this message is coming and how can i remove the error

Gaurav..
0
Comment
Question by:momentuminfotech
2 Comments
 
LVL 13

Expert Comment

by:jeebukarthikeyan
ID: 17801559
hi,


<xsl:template match="/">
               <p><xsl:value-of select="greeting"/></p>
</xsl:template>

go like this

b u d d h a
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 125 total points
ID: 17801636
Hi jeebukarthikeyan,

that doesn't really solve the problem
The problem with the above XSLT is that the template should be inside the stylesheet element
The error is here:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">></xsl:stylesheet>
By putting the <xsl:template> element after the stylesheet element
and not inside it, you have two root elements, so your stylesheet is no longer a welformed XML document,
hence your error

here is how you should do this

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <head>
                <title>First Sample</title>
            </head>
            <body>
                <p><xsl:value-of select="greeting"/></p>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

I tested the above stylesheet and it works

Cheers!

Geert
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create html table using xsl 8 46
XML Node Counting in MS Access VBA 4 56
XSL - substring between 2 commas 12 22
Need a modeling tool 2 40
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question