Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transform XML via XSL and save as XML

Status
Not open for further replies.

illcomms

Programmer
Jan 15, 2007
1
AU
Hi All,

I'm attempting to save the xsl processors output back into XML, however when it gets to the save method it bombs out saying:

Object required: 'xmlNewDoc'.

Also I have dumped the contents of the output in the html and it works fine and the output I wanted is correct. For whatever reason it doesn't want to save. And its not a permissions settings as I have full rights.

Code is as follows, if anyone can help I'd be most greatful!

=============ASP====================================
Set xslDoc = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
xslDoc.async = False
xslDoc.setProperty "SelectionLanguage", "XPath"
xslDoc.load( Server.MapPath("styles/xsl/rep_service_action.xsl") )

Set xmlTemplate = Server.CreateObject("Msxml2.XSLTemplate.3.0")
xmlTemplate.stylesheet = xslDoc

Set myProc = xmlTemplate.createProcessor()
myProc.input = xmlGroupDoc

myProc.transform()

Set xmlNewDoc = Server.CreateObject("Msxml2.DOMDocument.3.0")
xmlNewDoc.async = False
xmlNewDoc.validateOnParse = False
xmlNewDoc.preserveWhiteSpace = True
xmlNewDoc.resolveExternals = False
xmlNewDoc = myProc.output
xmlNewDoc.save("C:\AMS_Final\MAINTENANCE\temp4.xml")
=======================================================

=============XSL=======================================
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=" version="1.0">
<xsl:variable name="theStylesheet" select="document('')" />
<xsl:eek:utput method="xml" version="4.0" encoding="utf-8"/>

<xsl:template match="SERVICE_REQUESTS">
<xsl:apply-templates select="REQUEST_LIST"/>
</xsl:template>

<xsl:template match="REQUEST_LIST">
<xsl:choose>
<xsl:when test="count(row) > 0 ">
<chart title='My Chart' legend='right'>
<pie radius="1500" squash="1.5" thickness="20" labels="percent" />
<style>
<title font="Georgia" size="20" color="#FF9900" bold="true" />
<label font="Arial" size="12" color="#000000" bold="false" />
<legend rowodd="#EEEEEE" even="#DDDDDD" border="#000000" />
</style>
<values sort="descending">
<node value="30" label="widget 1" color="#FF0000" />
<node value="20" label="widget 2" color="#00FF00" />
<node value="60" label="widget 3" color="#0000FF" />
</values>
</chart>
</xsl:when>
<xsl:eek:therwise>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
======================================================
 
I think the culprit is here:
xmlNewDoc = myProc.output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
[1] Tell the forum what is xml version="4.0"???
><xsl:eek:utput method="xml" version="4.0" encoding="utf-8"/>
[tt]<xsl:eek:utput method="xml" version="[red]1[/red].0" encoding="utf-8"/>[/tt]

[2] Your transformation will not result in a well-form xml document. You need to set up a top element. As an illustration, like this to salvage the whole thing.
[tt]
<xsl:template match="SERVICE_REQUESTS">
[blue]<root>[/blue]
<xsl:apply-templates select="REQUEST_LIST"/>
[blue]</root>[/blue]
</xsl:template>
[/tt]
[3] Now the vbscript itself.

[3.1] You have not shown how you set up xmlGroupDoc. I hope you set it up right as the domdocument properly loaded up with a well-form xml source document.

[3.2] The way you understand .output is not correct.
[3.2.a] It must be setup _before_ transform().
[3.2.b] It is assigned to be the xmlNewDoc. Not the other way around.
[tt]
'etc etc
Set myProc = xmlTemplate.createProcessor()
myProc.input = xmlGroupDoc
[red]'[/red]myProc.transform()

Set xmlNewDoc = Server.CreateObject("Msxml2.DOMDocument.3.0")
xmlNewDoc.async = False
xmlNewDoc.validateOnParse = False
xmlNewDoc.preserveWhiteSpace = True
xmlNewDoc.resolveExternals = False
[red]'[/red]xmlNewDoc = myProc.output
[blue]myProc.output=xmlNewDoc[/blue]

[blue]myProc.transform()[/blue]

xmlNewDoc.save("C:\AMS_Final\MAINTENANCE\temp4.xml")
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top