[RESOLVED] Adding XSL style to XML document.
I'm using this code to create a document.
Code:
Public Sub CreateXMLDoc(sFile As String)
Set objDoc = New MSXML2.DOMDocument
Set objNode = objDoc.createElement("report")
Set objAttrib = objDoc.createAttribute("projectname")
objAttrib.Value = sFile
objNode.Attributes.setNamedItem objAttrib
objDoc.appendChild objNode
End Sub
I'm later adding some nodes and then saving the file. Below is a very stripped down version of one of the files.
Code:
<?xml version="1.0"?>
<report projectname="C:\Documents and Settings\mthesing\Desktop\Copy of RTP Code Drop 03-20-07">
<file name="netlinks.asp" id="701">
<totallines>44</totallines>
<codelines>38</codelines>
<commentlines>6</commentlines>
<created>4/10/2007 11:42:46 AM</created>
<modified>1/18/2007 2:54:37 PM</modified>
<filetype>Active Server Document</filetype>
<size>1.03 KB</size>
</file>
<file name="stylesheet.asp" id="702">
<totallines>1</totallines>
<codelines>1</codelines>
<commentlines>0</commentlines>
<created>4/10/2007 11:42:46 AM</created>
<modified>5/26/2006 11:05:17 AM</modified>
<filetype>Active Server Document</filetype>
<size>0.08 KB</size>
</file>
<summary>
<totaldirectories>23</totaldirectories>
<totallines>99,838</totallines>
<totalcodelines>91,773</totalcodelines>
<totalcommentlines>8,065</totalcommentlines>
</summary>
</report>
What I would like to do is assign an XSL stylesheet the the XML through code like the example below
Code:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="aspreport.xsl"?>
<report projectname="C:\Documents and Settings\mthesing\Desktop\Copy of RTP Code Drop 03-20-07">
<file name="netlinks.asp" id="701">
<totallines>44</totallines>
<codelines>38</codelines>
<commentlines>6</commentlines>
<created>4/10/2007 11:42:46 AM</created>
<modified>1/18/2007 2:54:37 PM</modified>
<filetype>Active Server Document</filetype>
<size>1.03 KB</size>
</file>
<file name="stylesheet.asp" id="703">
<totallines>1</totallines>
<codelines>1</codelines>
<commentlines>0</commentlines>
<created>4/10/2007 11:42:46 AM</created>
<modified>5/26/2006 11:05:17 AM</modified>
<filetype>Active Server Document</filetype>
<size>0.08 KB</size>
</file>
<summary>
<totaldirectories>23</totaldirectories>
<totallines>105,111</totallines>
<totalcodelines>97,046</totalcodelines>
<totalcommentlines>8,065</totalcommentlines>
</summary>
</report>
How do I do this?
Re: Adding XSL style to XML document.
I figured it out. Here is what seems to work for me
Code:
Public Sub CreateXMLDoc(sFile As String)
Dim strXSL As String
strXSL = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\")
strXSL = strXSL & "report.xsl"
Set objDoc = New MSXML2.DOMDocument
Set objNode = objDoc.createProcessingInstruction("xml-stylesheet", "type='text/xsl' href='" & strXSL & "'")
objDoc.appendChild objNode
Set objNode = objDoc.createElement("report")
Set objAttrib = objDoc.createAttribute("projectname")
objAttrib.Value = sFile
objNode.Attributes.setNamedItem objAttrib
objDoc.appendChild objNode
End Sub