Forward references in DFDL expressions are only allowed in one place,
and that is in the dfdl:outputValueCalc property. The spec says for this
property:
The expression may contain forward references to elements which have
not yet been processed.
Forward references normally aren't allowed because when parsing it
doesn't make any sense to reference something that hasn't been parsed
yet. So any property that can be used during parsing cannot contain
forward referencing expressions (which is most of the properties).
However, dfdl:outputValueCalc is not evaluated when when parsing--it is
only ever evaluated when unparsing. And during unparsing, you do have
access to the full infoset, so forward references are possible.
And this is actually a really useful feature since it allows you take
into account the entire infoset if you want to to recompute unparsed
data. For example, if you want to recompute a length field in the
header, it's very likely you'll need to access the payload which is
going to be a forward reference.
On 11/15/21 10:11 AM, Roger L Costello wrote:
Hi Folks,
I am looking at the DFDL schema [1] for the image format called NITF.
I noticed that the schema has a construct which references an element that
occurs later in the NITF file (i.e., a forward reference):
<xs:element name="NITF">
<xs:complexType>
<xs:sequence>
<xs:element name="Header">
...
<xs:element name="HeaderLength" type="nitfc:BCS-NP"
dfdl:outputValueCalc="{...ImageSegment...}" />
...
</xs:element>
<xs:element name="ImageSegment" minOccurs="0" maxOccurs="999" ...
/>
...
</xs:sequence>
</xs:complexType>
</xs:element>
Notice that HeaderLength references ImageSegment, which occurs later in the
file.
I thought forward references are not allowed in DFDL?
/Roger
[1]
https://github.com/DFDLSchemas/NITF/blob/master/src/main/resources/com/tresys/nitf/xsd/nitf.dfdl.xsd
<https://github.com/DFDLSchemas/NITF/blob/master/src/main/resources/com/tresys/nitf/xsd/nitf.dfdl.xsd>