Solved

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

Posted on 2006-10-24
2
8,005 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now