Solved

Merge 2 XML Files together

Posted on 2016-08-24
5
40 Views
Last Modified: 2016-08-25
Quite some time ago I received a huge amount of help from Geert Bormans on merging an XML and XLS(X) file together...now I'm back with some alterations to the XML file which hopefully someone - Geert :) - is able to help with.

The original questions can be found here:

https://www.experts-exchange.com/questions/28691313/Merge-Excel-file-with-contents-of-XML-file.html
https://www.experts-exchange.com/questions/28691770/Merge-Excel-file-with-contents-of-XML-file-Part-2.html

Everything has been working great but the scanner being used to create the XML file isn't working now and the new machine cannot output in the same way unfortunately so the XML file is completely different.

Essentially the job is still the same - take 2 files, convert them to XML and merge them together. The conversion to XML is working perfectly fine but it's the last part I'm having issues with as the structure of the XML file is different from what we had originally.

The files attached should hopefully give enough of an idea what I need but basically we need to group sections of the C225-BOX-235A.XML file together (we did this with a field called CORRESPONDENCE in the previous files). This is still in the C225-BOX-235A.XML file and we need to group them together again but this is now held as IndexValue with the Label GJH - this is the part which I'm confused with as I'm not sure how to alter the XSL file to handle this as when I attempt to merge them together I don't get the results I expect unfortunately.

I'm assuming I'm not creating the xsl:for-each-group area correctly and the DESCRIPTION and FILE fields are incorrect as well (again these are in the XML file as:

DESCRIPTION should be <IndexValue><Label>GJH</Label<Value>CORRESPONDENCE</Value> - I need the value element of this as the DESCRIPTION
FILE should be the contents of FileName but I need the location stripped out and only need the filename which is after the last \ - so I'd be looking for 001 CORRESPONDENCE.PDF

Hope that all makes sense (no doubt it won't) but any help/assistance is always appreciated

Thanx as always
merge-files.xsl
C225-BOX-235A-Converted.xml
C225-BOX-235A.XML
0
Comment
Question by:Steven O'Neill
  • 3
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 41768667
Hi, I just checked both the old project and the new files.
It is all a bit vague and combersom

could you please simply post

A snippet of file 1
A snippet of file 2
and the expected result?

Thanks
0
 
LVL 2

Author Comment

by:Steven O'Neill
ID: 41768826
Hi Geert

Thanx for getting back so fast :)

I've attached a few files that hopefully give you an idea what it is we're attempting to accomplish.

  • File 1 (C225-BOX-235A.XML) is output from the scanner when the documents are scanned in;
  • File 2 (C225-BOX 235A-Converted.XML) is a converted XLS(X) file which we have run through a conversion process to make it XML (using Total Excel Converter);
  • File 3 (C225-BOX-235A.xml) is what should be output when both files are merged using the XSLT file (File 4 - merge-files.xsl)

We know the scanned documentation file will always be in an order (this is File 1 - C225-BOX-235A.XML). So we need to group File 1 (C225-BOX-235A.XML) using the CORRESPONDENCE field (although it's now shown as IndexValue in the XML file and we are looking to group these on the IndexValue with the Label = GJH and Value = CORRESPONDENCE). I tried to amend the XSLT file (File 4) that you provided by looking at <Documents> and grouping the <Document> together but this is where I've lost it as there are no fields like there was previously in the scanner XML file and it's using these IndexValue; Label and Value elements now.

Hopefully that makes a little more sense but if you need anything else then please let me know.

Thanx
C225-BOX-235A.XML
C225-BOX-235A-Converted.xml
C225-BOX-235A.xml
merge-files.xsl
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 41769244
   <xsl:template match="/">
        <xsl:apply-templates select=".//Documents"/>
    </xsl:template>
    
    <xsl:template match="Documents">
        <data-set>
            <xsl:for-each-group select="Document" group-starting-with="Document[IndexValues[IndexValue[Label ='GJH'][Value = 'CORRESPONDENCE']]]" >
                <xsl:variable name="pos" select="position()"/>
                <xsl:variable name="this-initial" select="$initial-file-data/record[position() = $pos]"/>
                <xsl:for-each select="current-group()">
                    <record>
                        <FORENAME><xsl:value-of select="$this-initial/Forename"/></FORENAME>
                        <SURNAME><xsl:value-of select="$this-initial/Surname"/></SURNAME>
                        <DOB><xsl:value-of select="$this-initial/DoB"/></DOB>
                        <CHI><xsl:value-of select="substring($this-initial/CHI, string-length($this-initial/CHI) - 9 +1)"/></CHI>
                        <COUNT><xsl:value-of select="PageCount"/></COUNT>
                        <FILE_DATE><xsl:value-of select="format-dateTime(current-dateTime(),'[Y0001].[M01].[D01] [H01]:[m01]:[s]')"/></FILE_DATE>
                        <EVENT_DATE><xsl:value-of select="format-dateTime(current-dateTime(),'[Y0001].[M01].[D01] [H01]:[m01]:[s]')"/></EVENT_DATE>
                        <FOLDER_ID>1</FOLDER_ID>
                        <DESCRIPTION><xsl:value-of select="IndexValues/IndexValue[Label ='GJH']/Value"/></DESCRIPTION>
                        <FILE><xsl:value-of select="tokenize(FileName, '[\\/]')[last()]"/></FILE>
                         </record>
                </xsl:for-each>
            </xsl:for-each-group>
        </data-set>
     </xsl:template>

Open in new window


will do most of it right
1
 
LVL 2

Author Closing Comment

by:Steven O'Neill
ID: 41769512
Absolutely sweet as always Geert :)
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 41769862
welcome
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now