I'm using MSXML 2.0 to manipulate XML/XSLT files in my ASP code. I'm running the following code:
Set ObjXSLTemplate = CreateObject("Msxml2.XSLTe
mplate.4.0
")
Set ObjXSLDoc = CreateObject("Msxml2.FreeT
hreadedDOM
Document.4
.0")
Set ObjXMLDoc = CreateObject("Msxml2.DOMDo
cument.4.0
")
ObjXSLDoc.async = false
ObjXSLDoc.resolveExternal = false
ObjXSLDoc.load("QNS.xsl")
ObjXMLDoc .async = false
ObjXMLDoc .resolveExternal = false
ObjXMLDoc .loadXML(xml)
set ObjXSLTemplate.stylesheet = ObjXSLDoc
set ObjXSLProc = ObjXSLTemplate.createProce
ssor()
ObjXSLProc.input = ObjXMLDoc
ObjXSLProc.Transform()
if LogALL then WriteToLog "Result XML after XSL transformation: " & ObjXSLProc.output
ObjXMLDoc.loadXML(ObjXSLPr
oc.output)
xml is a string that contains XML tree:
<?xml version="1.0"?>
<Response>
<EmailCounters>
<NewEmailMsg>-1</NewEmailM
sg>
<TotalEmailMsg>-1</TotalEm
ailMsg>
<UrgentEmailMsg>-1</Urgent
EmailMsg>
</EmailCounters>
<VoiceCounters>
<NewFaxMsg>-1</NewFaxMsg>
<NewVoiceMsg>-1</NewVoiceM
sg>
<TotalFaxMsg>-1</TotalFaxM
sg>
<TotalVoiceMsg>-1</TotalVo
iceMsg>
<UrgentMsg>-1</UrgentMsg>
</VoiceCounters>
<EmailCountersUpdate>
<NewEmailMsgUD>Deactivate<
/NewEmailM
sgUD>
<TotalEmailMsgUD>Deactivat
e</TotalEm
ailMsgUD>
<UrgentEmailMsgUD>Deactiva
te</Urgent
EmailMsgUD
>
</EmailCountersUpdate>
<VoiceCountersUpdate>
<NewFaxMsgUD>Deactivate</N
ewFaxMsgUD
>
<NewVoiceMsgUD>Deactivate<
/NewVoiceM
sgUD>
<TotalFaxMsgUD>Deactivate<
/TotalFaxM
sgUD>
<TotalVoiceMsgUD>Deactivat
e</TotalVo
iceMsgUD>
<UrgentMsgUD>Deactivate</U
rgentMsgUD
>
</VoiceCountersUpdate>
<AccountInfo>
<LastMsgType>voice</LastMs
gType>
</AccountInfo>
</Response>
QNS.xsl contains:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/Response">
<mb>
<nem><xsl:value-of select="EmailCounters/NewE
mailMsg"/>
</nem>
<em><xsl:value-of select="EmailCounters/Tota
lEmailMsg"
/></em>
<nvm><xsl:value-of select="VoiceCounters/NewV
oiceMsg"/>
</nvm>
<vm><xsl:value-of select="VoiceCounters/Tota
lVoiceMsg"
/></vm>
<nfm><xsl:value-of select="VoiceCounters/NewF
axMsg"/></
nfm>
<fm><xsl:value-of select="VoiceCounters/Tota
lFaxMsg"/>
</fm>
<uem></uem>
<um></um>
</mb>
</xsl:template>
<xsl:template match="/EmailCountersUpdat
e"/>
<xsl:template match="/VoiceCountersUpdat
e"/>
<xsl:template match="/AccountInfo"/>
<xsl:template match="//UrgentEmailMsg"/>
<xsl:template match="//UrgentMsg"/>
</xsl:stylesheet>
Transformation result that appears in the logger is :
Result XML after XSL transformation: <?xml version="1.0"?><mb><nem>-1
</nem><em>
-1</em><nv
m>-1</nvm>
<vm>-1</vm
><nfm>-1</
nfm><fm>-1
</fm></mb>
But, ObjXMLDoc.loadXML(ObjXSLPr
oc.output)
fails with the following error:
XML document must have a top level element
What's wrong?
Thanks
Start Free Trial