XSLT Union of two input xml documents [closed]

喜欢而已 提交于 2019-12-24 02:22:33

问题


I want to merge two xml documents.

  1. $input(Doc A) contains all the possible elements.
  2. Main Source(doc B) may or may not contain all the elements
  3. Doc B contains repeatable elements.
  4. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!