Use Conditional Mappings

You may have a requirement to map data dynamically depending on other data in your integration. This requirement can be achieved with conditional mappings.

This use case describes how to create mappings that specify conditions to take based one of the following countries. If none of those countries are specified, an otherwise condition is taken.
  • United States of America
  • India
  • United Kingdom
  1. Click XSLT.
  2. In the upper right corner, click Toggle functions Mapper functions icon.
  3. Expand XSL Constructors, then Flow Control to display the constructs required to create conditional mappings.
  4. Locate the target element (for this example, named country) in the tree.
    This is the element for which to create conditional mappings.
  5. If the selected element is a lighter color, that means the element does not exist in the mapper’s output. Right-click and select Create Target Node. You cannot insert conditions around country without this step.

    The country element has been right-clicked to display enabled selections for Node Info and Create Target node.

  6. Drag and drop the choose construct as a child of country. The cursor position surrounding country indicates whether the choose construct can be inserted as a child (bottom left) or a parent (upper right).

    The choose element in the XSLT right navigation pane is being dragged to the lower left corner of the country target element.

    For this case, choose is inserted as a child.


    The choose element in the XSLT right navigation pane has been dragged to the lower left corner of the country target element.

  7. Drag and drop a when construct as a child of the choose construct.

    A single when construct has been placed below the choose construct in the target mapper tree. The XSLT navigation pane of constructs is displayed to the right.

  8. Drag and drop two additional when constructs as children of the choose construct to create placeholders for the three conditions.
  9. Drag an otherwise construct below the third when construct.

    Three when constructs and an otherwise construct have been placed below the choose construct in the target mapper tree. The XSLT navigation pane of constructs is displayed to the right.

    Each condition also requires a corresponding mapping value.

  10. Drag and drop a value-of construct as a child of each when and otherwise construct. The tree structure needed to create conditional expressions and mapping expressions is now complete.

    value-of constructs have been placed below all three when construct as child entries in the target mapper tree.

  11. Select the first when construct in the target tree to create the first condition.
  12. Map country from the source tree to the first when construct.

    This image shows the county source element being mapped to the when target element, which appears under country > choose.

  13. Select the value-of element for the first when construct.
  14. Enter = "United States of America" in the Expression Builder to complete the expression.

    This image country source element is mapped to the when target element. A child value-of element of the when element is highlighted. In the Expression Builder, a value of "United States of America" is entered. Three icons are above the Expression Builder.

  15. Click the checkmark to save the expression.
    The text you entered is identified with a T for text (or literal) value.
  16. Repeat steps 11 through 15 for the second and third when constructs.
    • Add "India" to the value-of element of the second when construct.
    • Add "United Kingdom" to the value-of element of the third when construct.


      The source element has been connected to the first when construct in the target mapper tree. The Expression Builder is open at the bottom of the page with the corresponding mapping logic (with "United States of America" added at the end of the logic construct).

  17. Drag and drop country from the source tree to the value-of element of the otherwise construct.
  18. Do not enter a literal value for the otherwise construct.

    When complete, the design looks as follows.


    The source element has been connected to the first when construct in the target mapper tree. The Expression Builder is open at the bottom of the page with the corresponding mapping logic (with "United States of America" added at the end of the logic construct).

  19. Click the checkmark to save the expression.
  20. Click Validate.
  21. Click Code Mapper code icon to view the code for the conditional mapping.
    <nstrgmpr:address xml:id="id_138">
          <cc:country xml:id="id_139">
                <xsl:choose>
                      <xsl:when test="/nstrgdfl:quote/nstrgdfl:customer/cc:address/cc:country">
                            <xsl:value-of select="&quot;United States of America&quot;"/>
                      </xsl:when>
                            <xsl:when test="/nstrgdfl:quote/nstrgdfl:customer/cc:address/cc:country">
                            <xsl:value-of select="&quot;India&quot;"/>
                      </xsl:when>
                            <xsl:when test="/nstrgdfl:quote/nstrgdfl:customer/cc:address/cc:country">
                            <xsl:value-of select="&quot;United Kingdom&quot;"/>
                      </xsl:when>
                      <xsl:otherwise>
                            <xsl:value-of select="/nstrgdfl:quote/nstrgdfl:customer/cc:address/cc:country"/>
                      </xsl:otherwise>
                 </xsl:choose>
          </cc:country>
    </nstrgmpr:address>