troubleshooting Question

copy xml elements with matching names from another doc with slightly different structure

Avatar of FelineConspiracy
FelineConspiracy asked on
XML
10 Comments1 Solution187 ViewsLast Modified:
My requirement is to pre-populate an xml document A by copying matching xml elements from an existing document B.

I cannot introduce any new elements into A; I just want to bring in elements from B if there is already an element in A of the same name.

B's structure will be slightly different from A's. Both will be exactly three elements deep, with the same root, and one child whose name will vary. It's the common elements under that child that I want to copy. (There is an oddball document that doesn't match this three-layer pattern but I'm ignoring that for now.)


Document A

<enroll>
      <orp>
            <email></email>
            <zip></zip>
            <npi></npi>
      </orp>
</enroll>

Document B - I don't want <monkey> copied to A because A doesn't already have one:

<enroll>
      <phys>
            <email>p@z.g</email>
            <zip>11111</zip>
            <npi>0101010101</npi>
            <monkey></monkey>
      </phys>

</enroll>

The result should be

<enroll>
      <orp>
            <email>p@z.g</email>
            <zip>11111</zip>
            <npi>0101010101</npi>
      </orp>
</enroll>




I have a pretty good idea that xsl:copy is the tool, but... no idea how to do this. An xsl 1.0 solution would be best, we're on a pretty old platform and I'm not sure 2.0 is supported. Can anyone assist?
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)
Information Architect
Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros