XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old July 9th, 2003, 02:25 AM
Wizard2003's Avatar
Wizard2003 Wizard2003 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 206 Wizard2003 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 29 m 24 sec
Reputation Power: 6
Merge two xml files

Hi all,

I'm trying to merge two xml files but it doesn't work properly.
My aim is to get an xml file like:
Code:
<root>
  <node>
      <node>
        <node text="In attribute 1.1.1 of file 1" text2="In attribute 1.1.1 of file 2">
        </node>
      </node>
      <node>
        <node text="In attribute 1.2.1 of file 1" text2="In attribute 1.2.1 of file 2">
        </node>
      </node>
  </node>
  <node>
      <node>
        <node>
        </node>
      </node>
  </node>
  <node>
      <node>
        <node>
        </node>
      </node>
  </node>
</root>


What I would do is to add each text attribute of a node an other text attribute of the corresponding node in the other file.
I dont know have deep the tree is so that I can not give the path absolutly (like /path/path).

The two xml files:
file1:

Code:
<root>
  <node>
      <node>
        <node text="In attribute 1.1.1 of file 1">
        </node>
      </node>
      <node>
        <node text="In attribute 1.2.1 of file 1">
        </node>
      </node>
  </node>
  <node>
      <node>
        <node>
        </node>
      </node>
  </node>
  <node>
      <node>
        <node>
        </node>
      </node>
  </node>
</root>


and file2:

Code:
<root>
  <node>
      <node>
        <node text="In attribute 1.1.1 of file 2">
        </node>
      </node>
      <node>
        <node text="In attribute 1.2.1 of file 2">
        </node>
      </node>
  </node>
  <node>
      <node>
        <node>
        </node>
      </node>
  </node>
  <node>
      <node>
        <node>
        </node>
      </node>
  </node>
</root>


This is my xsl file:

Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:variable name="baum1" select="document('baum1.xml')" />
  <xsl:variable name="baum2" select="document('baum2.xml')" />

  <xsl:output method="xml" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="root">
    <root>
      <xsl:apply-templates />
    </root>
  </xsl:template>

  <xsl:template match="node">
    <xsl:variable name="thisindex"  select="count(preceding::node())"/>
    <xsl:if test="@text">
      <node text ="{@text}"
            text2="{document('baum2_1.xml')//descendant::node[$thisindex]/@text}"
            index="{$thisindex}"/>
    </xsl:if>
    <xsl:if test="not(@text)">
      <node>
        <xsl:apply-templates />
      </node>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>


Any ideas?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Merge two xml files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway