XFA Specification
Chapter 3, Object Models in XFA
Scripting Object Model
87
is a subtree of the data corresponding to one element and its contents. In this mode of operation
$record
points to the node representing the outer element for the current record. In the receipt
example
$record
would initially be set to point to the node representing the first
Detail
element.
After some processing
$record
would advance to the node representing the next
Detail
element.
The receipt example contains only two records, but large documents may contain tens of thousands of
records.
●
Record processing not enabled.
In non-record mode
$record
points to the node representing the
outermost element of the data document, that is the node which is the only child of
$data
. In the
receipt example
$record
would be set to
$data
.
Receipt
. Hence in non-record mode the entire
document is treated as one big record.
See the
“Creating, Updating, and Unloading a Basic XFA Data DOM” on page 113
record processing.
Repeated Elements
When multiple nodes with the same name occur as children of the same parent node, a reference to the
shared name is taken to refer to the first matching child, in document order. (In tree diagrams, document
order corresponds to starting at the root node and making a depth-first left-to-right traversal of the tree.)
The receipt example includes two sets of data describing purchased items, each in a
Detail
element. The
following expression refers only to the node representing the first
Detail
element in document order
(that is, the one for a giant sling shot):
$data.Receipt.Detail
To access the other
Detail
nodes, given that they have the same name, it is necessary to use an
array-subscript notation. The syntax [nnn], where
nnn
represents a number, is used to select one particular
element out of a group of siblings with the same names. The number zero represents the first sibling.
Hence the following two expressions are equivalent:
$data.Receipt.Detail $data.Receipt.Detail[0]
The next
Detail
node is referenced as
$data.Receipt.Detail[1]
Note:
It would not make any difference if there had been other nodes in between, as long as they were
not named
Detail
. For example, if the data document is changed to
<?xml version="1.0" encoding="UTF-8" ?>
<Receipt>
<Page>1</Page>
<Detail>
<Description>Giant Slingshot</Description>
<Units>1</Units>
<Unit_Price>250.00</Unit_Price>
<Total_Price>250.00</Total_Price>
</Detail>
<Page>2</Page>
<Detail>
<Description>Road Runner Bait, large bag</Description>
<Units>5</Units>
<Unit_Price>12.00</Unit_Price>
<Total_Price>60.00</Total_Price>
</Detail>
<Sub_Total>310.00</Sub_Total>