Altova MapForce 2022 Enterprise Edition

Applying Node Functions and Defaults Conditionally

Home Prev Top Next

Whenever you create a node function or a default (a so-called "rule"), you can define it either on a item that has descendants, or on a "leaf" item. Importantly, if the item has descendants, you must specify a data type for the rule—this means that only descendants of this data type will be affected by the rule. To better understand this concept, open the following demo mapping: <Documents>\Altova\MapForce2022\MapForceExamples\\OrderInUSD.mfd. Next, click the mf_ic_node_func_defined icon next to Rows item in the target component.



The mapping above reads data from an XML file and writes it to a target CSV file. In the target CSV component, a rule is defined on the input side of the Rows item. Notice that the Rows item has children of type string and integer. Since the data type of the rule is string, the rule will affect only items of this type. In other words, the mf_ic_node_func_applied icon is present only for items of type string, but not for those of type integer. The mf_ic_node_function_blocked icon indicates that the rule is blocked for some items—this fact is not relevant for the moment, see How Defaults and Node Functions Work for more information.


Tip:To display the data type next to each item like in the mapping above, toggle on the Show Data Types ic-show-types toolbar button, and toggle off the Show Annotations ic-show-annot toolbar button. These toggle commands are also available in the View menu.


To change the data type of a rule, click the Ellipsis button mf_ic_ellipsis in the grid above the mapping. This opens a dialog box where you can choose the required type.


"Filter Node Functions and Defaults" dialog box

For example, if you select integer as data type, the rule will apply only to item Amount (since this is the only item of type integer). The component is now redrawn accordingly to illustrate this fact. Notice that no other items except Amount are now affected by rule since they are all of type string.



Change a rule's data type only when this is meaningful in your node function. In the demo OrderInUSD.mfd mapping, the node function is designed to process string data, not numeric data (that is, it performs concatenation of two strings). Consequently, this mapping will fail to execute if you change the node function's data type to integer.


Type inheritance

Since MapForce works not only with XML data, the data types available for selection on the "Filter Node Functions and Defaults" dialog box do not correspond exactly to XML Schema types. Some of them are in fact categories of types, meaning that they will match a larger selection of types. For example, the type string matches various other data types derived from string, such as normalizedString, token, NCName, NMTOKEN, IDREF, ENTITY, and others. Likewise, the type decimal will match the derived types integer, long, short, and others.


The hierarchy of types is according to the XML Schema W3C recommendation. For a diagram that fully illustrates this hierarchy, see §3 in "XML Schema Part 2: Datatypes Second Edition",


Advanced filtering

Optionally, you can apply rules based on even more advanced criteria:


Apply rule if the node is of specific type AND the node name matches some custom text

Apply rule if the node is of specific type AND the type name matches some custom text


For example, the settings below apply a rule only if the node type is string AND the node name is "Title". The image on the right illustrates an example structure where such a rule might be useful (only the node "Title" is matched therefore it gets themf_ic_node_func_applied icon):




Alternatively, you can use a regular expression to match multiple node names or type names that qualify. For example, the settings below apply a rule to all items of type string whose name ends with "total". Notice that a regular expression is used. The regular expression .+total literally means: match one or more occurrences of any character, followed by the text "total". Also, the search is case-insensitive, which means that "SOMETOTAL" and "SomeTotal" will both be matched. The image on the right illustrates an example structure where such a rule might be useful (namely, the three "Total" items qualify for the rule and, therefore, get the mf_ic_node_func_applied icon):




The regular expressions dialect is the same as that of XML schema, see also Regular Expressions. Note the following:


The anchors ^ and \$ are implicit and must not be entered in the Match to box.

Case sensitivity is provided by the Match Case check box, so the i flag is not supported.

Matching on multiple lines is not meaningful for node filtering, so the m flag is not supported.

© 2016-2022 Altova GmbH