1

I am trying to map parts of the following source structure that has two sets of properties - one flat and one looped:

Source Document

<root>
  <flat>
    <prop1>foo</prop1>
    <prop2>bar</prop2>
    ...
  </flat>
  <loop>
    <prop>
      <qual>propA</qual>
      <data>baz</data>
      <more>blah</more>
    </prop>
    <prop>
      <qual>propB</qual>
      <data>qux</data>
      <more>bhal</more>
    </prop>
    ...
  </loop>
</root>

Specifically, the flat part is the PO1 segment of an X12 850 EDI document, and the looping properties are the subsequent REF segments.

These should be mapped to a looping destination structure of key-value pairs that looks like this:

Destination Document

<root>
  <props>
    <prop>
      <name>prop1</name>
      <value>foo</value>
    </prop>
    <prop>
      <name>propA</name>
      <value>baz</value>
    </prop>
  </props>
</root>

I would like to map only some of the values, depending on the property name.

What I've Tried

I have successfully mapped the flat portion to the destination using a table looping functoid and two table extractor functoids:

Flat properties mapped to options

I have also successfully mapped the looping portion to the destination using a looping functoid and some equality checks to select only certain qual values:

Looped properties mapped to options

When I attempt to include both of these mappings at the same time, the map succeeds, but doesn't generate the combined output.

The Question

How I can I map both sections of the source document to the same looping section in the destination document?

Update 1

Turns out I had oversimplified the problem; the flat group of properties actually contains the property name in one node and the value in another node. This is what they actually look like:

<flat>
  <name1>prop1</name1>
  <value1>foo</value1>
  <name2>prop2</name2>
  <value2>bar</value2>
  ...
</flat>

The concept of @Dijkgraaf's answer still works with this change if you use a Value Mapping (Flattening) functoid to get the property name from the correct location.

Jens Ehrich
  • 573
  • 1
  • 6
  • 19
  • Can you share a sample map with what you have so far? – Dijkgraaf Jun 30 '20 at 20:34
  • @Dijkgraaf I've updated the question with screen-shots of the relevant map portions. These were both taken from the combined map which is not working at the moment, but if I remove either one the other works. LMK if there's any other details I can provide. – Jens Ehrich Jun 30 '20 at 21:14

1 Answers1

1

Usually the only way to solve this is with either

  • Inline Custom XSLT via the Scripting Functoid
  • Custom XSLT setting Custom XSLT Path for the whole map
  • Having an intermediate schema that contains two Option nodes and having two maps. The first that maps the flat structure to one node and the looping to the second. Then a second map that loops across both and maps to to the same node.
  • In your case however, you need to have both (prop1,prop2,..) and the looping prop linked to the same looping functoid, and linking to the name and value and setting the link properties on the links from prop1,prop2 etc. to Copy name instead of value.

enter image description here enter image description here

With your sample input that gives

<root>
    <props>
        <prop>
            <name>prop1</name>
            <value>foo</value>
        </prop>
        <prop>
            <name>prop2</name>
            <value>bar</value>
        </prop>
        <prop>
            <name>propA</name>
            <value>baz</value>
        </prop>
        <prop>
            <name>propB</name>
            <value>qux</value>
        </prop>
    </props>
</root>
Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
  • Thank you, this solves the question that I asked perfectly. Unfortunately, I asked the wrong question. I had oversimplified the source document structure a bit. I have updated my question accordingly. – Jens Ehrich Jul 01 '20 at 14:29
  • I've managed to pull the property name from a different node using a Value Mapping (Flattening) functoid, triggered by a Logical Existence functoid on the node that contains the property value. – Jens Ehrich Jul 01 '20 at 15:37
  • Hi @JensEhrich Changing a question after it has received an answer that then invalidate the answer is frowned upon in StackOverflow. In that scenario you are sometimes better off asking a new question which better asks the question and linking to the original Q&A if it relevant. In this case I think the answer still is fundamentally correct, in that you have to link both sets to a single looping functoid, but the mapping for the flat structure is not as you have pointed out. – Dijkgraaf Jul 01 '20 at 21:45
  • Good point, I will revert the question back to the original structure, and keep the updates at the end for anyone in a similar situation. Regardless, your answer solves the problem in either scenario. Thanks again. – Jens Ehrich Jul 02 '20 at 03:44
  • I reverted the question to the original XML structure to keep this answer 100% valid. I moved the actual structure into the update section instead of creating a new question as I think it would be considered a duplicate. – Jens Ehrich Jul 02 '20 at 14:53