问题
I want to merge two xml documents.
- $input(Doc A) contains all the possible elements.
- Main Source(doc B) may or may not contain all the elements
- Doc B contains repeatable elements.
- O/P should be a UNION of both documents.
$input (simplified)
<StudentData>
<Header>
<Info></Info>
</Header>
<Source>
<Sinfo></Sinfo>
</Source>
<Student>
<Fname></Fname>
<Mname></Mname>
<Lname></Lname>
<age></age>
<email></email>
<subject> <!-- Repeatable -->
<name></name>
<avg_marks></avg_marks>
</subject>
<Hobby> <!-- Repeatable -->
<name></name>
<desc></desc>
</Hobby>
</Student>
</StudentData>
Sample Source(Doc B)
<StudentData>
<Header>
<Info>This gives basic information</Info>
</Header>
<Student>
<Fname>Walter</Fname>
<Lname>White</Lname>
<age>56</age>
<email>whwhite@xyz.com</email>
<subject>
<name>MATHS</name>
<avg_marks>80</avg_marks>
</subject>
<subject>
<name>CHEMISTRY</name>
<avg_marks>100</avg_marks>
</subject>
<subject>
<name>PHYSICS</name>
<avg_marks>78</avg_marks>
</subject>
<Hobby>
<name>Reading</name>
</Hobby>
<Hobby>
<name>SOCCER</name>
</Hobby>
</Student>
</StudentData>
O/p
<StudentData>
<Header>
<Info>This gives basic information</Info>
</Header>
<Source> <!-- Added as empty tags as it is not present in Source -->
<Sinfo></Sinfo>
</Source>
<Student>
<Fname>Walter</Fname>
<Mname></Mname>
<Lname>White</Lname>
<age>56</age>
<email>whwhite@xyz.com</email>
<subject>
<name>MATHS</name>
<avg_marks>80</avg_marks>
</subject>
<subject>
<name>CHEMISTRY</name>
<avg_marks>100</avg_marks>
</subject>
<subject>
<name>PHYSICS</name>
<avg_marks>78</avg_marks>
</subject>
<Hobby>
<name>Reading</name>
<desc></desc>
</Hobby>
<Hobby>
<name>SOCCER</name>
<desc></desc>
</Hobby>
</Student>
</StudentData>
The o/p should contain empty tags if the source(doc B) does not contain that element.
- Clarification
I am using Oracle Service Bus. The Source(doc b) will be directly accessible. Doc A can be accessed with $input.
For example, Student Fname can be accessed by:
$input/StudentData/Student/Fname
Is there any simple way to do this? Thanks in advance.
来源:https://stackoverflow.com/questions/29722494/xslt-union-of-two-input-xml-documents