Skip to main content

Result Propagation

Any CDATA value of a statement may be replaced with the result of an embedded statement, unless it is explicitly precluded (by the no-result-propagation predicate). An incompatible result type is thereby implicitly cast to the appropriate input type.

Result propagation is one of iXML's most distinctive features. It allows you to compose statements by nesting them, with the inner statement's result flowing upward to become the content of the outer statement. This eliminates the need for temporary variables in many common patterns and enables a concise, functional style of coding.

Basic propagation

Instead of storing a value in a variable and then referencing it, you can embed the producing statement directly inside the consuming statement:

XML
<!-- Two-step approach with a temporary variable: -->
<set var="number">$(15 + (7.5 * 2 - 3))</set>
<output>$number</output>
<!-- 27 -->

<!-- Single-step approach with result propagation: -->
<output>
<set>$(15 + (7.5 * 2 - 3))</set>
</output>
<!-- 27 -->

In the second form, the <set> statement (without a var attribute) computes the value 27 and propagates it as the content of the <output> statement.

Simultaneous storage and propagation

The result may still be stored in a result variable if specified, while also propagating upward:

XML
<output>
<set var="number">$(15 + (7.5 * 2 - 3))</set>
</output>

<output>,$number</output>

<!-- 27,27 -->

The first <output> receives the propagated result 27 and outputs it. Simultaneously, the value is stored in $number, which the second <output> references.

Last scalar result wins

When multiple embedded statements produce results within the same parent, the last scalar result is used for propagation:

XML
<output>
<set var="number">10</set>
<set>$($number + 100)</set>
<set>$($number + 5)</set>
</output>
<!-- 15 -->

The first <set> stores 10 in number and propagates "10". The second produces 110. The third produces 15. Since the last scalar result wins, the <output> receives 15. The intermediate results are discarded from the propagation chain (though the side effect of storing 10 in $number persists).

Deep nesting with control flow

The embedded code may also be deeply nested. Results of IF, IS, and SWITCH are propagated to the topmost statement, enabling inline conditional output:

XML
<set var="born">1945</set>

<output>
<if value1="$born" func="&lt;" value2="1950">
<set>This person is very old!</set>

<else>
<set>$(2012 - $born)</set>
</else>
</if>
</output>

<!-- This person is very old! -->

CDATA alongside embedded code is discarded

Any CDATA values (plain text) that are used alongside embedded code are discarded. Once you embed any statement inside a parent element, all plain text content in that parent is ignored:

XML
<output>
<set>$(15 + (7.5 * 2 - 3))</set>
471
</output>
<!-- 27 -->

The literal text 471 is discarded because embedded code is present. Only the result of the <set> statement (27) is propagated.

Propagation with function calls

Result propagation is also applicable to user-defined functions. The <call> command propagates its return value to the parent statement:

XML
<function var="getName">
<set var="return">iXML</set>
</function>

<output>
<call func="getName"/>
</output>

<!-- iXML -->

See also

  • set — the most common statement used in propagation patterns
  • call — function calls with result propagation
  • Syntax Essentials — how if, is, and switch propagate results