XML document must have a top level element

I am getting this error when transforming an xml document using an xsl. I have tested that the xsl works in xmlSPY and everything works fine. Both my original xml and the output xml have top level elements (can these have attributes?).

My asp code is:


Set xmlDoc=Server.CreateObject("MSXML2.DOMDocument")
xmlDoc.async=false
xmlDoc.load(Server.MapPath("/npt/xml/data_allcrime.xml"))


set xslDoc = Server.CreateObject("Msxml2.FreeThreadedDOMDocument")
xslDoc.async = false
xslDoc.load(Server.MapPath("/npt/xml/data_allcrime.xsl"))


set xslTemplate = Server.CreateObject("Msxml2.XSLTemplate")
' Setting the actual XSL document in the template
xslTemplate.stylesheet = xslDoc
' Compile your stylesheet into a processor
set xslProc = xslTemplate.createProcessor()
	
xslProc.addParameter "div", "E"

xslProc.input = xmlDoc  ' The xml input here is actually the xml you want to transform
xslProc.transform()  ' Do the transformation

Any help please?

monkey

What error?

sorry - the thread title:

XML document must have a top level element.

Can you show the XML file?

If i do:


Set xmlDoc=Server.CreateObject("MSXML2.DOMDocument")
xmlDoc.async=false
xmlDoc.load(Server.MapPath("/npt/xml/data_allcrime.xml"))

Set xslDoc=Server.CreateObject("MSXML2.DOMDocument")
xslDoc.async = false
xslDoc.load(Server.MapPath("/npt/xml/data_allcrime_v2.xsl"))

str = xmlDoc.transformNode(xslDoc)
Response.Write(str)

everything works fine, but i need to pass some params to the xsl.

The xml starts:


<?xml version="1.0" encoding="iso-8859-1"?>
		<perfStats upToMonth="Jul" financialYear="2006-07">
			<Division id="E">
				<stat type="1">
                                       <YearToDateFigures>
						<reported>111</reported>
						<detected>45</detected>
					</YearToDateFigures

SO is it litterally asking you to add <coolStats> above your perfStats element?

Sounds like it to me, with no attributes or anything, along with an equally closed </coolStats>

perfStats is my root element! Root elements can have atrtributes, but must have no siblings - which it doesn’t.

sorted it - what a fool!!!1

I forgot to response.write my transform output!! hence no top level element!!

cheers for your help :blush: