Create HTML from XML and XSL

Usually, if you defined within an XML file that it needs an XSL to display the Internet will transform Exporer 5.5 based XML and XSL to display the results in your browser. In the case that if you View Source of the webpage you just read the XML source only. May be wondering why you do not see the HTML source as a result of the process Tranform XML.
In VB6 program presented here you will find how to use the DOM (Document Object Model) of MSXML to do the work equivalent to IE 5.5 and save the results into a webpage HTML. This webpage can be display, independent of XML, in any WebBrowser nao.That, the MSXML ActiveX VB6 we used to when IE 5.5 is the Project | Reference "Microsoft XML, v3.0 ' .

Sample program

You can download sample programs to see how a very simple programming.

The main part of the program are in Sub Form_Load as listed below. You can view the listing and explanation of how to transform Library.xml based Library.xsl in my XML, computing the core technology in the future.
Private Sub Form_Load()
Dim HTMLCode As String
' Need to Project | References "Microsoft XML, v3.0" to use DOM
Dim myXMLDoc As New MSXML2.DOMDocument30
Dim myXSLDoc As New MSXML2.DOMDocument30
' Need to Project | References "Microsoft Script Runtime" to use
' FileSystemObject and TextStream
Dim Fs As FileSystemObject
Dim ts As TextStream
' Display the XML file in a listbox
PopulateListBoxFromFile LstXML, "Library.xml", False
' Display the XSL file in a listbox
PopulateListBoxFromFile lstXSL, "Library.xsl", False
' Load the XML file
myXMLDoc.Load App.Path & "\Library.xml"
' Load the XSL file
myXSLDoc.Load App.Path & "\Library.xsl"
' Transform XML by XSL to give HTML
HTMLCode = myXMLDoc.transformNode(myXSLDoc)
' Now Write the resultant HTML to file
' Create a FileSystem Object
Set Fs = CreateObject("Scripting.FileSystemObject")
' Open TextStream for Output
Set TS = Fs.OpenTextFile(App.Path & "\Library.htm", ForWriting, False, TristateUseDefault)
TS.Write HTMLCode ' Write the whole HTML string in one stroke
TS.Close ' Close the Text Stream
Set Fs = Nothing ' Dispose FileSystem Object
' Display the HTML file in a listbox
PopulateListBoxFromFile lstHTML, "Library.htm", False
End Sub 


Post a Comment