xsl-list
[Top] [All Lists]

RE: merging xmls

2002-09-10 10:22:10
I don't understand the de-duplication requirement. Your specimen output
contains a copy of each <univ> element and each <university> element
from each of the three source files. This doesn't tie in with what you
say about needing to remove duplicates.

Removing duplicates across multiple documents is a bit tricky: neither
of the standard XSLT 1.0 grouping techniques handles it directly, so you
need to build the composite document as a temporary tree and then do any
grouping that's needed. In XSLT 2.0 you can do it in one pass using
<xsl:for-each-group>.

The solution without duplicate elimination is easy:

<?xml version="1.0"?>
<university-records
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
     xsl:version="1.0">
      <xsl:variable name="docs" 
 
select="document('1.xml')|document('2.xml')|document('3.xml')"/>
        <univ-ids>
        <xsl:copy-of select="$docs//univ-ids/*"/>
        </univ-ids>
        <university-results>
        <xsl:copy-of select="$docs//university-results/*"/>
        </university-results>
</university-records>

In XSLT 2.0 you can add duplicate elimination like this:

<?xml version="1.0"?>
<university-records
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
     xsl:version="1.0">
      <xsl:variable name="docs" 
 
select="document('1.xml')|document('2.xml')|document('3.xml')"/>
        <univ-ids>
        <xsl:for-each-group select="$docs//univ-ids/*" group-by="@id">
          <xsl:copy-of select="."/>
        </xsl:for-each-group>
        </univ-ids>
        <university-results>
        <xsl:for-each-group select="$docs//university-results/*"
                            group-by="@univ-id">
          <xsl:copy-of select="."/>
        </xsl:for-each-group>          
        </university-results>
</university-records>

Michael Kay
Software AG
home: Michael(_dot_)H(_dot_)Kay(_at_)ntlworld(_dot_)com
work: Michael(_dot_)Kay(_at_)softwareag(_dot_)com 


-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Laura Jenkins
Sent: 10 September 2002 17:41
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] merging xmls


i have got a fairly conplicated problem ( atleast for me :( )
i have got 3 xml files that contains university result data 
from 3 different 
regions.and i have to merge them into one xml with all the 
data from 3 xmls. 
The resultant XML should have the same structure as 
individual XMLs.. for example,
xml1:
<?xml version="1.0"?>
<university-records>
      <univ-ids>
              <univ id = "KSU">
                      <name>Kansas State University</name>
                      <location>Kansas<location>
              </univ>
              <univ id = "FAU">
                      <name>Florida Atlantic University</name>
                      <location>Florida<location>
              </univ>
              <univ id = "MSU">
                      <name> Mississipi State University</name>
                      <location> Mississipi <location>
              </univ>
              <univ id = "OSU">
                      <name>Ohio State University</name>
                      <location> Ohio <location>
              </univ>
      </univ-ids>
      <university-results>
              <university univ-id = "KSU">100%</university>
              <university univ-id = "MSU">90%</university>
              <university univ-id = "FAU">80%</university>
      </university-results>
</university-records>

xml2:
<?xml version="1.0"?>
<university-records>
      <univ-ids>
              <univ id = "OSU">
                      <name> Ohio State University</name>
                      <location> Ohio <location>
              </univ>
              <univ id = "WSU">
                      <name> Wisconsin state University</name>
                      <location> Wisconsin <location>
              </univ>
              <univ id = "RPI">
                      <name> Rensellar polytechnic Institute </name>
                      <location> New Jersey <location>
              </univ>
              <univ id = "MSU">
                      <name> Mississipi State University</name>
                      <location> Mississipi  <location>
              </univ>
      </univ-ids>
      <university-results>
              <university univ-id = "OSU">70%</university>
              <university univ-id = "WSU">100%</university>
              <university univ-id = "RPI">100%</university>
      </university-results>
</university-records>
xml3:
<?xml version="1.0"?>
<university-records>
      <univ-ids>
              <univ id = "NSU">
                      <name> Newyork State University</name>
                      <location> Newyork <location>
              </univ>
              <univ id = "BU">
                      <name> Belmont University</name>
                      <location> Belmont <location>
              </univ>
              <univ id = "WSU">
                      <name>Wisconsin state University</name>
                      <location> Wisconsin <location>
              </univ>
              <univ id = "BCM">
                      <name> Berklee College of Music</name>
                      <location> Berklee <location>
              </univ>
      </univ-ids>
      <university-results>
              <university univ-id = "NU">70%</university>
              <university univ-id = "BU">60%</university>
              <university univ-id = "BCM">100%</university>
      </university-results>
</university-records>


i want the resultant xml to be ...

<university-records>
      <univ-ids>

              <univ id = "KSU">
                      <name>Kansas State University</name>
                      <location>Kansas<location>
              </univ>
              <univ id = "FAU">
                      <name>Florida Atlantic University</name>
                      <location>Florida<location>
              </univ>
              <univ id = "MSU">
                      <name> Mississipi State University</name>
                      <location> Mississipi <location>
              </univ>
              <univ id = "OSU">
                      <name> Ohio State University</name>
                      <location> Ohio <location>
              </univ>
              <univ id = "OSU">
                      <name> Ohio State University</name>
                      <location> Ohio <location>
              </univ>
              <univ id = "WSU">
                      <name> Wisconsin state University</name>
                      <location> Wisconsin <location>
              </univ>
              <univ id = "RPI">
                      <name> Rensellar polytechnic Institute </name>
                      <location> New Jersey <location>
              </univ>
              <univ id = "MSU">
                      <name> Mississipi State University</name>
                      <location> Mississipi  <location>
              </univ>
              <univ id = "NSU">
                      <name> Newyork State University</name>
                      <location> Newyork <location>
              </univ>
              <univ id = "BU">
                      <name> Belmont University</name>
                      <location> Belmont <location>
              </univ>
              <univ id = "WSU">
                      <name>Wisconsin state University</name>
                      <location> Wisconsin <location>
              </univ>
              <univ id = "BCM">
                      <name> Berklee College of Music</name>
                      <location> Berklee <location>
              </univ>

      </univ-ids>
      <university-results>
              <university univ-id = "NU">70%</university>
              <university univ-id = "BU">60%</university>
              <university univ-id = "BCM">100%</university>
              <university univ-id = "OSU">70%</university>
              <university univ-id = "WSU">100%</university>
              <university univ-id = "RPI">100%</university>
              <university univ-id = "KSU">100%</university>
              <university univ-id = "MSU">90%</university>
              <university univ-id = "FAU">80%</university>
      </university-results>
</university-records>


Things to be noticed here: The <univ-ids> in each of the xml 
files have some 
<univ-id> elements  which are there in other

xmls as well. for example the
                      <univ id = "MSU">
                      <name> Mississipi State University</name>
                      <location> Mississipi <location>
                      </univ>
which is in the xml2
similarly..
                      <univ id = "OSU">
                      <name> Ohio State University</name>
                      <location> Ohio <location>
                      </univ>
is there in both the xml files..

But The final XML should not reflect this.

Any Ideas as to how we can acheive this??

Thanks in advance..


_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>
  • merging xmls, Laura Jenkins
    • RE: merging xmls, Michael Kay <=