Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-10-24
2
Medium Priority
?
8,185 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 375 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

721 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