Checking whether the value of an input element is empty

Use appropriate expressions to test for empty input values, depending on whether the element is a simple or complex type.

About this task

You can define conditional expressions in a transform to determine whether the transform is applied or not in your message map. For example, you might decide not to apply a transform if the input value is empty.

For simple string types, you can test whether the element is empty by comparing with the empty string '' (two single quotation marks). For example, to check whether a string element that is represented by the variable name str is empty, use the following expression:

$str = ''

If the element is also nillable, use the following expression:

(fn:nilled( $elementName) = false)  and $str = ''

Other simple types have no natural empty value. For example, with numerical type elements the value must always contain a minimum set of valid digits. In this case, you might consider a particular value to be empty, and so test for that value. To check whether a number element that is represented by the variable name num has a zero value, use the following expression:

$num = 0

To determine whether a complex element is empty, check for child elements or attributes. For example, to check a complex element that is represented by the variable name comp, use the following expression:

fn:not( $comp/* or $comp/@* )

If the complex element allows mixed content, check for text content as well.

fn:not( $comp/text() or  $nodes/* or $nodes/@* )

Procedure

Take the following steps to define a conditional expression on a Move transform between a source and target string element. The expression ensures that the transform is not applied if the input data is an empty string.

  1. Create a Move transform between an input element and an output element.
  2. In the Properties view, under Condition, use content assist (Ctrl+Space) to enter the appropriate XPath expression.
    For example, assuming the variable name for the input is str:
    $str = ''