XFA Specification
Chapter 3, Object Models in XFA
Scripting Object Model
84
<field name="Final_Price"><bind match="dataRef"
ref="$data.Receipt.Total_Price"></field>
The expression
$data.Receipt.Total_Price
refers to a single node by naming the nodes which
must be traversed from the root of the Data DOM down to the desired node. Hence it refers to the
Total_Price
node which corresponds to the last
Total_Price
element in the receipt document. (This
is the node containing the value 334.80.) The result of this data reference is to force the XFA application to
associate the template field named
Final_Price
with that particular data node, even though the
template and data nodes have different names.
XFA SOM expressions may also be used in scripting to reference nodes in an XFA-DOM. For example, this
FormCalc expression contains an XFA SOM expression (highlighted in
bold):
Sum(Detail[*].Total_Price)
This expression takes advantage of
"[*]"
notation, which is described below under
“Selecting All Child
Nodes” on page 94,
and scoping, which is described in
“Relative References”.
For now it is sufficient to
understand that the expression
Detail[*].Total_Price
resolves as a list of all of the
Total_Price
data within
Detail
data groups. With the data given above this becomes 250.00 60.00. The FormCalc
function
sum()
simply adds the list of numbers passed to it, yielding in this case 310.00. This expression
would be embedded in the template of an intelligent form that added up the totals and taxes
automatically, rather than relying on the data file to supply them pre-calculated. For the receipt example,
the data file would be as follows:
<?xml version="1.0" encoding="UTF-8" ?>
<Receipt>
<Detail>
<Description>Giant Slingshot</Description>
<Units>1</Units>
<Unit_Price>250.00</Unit_Price>
</Detail>
<Detail>
<Description>Road Runner Bait, large bag</Description>
<Units>5</Units>
<Unit_Price>12.00</Unit_Price>
</Detail>
</Receipt>
The following template uses XFA SOM expressions to perform the calculations automatically. XFA SOM
expressions embedded in the template are highlighted in
bold.
<xdp …>
<template …>
<subform name="Receipt" …>
<pageSet name="ReceiptPageSet" …> … </pageSet>
<subform name="Detail" …>
<field name="Description" …> … </field>
<field name="Units" …> … </field>
<field name="Unit_Price" …> … </field>
<field name="Total_Price" …>
<calculate>
<script>Units *
Unit_Price</script>
</calculate>
</field>
</subform>
Home Index Bookmark Pages
Pages: Home Index