Test of recursive subforms

This test illustrates the use of a recursive call to a subform to handle a recursive element structure.

The data

The XML instance document uses a three-element vocabulary (op, var, lit for operators, variable references, and literal values) to represent simple arithmetic expressions. For example, the expression (x + 1) × (x - 1) is represented thus:

    <op name="product">
      <op name="sum">
	<var name="x"/>
	<lit value="1"/>
      </op>
      <op name="difference">
	<var name="x"/>
	<lit value="1"/>
      </op>
    </op>
      

The instance document current represents the expression (((x + 1) * (x - 1)) + ((y + 2) * (y - 2))).

A fixed-depth display

If we can guarantee a fixed (and shallow) maximum depth to the expressions, we can use nested xf:repeat elements to show the structure of the expression.

It is obviously equally possible to create a fixed-depth editor.

A recursive editor

Since often we cannot guarantee a fixed maximum depth to the expressions, we need some form of recursion. This example uses a recursive subform, but owing to ID conflicts, it does not work as desired.

A pseudo-recursive editor

This version of the recursive subform example uses several subforms, which differ only in the values they use for xf:load/@resource, xf:load/@targetid, xf:unload/@targetid.

For purposes of this demonstration, these subforms were generated by hand, but they could easily be generated on the fly by the server, with a server configuration that looks for attempts to load .../subform-N.xhtml and responds with a copy of the subform in which the appropriate values have been changed to refer to value N + 1.

Note that the calculation of the string values of the nodes here is not behaving as desired; changes should be visible in the bulleted-list display above even when they are not visible in the string values displayed here. A separate test case devoted to the question of recursive calculations is here.

Note also that this is a simplified example; a more realistic example would offer the ability to replace any expression of one type with an expression of a different type, thus changing the depth of the syntax tree dynamically.

CMSMcQ, 29 June 2016