Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Chapter 8 Mapping and Transforming Data : Shortcuts

Shortcuts
The Move In, Insert, Add Child, and Edit Statement buttons on the Input tab toolbar are ways to manually manipulate XSLT statements in the Activity Input area. These buttons, however, only add or modify one statement at a time. Also, there are some situations where you wish to convert a hint into a statement without performing any mapping. This section describes shortcuts for manipulating XSLT statements.
Right-Click Menu
When you select an element in the Activity Input schema and right-click, a popup menu appears. The Statement menu item contains several sub-items that are useful shortcuts for creating XSLT statements.
Dragging to the Left
Dragging an element in the Activity Input schema to the left past the divider between the two areas of the Input tab changes a hint into an XSLT statement. Figure 27 illustrates dragging an element to the left.
Figure 27 Dragging to the left to change a hint to a statement
This shortcut is useful in the following situations:
Cutting and Pasting
The Activity Input area is an XSLT template for specifying the activity’s input schema. You can choose any element in the Activity Input area and select Copy from the right-click menu or press the Control-C keys to copy the XSLT statement for the element. Once the XSLT is copied, you can paste it into a text editing tool to view or modify the code.
You can also paste arbitrary XSLT code into the Activity Input area using the right-click menu or the Control-V keys. Pasting XSLT code from the copy buffer places the code above the currently selected element in the Activity Input area.
Automatic Testing
When you map process data elements to activity input elements, the behavior of the mapping depends upon the types of elements you are mapping. In the simplest case of mapping a required element in the process data schema to a required activity input element, the value of the process data element is assigned to the required activity input element.
However, when elements are optional or nillable, more complex tests are necessary. When you drag the process data element to the activity input element, the necessary tests are automatically placed into the activity input XSLT template.
This section describes the result of mapping different types of elements. The types of mappings are described, then an example is given that illustrates these mappings and shows the XSLT code that is generated automatically when these mappings are performed.
Required to Required
Specifies that the statement should always include the required activity input element and its value should be obtained from the required process data element that the element is mapped to.
Optional to Optional
Specifies that the statement should test if the process data element is present, and if so, include the optional element in the activity’s input. If the process data element is not present, the optional element is omitted from the activity’s input.
Nillable to Nillable
Specifies that both the process data and activity input elements can be nil. Therefore, the value of the activity input element is set to the value of the process data element. The value of the activity input element is set explicitly to nil if that is the value of the process data element.
Optional to Nillable
Specifies that the statement should test if the optional process data element exists. If the element exists, the activity input element should be created and set to the value of the process data element. If the process data element does not exist, the element is omitted from the activity input schema.
Nillable to Optional
Specifies that the statement should test if the process data element has a value specified, and if so, the optional element in the activity input should be set to the value of the process data element. Otherwise, if the process data element is nil, the optional element is omitted from the activity input.
Optional & Nillable to Optional & Nillable
Specifies that if the optional process data element exists, then include the optional activity input element in the input schema. If the process data element is nil, set the value of the activity input element explicitly to nil. If the process data element is not nil, set the value of the activity input element to the value of the process data element. If the process data element is not present, then omit the optional element from the activity input schema.
Example of Mapping Required, Optional, and Nillable Elements
Figure 28 illustrates the different types of mappings when elements are required, optional, or nillable.
Figure 28 Examples of mapping required, optional, and nillable elements
In the example above, Item and Amount illustrate mapping required elements to other required elements. The OnSale element illustrates mapping a nillable element to an optional element. The Discount element illustrates mapping an optional element to an optional element. The Pickup element illustrates mapping an optional element to a nillable element. The CustomerAddr and ShipTo elements illustrate mapping an optional and nillable element to an optional and nillable element.
Below is the XSLT template illustrated by the mappings in Figure 28. You can see from the XSLT code that certain mappings are automatically surrounded by tests to create the appropriate input schema.
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:template xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:pd="http://xmlns.tibco.com/bw/process/2003"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:pfx="http://www.tibco.com/xmlns/ae2xsd/2002/05/ae/Order">
   <Order>
      <Item>
          <xsl:value-of select="$RetrieveOrder/IncomingOrder/Order/Item"/>
      </Item>
      <Amount>
         <xsl:value-of select="$RetrieveOrder/IncomingOrder/Order/Amount"/>
      </Amount>
      <xsl:if test="$RetrieveOrder/IncomingOrder/Order/OnSale/@xsi:nil!=
            (&quot;true&quot;,&quot;1&quot;)">
         <OnSale>
            <xsl:value-of select="$RetrieveOrder/IncomingOrder/Order/OnSale"/>
         </OnSale>
      </xsl:if>
      <xsl:if test="$RetrieveOrder/IncomingOrder/Order/Discount">
         <Discount>
            <xsl:value-of select="$RetrieveOrder/IncomingOrder/Order/Discount"/>
         </Discount>
      </xsl:if>
      <pfx:ShipTo>
         <Pickup>
            <xsl:choose>
               <xsl:when test=
                       "exists($RetrieveOrder/IncomingOrder/Order/Pickup)">
                  <xsl:value-of select=
                       "$RetrieveOrder/IncomingOrder/Order/Pickup"/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:attribute name="xsi:nil">true</xsl:attribute>
               </xsl:otherwise>
            </xsl:choose>
         </Pickup>
         <xsl:if test="$RetrieveOrder/IncomingOrder/Order/StoreLocation">
            <StoreLocation>
               <xsl:value-of select=
                      "$RetrieveOrder/IncomingOrder/Order/StoreLocation"/>
            </StoreLocation>
         </xsl:if>
         <xsl:if test="$RetrieveOrder/IncomingOrder/Order/CustomerAddr">
            <ShipTo>
               <xsl:copy-of select=
                      "$RetrieveOrder/IncomingOrder/Order/CustomerAddr/@xsi:nil"/>
               <xsl:value-of select=
                      "$RetrieveOrder/IncomingOrder/Order/CustomerAddr"/>
            </ShipTo>
         </xsl:if>
      </pfx:ShipTo>
   </Order>
</xsl:template>

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved