Author Topic: Chapter 21 Problem 21-9 compare two xml file with different ordering of nodes  (Read 1824 times)

Offline claudiozhang

  • Jr. Member
  • **
  • Posts: 60
hi, Tarun,
When the code is executed to outputText = xmlDoc.transformNode(xslDoc.documentElement),system pops up an error message:  invalid call of function or arguments :'(
I don't know the reason...
Do you have any idea?
Thanks in advance!!!

Code: [Select]
'Function to Apply a XSL to XML and save the output as a file
Public Function ApplyXSL(ByVal inputXML, ByVal inputXSL, ByVal outputFile)

'This should always work. Bu there are different version of XML Lib
'that we can use. Chnage the Lib name as per the library available on
'the system
sXMLLib = "MSXML.DOMDocument"
'Load the XML document
Set xmlDoc = CreateObject(sXMLLib)
'Load the XSL sytlesheet
Set xslDoc = CreateObject(sXMLLib)

xmlDoc.async = False
xslDoc.async = False
'Load the XSL file
xslDoc.load inputXSL
'Load the XML file
xmlDoc.load inputXML

'Apply the XSL stylesheet and get the tranformed text
[b][color=red]outputText = xmlDoc.transformNode(xslDoc.documentElement)[/color][/b]

'Write the text to a file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set outFile = FSO.CreateTextFile(outputFile,True)
outFile.Write outputText
outFile.Close

'Cleanup all objects
Set outFile = Nothing
Set FSO = Nothing
Set xmlDoc = Nothing
Set xslDoc = Nothing
Set xmlResults = Nothing
End Function

ApplyXSL "c:\b.xml","inputxsl.xsl","output.xml"

inputxsl.xsl
Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="@* |*">
        <xsl:copy>
            <xsl:apply-templates select="@* |*">
                <xsl:sort order="ascending" data-type="text" select="local-name()"/>
                <xsl:sort order="ascending" data-type="text" select="descendant-or-self::node()"/>
                <xsl:sort order="ascending" data-type="text" select="@name"/>
            </xsl:apply-templates>
            <xsl:value-of select="text()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

c:\b.xml
Code: [Select]
<Environment>
  <Variable>
    <Value>Claudio</Value>
    <Name>FirstName</Name>
  </Variable>
</Environment>
« Last Edit: March 29, 2010, 09:18:11 am by claudiozhang »
Claudio Zhang
MSN: claudiozhang@hotmail.com

Offline Tarun Lalwani

  • Administrator
  • Hero Member
  • *****
  • Posts: 3025
    • KnowledgeInbox
You didn't give the path of all files

ApplyXSL "c:\b.xml","inputxsl.xsl","output.xml"

should be

ApplyXSL "c:\b.xml","c:\inputxsl.xsl","c:\output.xml"
Regards,
Tarun
KnowledgeInbox Administrator

KnowledgeInbox" style="border:0

Offline claudiozhang

  • Jr. Member
  • **
  • Posts: 60
You didn't give the path of all files

ApplyXSL "c:\b.xml","inputxsl.xsl","output.xml"

should be

ApplyXSL "c:\b.xml","c:\inputxsl.xsl","c:\output.xml"

Sorry, I made a mistake, I put the "inputxsl.xsl" into the current test folder,have not save the test and run it :'(
It is a stupid error >:(

BTW, I can't find the related document in MSDN about MSXML.DOMDocument, and how I can know I use the Version 2.0 lib "MSXML.DOMDocument"?

I only found:
How Do I use the XML DOM?

You use the XML DOM by creating an instance of an XML parser. To make this possible, Microsoft exposes the XML DOM via a set of standard COM interfaces in Msxml.dll. Msxml.dll contains the type library and implementation code for you to work with XML documents. If you're working with a scripting client, such as VBScript executing in Internet Explorer, you use the DOM by using the CreateObject method to create an instance of the Parser object.
Set objParser = CreateObject( "Microsoft.XMLDOM" )
Claudio Zhang
MSN: claudiozhang@hotmail.com

Offline Tarun Lalwani

  • Administrator
  • Hero Member
  • *****
  • Posts: 3025
    • KnowledgeInbox
Well these are now replaced with by Microsoft.XMLDOM. Look at below

http://msdn.microsoft.com/en-us/library/aa468547.aspx
Regards,
Tarun
KnowledgeInbox Administrator

KnowledgeInbox" style="border:0

Offline claudiozhang

  • Jr. Member
  • **
  • Posts: 60
Well these are now replaced with by Microsoft.XMLDOM. Look at below

http://msdn.microsoft.com/en-us/library/aa468547.aspx

That is the page I found.
I found  Microsoft.XMLDOM and MSXML.DOMDocument are all OK.
compatibility is Good.
Claudio Zhang
MSN: claudiozhang@hotmail.com