XFA Specification
Chapter 3, Object Models in XFA
Scripting Object Model
104
Unqualified References to Ancestors of the Container
One more type of unqualified reference is possible. A SOM expression can refer with an unqualified name
to an ancestor of its container or to a sibling of an ancestor. This makes it possible to modify a template by
wrapping portions of it inside a subform without having to change any of the enclosed scripts. For
example, suppose that we are starting with the following template:
<xdp …>
<template …>
<subform name="Receipt" …>
<subform name="Detail" …>
<field name="Description" …> … </field>
<field name="Units" …> … </field>
<field name="Unit_Price" …> … </field>
<field name="Sub_Total" …>
<calculate>
<script>Units * Unit_Price</script>
</calculate>
</field>
</subform>
…
</subform>
</template>
</xdp>
The template is modified as follows:
<xdp …>
<template …>
<subform name="Receipt" …>
<subform name="Detail" …>
<field name="Description" …> … </field>
<field name="Units" …> … </field>
<field name="Unit_Price" …> … </field>
<subform name="New_Subform"
…>
<field name="Sub_Total" …>
<calculate>
<script>Units * Unit_Price</script>
</calculate>
</field>
</subform>
</subform>
…
</subform>
</template>
</xdp>
The same script still works because
Units
and
Unit_Price
are both siblings of
New_Subform
, which is
an ancestor of
Sub_Total
, which is the container for the script.
Note that this does not work in the other direction. Ancestors can be referred to directly but not
descendants beyond immediate children. Starting with the same original fragment, if a new subform is
wrapped around
Units
and
Unit_Price
, it is necessary to modify the script that calculates
Sub_Total
as follows:
<xdp …>
<template …>