Solved

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

Posted on 2006-10-24
2
8,133 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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 …
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

636 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