• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 115
  • Last Modified:

Merge 2 XML Files together

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
Steven O'Neill
Asked:
Steven O'Neill
  • 3
  • 2
1 Solution
 
Geert BormansCommented:
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
 
Steven O'NeillSolutions ArchitectAuthor Commented:
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
 
Geert BormansCommented:
   <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
 
Steven O'NeillSolutions ArchitectAuthor Commented:
Absolutely sweet as always Geert :)
0
 
Geert BormansCommented:
welcome
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now