title: Conditional Mapping Inbound XML to JSON
body: <p>Using Dataweave, I'm trying to map inbound <code>XML</code> payload to conditionally map to <code>JSON</code> based on tag values. For example if <code>FieldValue.FieldName == “DueDate”</code> then map value of <code>FieldValue.Value</code> under the same parent <code>FieldValue</code> tag to <code>customfield_10659</code> and if <code>FieldValue.FieldName == “CommittedDate”</code> to <code>customfield_19029</code>. Similarly if value of <code>FieldValue.FieldName == "Importance"</code> then map value of <code>FieldValue.Value.Id.Value</code> to <code>customfield_38383</code></p>
  
  <p>==============</p>
  
  <p>Input XML:</p>
  
  <pre><code>&lt;OutboundRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xyz.bac/api"&gt;
    &lt;Entities&gt;
      &lt;BaseEntity i:type="GenericEntity"&gt;
        &lt;Id&gt;
          &lt;TypeName&gt;Project&lt;/TypeName&gt;
          &lt;Value&gt;76wp5wtggqnr2zh2zulelom6v92&lt;/Value&gt;
        &lt;/Id&gt;
        &lt;Values&gt;
          &lt;FieldValue&gt;
            &lt;FieldName&gt;DueDate&lt;/FieldName&gt;
            &lt;Value xmlns:d6p1="http://www.w3.org/2001/XMLSchema" i:type="d6p1:dateTime"&gt;2019-07-30T21:00:00&lt;/Value&gt;
          &lt;/FieldValue&gt;
          &lt;FieldValue&gt;
            &lt;FieldName&gt;StartDate&lt;/FieldName&gt;
            &lt;Value xmlns:d6p1="http://www.w3.org/2001/XMLSchema" i:type="d6p1:dateTime"&gt;2019-03-04T13:00:00&lt;/Value&gt;
          &lt;/FieldValue&gt;
          &lt;FieldValue&gt;
            &lt;FieldName&gt;CommittedDate&lt;/FieldName&gt;
            &lt;Value xmlns:d6p1="http://www.w3.org/2001/XMLSchema" i:type="d6p1:dateTime"&gt;2019-01-31T00:00:00&lt;/Value&gt;
          &lt;/FieldValue&gt;
          &lt;FieldValue&gt;
            &lt;FieldName&gt;C_Components&lt;/FieldName&gt;
            &lt;Value i:type="EntityId"&gt;
              &lt;TypeName&gt;C_WorkItemComponents&lt;/TypeName&gt;
              &lt;Value&gt;SS-BA;SS-PM;IS-JIRA&lt;/Value&gt;
            &lt;/Value&gt;
          &lt;/FieldValue&gt;
          &lt;FieldValue&gt;
            &lt;FieldName&gt;C_PrimaryTeam&lt;/FieldName&gt;
            &lt;Value i:type="GenericEntity"&gt;
              &lt;Id&gt;
                &lt;TypeName&gt;C_WorkItemPrimaryTeam&lt;/TypeName&gt;
                &lt;Value&gt;IS-JIRA&lt;/Value&gt;
              &lt;/Id&gt;
              &lt;Values /&gt;
            &lt;/Value&gt;
          &lt;/FieldValue&gt;
          &lt;FieldValue&gt;
            &lt;FieldName&gt;Importance&lt;/FieldName&gt;
            &lt;Value i:type="GenericEntity"&gt;
              &lt;Id&gt;
                &lt;TypeName&gt;Importance&lt;/TypeName&gt;
                &lt;Value&gt;High&lt;/Value&gt;
              &lt;/Id&gt;
              &lt;Values /&gt;
            &lt;/Value&gt;
          &lt;/FieldValue&gt;
          &lt;FieldValue&gt;
            &lt;FieldName&gt;C_JIRA_Integration_Code&lt;/FieldName&gt;
            &lt;Value xmlns:d6p1="http://www.w3.org/2001/XMLSchema" i:type="d6p1:string"&gt;ZenJIRA&lt;/Value&gt;
          &lt;/FieldValue&gt;
          &lt;FieldValue&gt;
            &lt;FieldName&gt;C_JIRAKey&lt;/FieldName&gt;
            &lt;Value xmlns:d6p1="http://www.w3.org/2001/XMLSchema" i:type="d6p1:string"&gt;https://dev.server/browse/ABC-14759&lt;/Value&gt;
          &lt;/FieldValue&gt;
          &lt;FieldValue&gt;
            &lt;FieldName&gt;Phase&lt;/FieldName&gt;
            &lt;Value i:type="GenericEntity"&gt;
              &lt;Id&gt;
                &lt;TypeName&gt;Phase&lt;/TypeName&gt;
                &lt;Value&gt;Coordination&lt;/Value&gt;
              &lt;/Id&gt;
              &lt;Values /&gt;
            &lt;/Value&gt;
          &lt;/FieldValue&gt;
        &lt;/Values&gt;
      &lt;/BaseEntity&gt;
    &lt;/Entities&gt;
    &lt;OrganizationId&gt;2heyug4hn27vwlvmm3t6o92x90&lt;/OrganizationId&gt;
    &lt;RuleName&gt;JiraSync&lt;/RuleName&gt;
  &lt;/OutboundRequest&gt;
  </code></pre>
  
  <p>Output JSON:</p>
  
  <pre><code>{
      "fields": {
          "customfield_10659": "2019-07-30T21:00:00",
          "customfield_19029": "2019-07-30T21:00:00",
          "customfield_10645": {
              "value": "High"
          },
          "customfield_12925": {
              "value": "IS-JIRA"
          },
          "customfield_12735": {
              "value": "BlockerReason"
          }
      }
  }
  </code></pre>