Mapping and Transforming Data : XSLT Statements

XSLT Statements
The following sections describe the XSLT statements you can add to your mapping. You can add or edit these statements by clicking the Edit Statement () button or these statements can be added automatically by selecting them from the dialogs that appear when you drag and drop elements from the Scope Variables tree to the function argument tree.
The following sections discuss statement types (available in the Statement Type drop-down list in the Edit Statement dialog).
Attribute
Allows you to specify an attribute, and optionally the namespace for the attribute. You can also specify the type of value for the attribute.
XSLT Equivalent
The following is an attribute named "lastname".
 
<ns:attribute namespace="mns" name="lastName"/>
When attributes are created, you can optionally specify the kind of value the attribute will have and whether the attribute should be surrounded by an if statement. For example, you can specify the value of the last name attribute to be a constant, like so:
 
<ns:attribute namespace="mns" name="lastName"/>
   "Smith"
</ns:attribute>
Choose
Provides a way to select transformation to perform based on an expression. Specify the condition in the when element as an XPath expression. You can optionally specify an otherwise condition for processing all elements that do not meet any of the specified when conditions.
XSLT Equivalent
The following determines if the node set for FilesTransferred contains any files, and if so, performs an action. If the node set is empty (no files were transferred), a different action is performed.
 
<ns0:choose xmlns:ns0="http://www.w3.org/1999/XSL/Transform">
   <ns0:when test="$FTP-Put/FTPPutOutputFile/FileTransferred" >
      < something here ... >
   </ns:0when>
   <ns0:otherwise>
      < something here ...>
   </ns0:otherwise>
</ns0:choose>
Comment
Places a comment in the XSLT template. Comments are delimited by <!-- and -->.
XSLT Equivalent
 
<!-- comment here -->
Copy
Copies the selected node to the current node in the input tree. Only the node is copied, no children of the node are copied.
XSLT Equivalent
 
<ns0:copy xmlns:ns0="http://www.w3.org/1999/XSL/Transform" select="$Query/resultSet"/>
Copy-Contents-Of
Copies the selected node’s contents. This is useful if you wish to copy an element to a new element with a different name.
XSLT Equivalent
 
<ns:element namespace="foo" name="bar">
   <ns:copy-of select="null/@*"/>
   <ns:copy-of select="null/node()"/>
</ns:element>
Copy-Of
Creates a copy of the selected node, including the node’s children. Both the copied node and the destination node must have the same name and structure.
XLST Equivalent
 
<ns0:copy-of xmlns:ns0="http://www.w3.org/1999/XSL/Transform" select=""/>
Element
Creates an element with the specified name.
XSLT Equivalent
 
<elementName>value</elementName>
For-Each
Performs the specified statements once for each item in the selected node. This is useful if you wish to process each item of a repeating element once.
XSLT Equivalent
The following iterates over the list of files transferred from a ActiveMatrix BusinessWorks FTP Put activity and outputs an element with the name of each file for each file transferred.
<ns:for-each select="$FTP-Put/FTPPutOutputFile/FileTransferred">
   <fileName>
      <ns:value-of select="$FTP-Put/FTPPutOutputFile/FileTransferred/Name"/>
   </fileName>
</ns:for-each>
For-Each-Group
Groups the items in a list by a specified element. This statement requires a Grouping statement to specify which element to group-by. See Converting a List Into a Grouped List for an example of using the For-Each-Group statement.
XSLT Equivalent
 
<ns0:for-each-group xmlns:ns0="http://www.w3.org/1999/XSL/Transform" select=""/>
Generate Comment
Places a comment element into the XSLT template. This comment will be generated into the function’s output.
Comment elements have the following syntax:
 
<ns0:comment xmlns:ns0="http://www.w3.org/1999/XSL/Transform"/>
Generate PI
Places a processing instruction into the XSLT template.
XSLT Equivalent
 
<ns0:processing-instruction xmlns:ns0="http://www.w3.org/1999/XSL/Transform" name=""/>
If
An if statement is used to surround other statements in an XSLT template to perform conditional processing. If the test attribute evaluates to true, the statements in the if are output, otherwise they are not output.
XSLT Equivalent
The following if statement surrounds an attribute for processing order items.
 
<ns:if xmlns:ns="http://www.w3.org/1999/XSL/Transform" test="not(position()=last())">
<ns:attribute name="OrderItem">
<ns:value-of select=
  "$GetOrderInformation/OrderInformation/OrderDetails/OrderItem"/>
</ns:attribute>
</ns:if>
Value-Of
Specifies a value-of statement. This is normally done implicitly by specifying the formula for an element (field) in the mapping, but you may insert this statement explicitly.
XSLT Equivalent
 
<ns:value-of xmlns:ns="http://www.w3.org/1999/XSL/Transform" select=""/>
Variable
Adds a local variable for use in the current mapping. You can specify the name of the variable and whether you wish the variable to have a select attribute.
When you add a local variable, it appears in the Function and Scope Variables panels. You can supply any XPath expression to the new variable in the Function panel (either through mapping or through the XPath Formula Builder).
Once the variable’s contents have been supplied, the variable (in the Scope Variables area) can be mapped to any item.
Adding a variable is useful when you wish to join two repeating elements into a single list, then map the combined list to an item. Adding a variable is also useful if you perform the same computation repeatedly. You can map the results of the computation to several items instead of recreating the computation for each item.
Variables can also improve performance of mappings for large data structures. For example, if you have a process variable with 40 sub-elements, and you map each of the sub-elements to a corresponding input item, TIBCO BusinessEvents must retrieve the current process variable for each XPath expression, in this case 40 times. If this mapping appears in a loop, the retrieval of the current process variable occurs 40 times per iteration of the loop. With a variable, the data is retrieved only once and used for all mappings containing the variable. Therefore, to improve performance, create a local variable to hold process variables with a large number of elements and use the local variable in XPath expressions instead of the process variable.
XSLT Equivalent
 
<ns0:variable xmlns:ns0="http://www.w3.org/1999/XSL/Transform" name="var" select="$RetrieveResults/resultSet"/>