I'm importing some XML documents (created in InfoPath) into MS Access using an XSLT. It's working fine except for one issue. Many of the nested elements (child tables) contain multiple values, but the import is only bringing in one record.
In this sample, there are 3 UnsafeProcedures, but only the first one gets imported to the tblUnsafeProcedures table.
XML
<my:myFields
<my:DateOfIncident>2017-01-10T16:00:00</my:DateOfIncident>
<my:IncidentID>20170125T1452</my:IncidentID>
<my:IncidentLocation>Mayberry</my:IncidentLocation>
<my:InvolvedPerson>Joe Blow</my:InvolvedPerson>
<my:tblUnsafeProcedures>
<my:IncidentID>20170125T1452</my:IncidentID>
<my:UnsafeProcedures>Other (explain)</my:UnsafeProcedures>
<my:UnsafeProcedures>Unsafe Lifting</my:UnsafeProcedures>
<my:UnsafeProcedures>Using equipment unsafely</my:UnsafeProcedures>
</my:tblUnsafeProcedures>
</my:myFields>
Here is the VBA that runs the import
Public Sub TransformAndImportMultipleXMLs()
On Error GoTo Err_Trap
Dim strFile As String, strPath As String
Dim xmlDoc As New MSXML2.DOMDocument60
Dim xslDoc As New MSXML2.DOMDocument60
Dim newDoc As New MSXML2.DOMDocument60strPath = "y:\"
strFile = Dir(strPath & "*.xml")
xslDoc.async = False
xslDoc.validateOnParse = False
xslDoc.resolveExternals = False
xslDoc.Load "C:\JSTAdb\IncidentID.xslt"
While strFile <> ""
' REINITIALIZE DOM OBJECTS
Set xmlDoc = New MSXML2.DOMDocument60
Set newDoc = New MSXML2.DOMDocument60
' LOAD XML SOURCE
xmlDoc.Load strPath & strFile
' TRANSFORM SOURCE
xmlDoc.transformNodeToObject xslDoc, newDoc
newDoc.Save "C:\JSTAdb\temp.xml"
' APPEND TO TABLES
Application.ImportXML "C:\JSTAdb\temp.xml", acAppendData
Call WaitFor(1) 'Wait for 1 second between imports
strFile = Dir()
Wend
' RELEASE DOM OBJECTS
Set xmlDoc = Nothing: Set xslDoc = Nothing: Set newDoc = Nothing
Err_Trap:
Debug.Print Error
Resume Next
End Sub
There must be a way to import all of these child elements. What am I missing?
XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2016-02-16T15:55:31"
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"
xml:lang="en-US">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="my:grpUnsafeWorkProcedures">
<my:tblUnsafeProcedures>
<my:IncidentID><xsl:value-of select="../my:IncidentID"/></my:IncidentID>
<xsl:apply-templates select="@*|node()"/>
</my:tblUnsafeProcedures>
</xsl:template>
</xsl:stylesheet>
Below is the original XML file before transformation. This is an InfoPath form. The UnsafeProcedures field is a multi-selection list box with 7 items to choose from. In this case, 3 items were chosen.
Original XML
<?xml version="1.0" encoding="utf-8"?>
<?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:INCIDENT-INVESTIGATION-REPORTS:-myXSD-2016-02-16T15-55-31" solutionVersion="1.0.0.1597" productVersion="15.0.0.0" PIVersion="1.0.0.0" href="http://sharepoint.acme.com/sites/safety/RecAndNonRec/Forms/template.xsn"?>
<?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.4"?>
<?mso-infoPath-file-attachment-present?>
<my:myFields my:Why4="Joe messed up" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls" xmlns:ma="http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes" xmlns:d="http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields" xmlns:q="http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:dms="http://schemas.microsoft.com/office/2009/documentManagement/types" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2016-02-16T15:55:31" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-US">
<my:DateOfIncident>2017-01-10T16:00:00</my:DateOfIncident>
<my:IncidentLocation>Maberry</my:IncidentLocation>
<my:InvolvedPerson>Joe Blow</my:InvolvedPerson>
<my:grpUnsafeWorkProcedures>
<my:UnsafeProcedures></my:UnsafeProcedures><my:UnsafeProcedures>Other (explain)</my:UnsafeProcedures><my:UnsafeProcedures>Unsafe Lifting</my:UnsafeProcedures><my:UnsafeProcedures>Using equipment unsafely</my:UnsafeProcedures>
</my:grpUnsafeWorkProcedures>
<my:IncidentID>20170125T1452</my:IncidentID>
</my:myFields>