Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1075327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:15:24+00:00 2026-05-16T21:15:24+00:00

CURRENT XML: <?xml version=1.0?> <form1> <page1> <first_name></first_name> <last_name></last_name> . . </page1> <page2> <address></address> <phone_number></phone_number>

  • 0

CURRENT XML:

<?xml version="1.0"?>

<form1>
   <page1>
      <first_name></first_name>
      <last_name></last_name>
      .
      .
   </page1>
   <page2>
      <address></address>
      <phone_number></phone_number>
      .
      .
   </page2>
   <page3>
      <company_name></company_name>
      <job_title></job_title>
      .
      .
   </page3>
</form1>

DESIRED XML –
i want to merge all child elements and rename the parent:

<?xml version="1.0"?>

<form>
   <page>
      <first_name></first_name>
      <last_name></last_name>
      .
      .
      <address></address>
      <phone_number></phone_number>
      .
      .
      <company_name></company_name>
      <job_title></job_title>
      .
      .
   </page>
</form>

then, since i have thousands of XML files with some unknown elements, i want to find all of them before bulk importing the XML into Access database, because any new elements in subsequent files will be dropped if they are not defined in the schema.

not all child elements are known.
not all file names are known.

so, how can i check all files for all elements, fill the Access table with them all, then bulk import all the XML records to fit into the desired schema as shown above?

EDIT:

ok, i see – there are no attributes.
what i meant was all child elements.
thanks for pointing that out Oded, I updated the question with corrections.

this is the VBA code I am using in Access for bulk importing the files:

 Private Sub cmdImport_Click()
 Dim strFile As String 'Filename
 Dim strFileList() As String 'File Array
 Dim intFile As Integer 'File Number
 Dim strPath As String ' Path to file folder

 strPath = "C:\Users\Main\Desktop\XML-files"
 strFile = Dir(strPath & "*.XML")

 While strFile <> ""
      'add files to the list
     intFile = intFile + 1
     ReDim Preserve strFileList(1 To intFile)
     strFileList(intFile) = strFile
     strFile = Dir()
 Wend
 'see if any files were found
 If intFile = 0 Then
     MsgBox "No files found"
     Exit Sub
 End If

 'cycle through the list of files
 For intFile = 1 To UBound(strFileList)
     Application.ImportXML strPath & strFileList(intFile), acAppendData

 Next intFile
MsgBox "Import Completed"

End Sub

i can use the stylesheet to transform the XML as such:

  For intFile = 1 To UBound(strFileList)
     Application.TransformXML strPath & strFileList(intFile), _
     "C:\Users\Main\Desktop\stylesheet2.xslt", _
     "C:\Users\Main\Desktop\temp.xml", True
     Application.ImportXML "C:\Users\Main\Desktop\temp.xml", acAppendData
   Next intFile

 MsgBox "Import Completed"
End Sub

however, it does not merge all the file elements into one table. am i missing something?
do i need to save a variable list? or create some attribute ids?

EDIT: From comments

my file names are 1.xml, 2.xml, 3.xml,
4.xml, etc. But like i said have thousands

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:15:25+00:00Added an answer on May 16, 2026 at 9:15 pm

    Suppose this input documents:

    1.xml

    <form1>
       <page1>
            <first_name>D</first_name>
            <last_name>E</last_name>
       </page1>
       <page2>
            <address>F</address>
            <phone_number>1</phone_number>
       </page2>
       <page3>
            <company_name>G</company_name>
       </page3>
    </form1>
    

    2.xml

    <form2>
       <page1>
            <first_name>A</first_name>
       </page1>
       <page2>
            <address>B</address>
       </page2>
       <page3>
            <company_name>C</company_name>
            <job_title>H</job_title>
       </page3>
    </form2>
    

    This stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="kElementByName" match="/*/*/*" use="name()"/>
        <xsl:param name="pMaxFileNumber" select="2"/>
        <xsl:template match="/">
            <xsl:variable name="vFieldsNames">
                <xsl:call-template name="names">
                    <xsl:with-param name="pFrom" select="1"/>
                    <xsl:with-param name="pTo" select="$pMaxFileNumber"/>
                    <xsl:with-param name="pFieldsNames" select="'|'"/>
                </xsl:call-template>
            </xsl:variable>
            <form>
                <xsl:call-template name="merge">
                    <xsl:with-param name="pFrom" select="1"/>
                    <xsl:with-param name="pTo" select="$pMaxFileNumber"/>
                    <xsl:with-param name="pFieldsNames" select="$vFieldsNames"/>
                </xsl:call-template>
            </form>
        </xsl:template>
        <xsl:template name="names">
            <xsl:param name="pFrom"/>
            <xsl:param name="pTo"/>
            <xsl:param name="pFieldsNames"/>
            <xsl:choose>
                <xsl:when test="$pFrom = $pTo">
                    <xsl:value-of select="$pFieldsNames"/>
                    <xsl:apply-templates
                         select="document(concat($pFrom,'.xml'),/)/*/*/*
                                           [count(.|key('kElementByName',
                                                        name())[1])=1]
                                           [not(contains($pFieldsNames,
                                                         concat('|',name(),'|')))]"
                         mode="names"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:variable name="vNewTop"
                                  select="floor(($pTo - $pFrom) div 2) + $pFrom"/>
                    <xsl:variable name="vNewFieldsNames">
                        <xsl:call-template name="names">
                            <xsl:with-param name="pFrom" select="$pFrom"/>
                            <xsl:with-param name="pTo" select="$vNewTop"/>
                            <xsl:with-param name="pFieldsNames"
                                            select="$pFieldsNames"/>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:call-template name="names">
                        <xsl:with-param name="pFrom" select="$vNewTop + 1"/>
                        <xsl:with-param name="pTo" select="$pTo"/>
                        <xsl:with-param name="pFieldsNames"
                                        select="$vNewFieldsNames"/>
                    </xsl:call-template>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        <xsl:template name="merge">
            <xsl:param name="pFrom"/>
            <xsl:param name="pTo"/>
            <xsl:param name="pFieldsNames"/>
            <xsl:choose>
                <xsl:when test="$pFrom = $pTo">
                    <page>
                        <xsl:apply-templates
                         select="document(concat($pFrom,'.xml'),/)/*/*[1]/*[1]">
                            <xsl:with-param name="pFieldsNames"
                                            select="$pFieldsNames"/>
                        </xsl:apply-templates>
                    </page>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:variable name="vNewTop"
                                  select="floor(($pTo - $pFrom) div 2) + $pFrom"/>
                    <xsl:call-template name="merge">
                        <xsl:with-param name="pFrom" select="$pFrom"/>
                        <xsl:with-param name="pTo" select="$vNewTop"/>
                        <xsl:with-param name="pFieldsNames" select="$pFieldsNames"/>
                    </xsl:call-template>
                    <xsl:call-template name="merge">
                        <xsl:with-param name="pFrom" select="$vNewTop + 1"/>
                        <xsl:with-param name="pTo" select="$pTo"/>
                        <xsl:with-param name="pFieldsNames" select="$pFieldsNames"/>
                    </xsl:call-template>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        <xsl:template match="/*/*">
            <xsl:param name="pFieldsNames"/>
            <xsl:apply-templates select="*[1]">
                <xsl:with-param name="pFieldsNames" select="$pFieldsNames"/>
            </xsl:apply-templates>
        </xsl:template>
        <xsl:template match="/*/*/*" name="copy">
            <xsl:param name="pFieldsNames"/>
            <xsl:copy>
                <xsl:value-of select="."/>
            </xsl:copy>
            <xsl:variable name="vName" select="concat('|',name(),'|')"/>
            <xsl:apply-templates select="following::*[1]">
                <xsl:with-param name="pFieldsNames"
                                select="concat(substring-before($pFieldsNames,
                                                                $vName),
                                               '|',
                                               substring-after($pFieldsNames,
                                                               $vName))"/>
            </xsl:apply-templates>
        </xsl:template>
        <xsl:template match="/*/*[last()]/*[last()]">
            <xsl:param name="pFieldsNames"/>
            <xsl:call-template name="copy"/>
            <xsl:variable name="vName" select="concat('|',name(),'|')"/>
            <xsl:call-template name="empty">
                <xsl:with-param name="pFieldsNames"
                                select="substring(
                                          concat(substring-before($pFieldsNames,
                                                                  $vName),
                                                 '|',
                                                 substring-after($pFieldsNames,
                                                                 $vName)),
                                          2)"/>
            </xsl:call-template>
        </xsl:template>
        <xsl:template match="/*/*/*" mode="names">
            <xsl:value-of select="concat(name(),'|')"/>
        </xsl:template>
        <xsl:template name="empty">
            <xsl:param name="pFieldsNames"/>
            <xsl:if test="$pFieldsNames!=''">
                <xsl:element name="{substring-before($pFieldsNames,'|')}"/>
                <xsl:call-template name="empty">
                    <xsl:with-param name="pFieldsNames"
                               select="substring-after($pFieldsNames,'|')"/>
                </xsl:call-template>
            </xsl:if>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <form>
        <page>
            <first_name>D</first_name>
            <last_name>E</last_name>
            <address>F</address>
            <phone_number>1</phone_number>
            <company_name>G</company_name>
            <job_title />
        </page>
        <page>
            <first_name>A</first_name>
            <address>B</address>
            <company_name>C</company_name>
            <job_title>H</job_title>
            <last_name />
            <phone_number />
        </page>
    </form>
    

    Note: If this blows up your memory, then you need to split this in two stylesheets: first, output the names; second, merge. If you can’t pass param with Application.TransformXML, then the max number of files is fixed. Also, there must not be any hole: if max number of files is 3, 2.xml can’t be missed (this is because fn:document throws an error)

    EDIT: For a two pass transformation.

    This stylesheet with any input (not used):

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:param name="pMaxFileNumber" select="2"/>
        <xsl:template match="/">
            <form>
                <xsl:call-template name="copy">
                    <xsl:with-param name="pFrom" select="1"/>
                    <xsl:with-param name="pTo" select="$pMaxFileNumber"/>
                </xsl:call-template>
            </form>
        </xsl:template>
        <xsl:template name="copy">
            <xsl:param name="pFrom"/>
            <xsl:param name="pTo"/>
            <xsl:choose>
                <xsl:when test="$pFrom = $pTo">
                    <page>
                        <xsl:copy-of 
                         select="document(concat($pFrom,'.xml'),/)/*/*/*"/>
                    </page>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:variable name="vMiddle"
                          select="floor(($pTo - $pFrom) div 2) + $pFrom"/>
                    <xsl:call-template name="copy">
                        <xsl:with-param name="pFrom" select="$pFrom"/>
                        <xsl:with-param name="pTo" select="$vMiddle"/>
                    </xsl:call-template>
                    <xsl:call-template name="copy">
                        <xsl:with-param name="pFrom" select="$vMiddle + 1"/>
                        <xsl:with-param name="pTo" select="$pTo"/>
                    </xsl:call-template>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <form>
        <page>
            <first_name>D</first_name>
            <last_name>E</last_name>
            <address>F</address>
            <phone_number>1</phone_number>
            <company_name>G</company_name>
        </page>
        <page>
            <first_name>A</first_name>
            <address>B</address>
            <company_name>C</company_name>
            <job_title>H</job_title>
        </page>
    </form>
    

    And this stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="kElementByName" match="/*/*/*" use="name()"/>
        <xsl:variable name="vElements"
                      select="/*/*/*[count(.|key('kElementByName',name())[1])=1]"/>
        <xsl:template match="form">
            <xsl:copy>
                <xsl:apply-templates/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="page">
            <xsl:copy>
                <xsl:apply-templates select="$vElements">
                    <xsl:with-param name="pContext" select="."/>
                </xsl:apply-templates>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="/*/*/*">
            <xsl:param name="pContext"/>
            <xsl:element name="{name()}">
                <xsl:value-of select="$pContext/*[name()=name(current())]"/>
            </xsl:element>
        </xsl:template>
    </xsl:stylesheet>
    

    With previus output as input, result:

    <form>
        <page>
            <first_name>D</first_name>
            <last_name>E</last_name>
            <address>F</address>
            <phone_number>1</phone_number>
            <company_name>G</company_name>
            <job_title></job_title>
        </page>
        <page>
            <first_name>A</first_name>
            <last_name></last_name>
            <address>B</address>
            <phone_number></phone_number>
            <company_name>C</company_name>
            <job_title>H</job_title>
        </page>
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Current Layout is <?xml version=1.0 encoding=utf-8?> <ScrollView android:id=@+id/scrMain android:layout_width=fill_parent android:layout_height=match_parent android:layout_gravity=top android:fillViewport=true >
I want to check a data version number in my XML and if the
hey guys i have a restful xml service where client passes current version of
How can I access current xml document uri in XSLT?
Is there a way to get the current xml data when we make our
My current LINQ query and example XML are below. What I'd like to do
I need my current script to include additional xml. This is the script in
My current setup using hibernate uses the hibernate.reveng.xml file to generate the various hbm.xml
At current i have an index page which shows values from an XML page
Given the following XML: <current> <login_name>jd</login_name> </current> <people> <person> <first>John</first> <last>Doe</last> <login_name>jd</login_name> </preson> <person>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.