exists 
Use this function to determine whether a particular source field exists in the XML instance to be processed. If it does, exists() returns the value true, otherwise it returns the value false.
In the example below, a function description is to be mapped to a structure that merely comprises the technical name and the description of the function. The source structure field description is optional, however, the target structure field descriptionOfUse is mandatory (minOccurs = 1).
Source Structure (Left) and Target Structure (Right)
Field Name |
minOccurs |
maxOccurs |
Field Name |
min- Occurs |
max- Occurs |
FunctionDeclMsg |
1 |
1 |
FunctionHeadingMsg |
1 |
1 |
name |
1 |
1 |
technicalName |
1 |
1 |
description |
0 |
1 |
descriptionOfUse |
1 |
1 |
inputArg |
0 |
64 |
|||
name (Attr) |
1 |
1 |
|||
type (Attr) |
1 |
1 |
|||
returnValue |
0 |
1 |
|||
type (Attr) |
1 |
1 |
Using the exists()function and other Boolean functions you can output a specified string by default if the description-tag does not exist here. This ensures that the target field descriptionOfUse is always completed and is never empty.
Message Mapping Using exists()
Target Field Mapping |
Value of Constant() |
/FunctionHeadingMsg=/FunctionDeclMsg |
|
/FunctionHeadingMsg/technicalName=/FunctionDeclMsg/name |
|
/FunctionHeadingMsg/descriptionOfUse= if( Constant() , Not(exists(/FunctionDeclMsg/description)) , /FunctionDeclMsg/description ) |
(No description available) |
Note
The text description of the if standard function must be read as follows: if ( <result if condition true>, <condition>, <result if condition false>).
Source Instance |
Result |
<?xml version="1.0" encoding="UTF-8"?> <FunctionDeclMsg> <name> myFunc </name> <inputArg type="String" name="arg1" /> <inputArg type="String" name="arg2" /> <inputArg type="String" name="arg3" /> <returnValue type="String" /> </FunctionDeclMsg> |
<?xml version="1.0" encoding="UTF-8"?> <ns0:FunctionHeadingMsg xmlns:ns0="workshopDemo"> <technicalName> myFunc </technicalName> <descriptionOfUse> (No description available) </descriptionOfUse> </ns0:FunctionHeadingMsg> |