Hi,
Firstly: Thanks for your help Phil - much appreciated!! :o)
Secondly, in the interests of completeness, here is the complete code:
VB Code:
Private Sub Command1_Click()
'Dim conn As New ADODB.Connection
'conn.ConnectionString = "Provider=Microsoft.Jet.OLE.3.51; Data Source=C:\Documents and Settings\User\My Documents\code\Visual Basic\
VB 6 and XML"
Dim xDom As New MSXML2.DOMDocument
Dim xXSLT As New MSXML2.DOMDocument
Dim xOutput As New MSXML2.DOMDocument
Dim strXML As String
Dim rsXML As New ADODB.Recordset
Dim sSQL As String, sConn As String
sSQL = "SELECT * From Cars"
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Cars.mdb"
rsXML.Open sSQL, sConn
'Save Recordset directly into a DOM tree.
rsXML.Save xDom, adPersistXML
'Destroy Recordset
rsXML.Close
Set rsXML = Nothing
'load xslt
xXSLT.async = False
'Save RS_XML
xDom.Save ("C:\Cars.xml")
'Load XSLT file
xXSLT.Load "C:\remove.xslt"
'transform RS_XML
strXML = xDom.transformNode(xXSLT)
'load trnsformed XML
xOutput.loadXML (strXML)
'Save transformed XML
xOutput.Save ("C:\Cars_transformed.xml")
'Confirm Process is complete
MsgBox ("XML extracted and Turned into a file")
End Sub
Here is the XSLT which I used to transform the ADODB.Recordset XML:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<xsl:import href="copy.xslt"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="*[z:row]">
<Cars>
<xsl:apply-templates/>
</Cars>
</xsl:template>
<xsl:template match="s:Schema">
<xsl:for-each select="z:row">
<xsl:apply-templates />
</xsl:for-each>
</xsl:template>
<xsl:template match="z:row/@*">
<xsl:element name="{name( )}">
<xsl:value-of select="." />
</xsl:element>
</xsl:template>
<xsl:template match="z:row">
<xsl:element name="Cars">
<xsl:apply-templates select="@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
And here is the copy.xslt file:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node( ) | @*">
<xsl:copy>
<xsl:apply-templates select="@* | node( )"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Hope this helps someone,
Morris