Solved

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

Posted on 2006-10-24
2
7,982 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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

11 Experts available now in Live!

Get 1:1 Help Now