Step 2: mapping

From: Gionni (ehigionni_at_katamail.com)
Date: 11/03/04


Date: 3 Nov 2021 08:45:49 -0800

Hello everyone,
   some days ago I posted about a xsd definition for a flat file.
Thank for your help, I have this xml assembled:
<Root>
   <Record>
       <CommonField1>
       <CommonField2>
       ...
       <ChoiceField>
          <SubRecord1>
            <SubRecord1Field1>
            <SubRecord1Field2>
          </SubRecord1>
          <SubRecord2>
          ...
       </ChoiceField>
    </Record>
</Root>

I have to map this into this schema:
<Root>
   <Record>
       <CommonFieldKey1>
       <CommonFieldKey2>
       ...
       <SubRecord1>
            <CommonFieldNonKey1>
            <CommonFieldNonKey1>
            <SubRecord1Field1>
            <SubRecord1Field2>
       </SubRecord1>
       <SubRecord2>
       ...
    </Record>
</Root>

Suppose some common fields work as primary key. This should compare
once in schema2. The records in schema1 with this key have to be
mapped in the same record in schema2. I think it is not clear, so I
hope an example could help (me).

Example.
First Instance XML
<Root>
    <Record>
      <A> 1 </A> (key)
      <B> 2 </B> (key)
      <C> 3 </C>
      <Sub1>
        <D> 4 </D>
      </Sub1>
    </Record>
    <Record>
      <A> 3 </A> (key)
      <B> 4 </B> (key)
      <C> 7 </C>
      <Sub2>
        <D> 8 </D>
      </Sub2>
    </Record>
    <Record>
      <A> 1 </A> (key)
      <B> 2 </B> (key)
      <C> 5 </C>
      <Sub2>
        <D> 6 </D>
      </Sub2>
    </Record>
</Root>

Mapped Instance
<Root>
   <Record>
       <A> 1 </A>
       <B> 4 </B>
       <Sub1>
          <C> 3 </C>
          <D> 4 </D>
       </Sub1>
       <Sub2>
          <C> 5 </C>
          <D> 6 </D>
       <Sub2>
    </Record>
   <Record>
       <A> 3 </A>
       <B> 4 </B>
       <Sub2>
          <C> 7 </C>
          <D> 8 </D>
       <Sub2>
    </Record>
</Root>

I hope a possible mapping exists... I tried to flatten the values of
key, but only the last (sometimes the first) value has returned.
If I could the key group by their values, I think the problem could be
solved.

Thanks for your help, I know it is a difficult question.

Cheers,
Gionni