Data Format Description Language (DFDL) v1.0 Specification
OGF Proposed Recommendation GFD-P-R.174, January 31, 2011
This section describes properties which allow the creation of calculated elements. When parsing, the value of a calculated element is derived using a DFDL Expression, and not by processing bytes from the data stream. When unparsing, the value of a calculated element is derived using a DFDL Expression, and is not obtained from the infoset in the usual way.
Calculated elements allow a technique that is commonly called layering. In this technique, some elements are said to be in the physical layer, and some in the logical layer. When parsing, the logical layer values are computed from physical layer values. When unparsing the opposite occurs, that is the physical layer values are computed from the logical layer values.
Calculated elements are commonly used with hidden elements so as to hide the physical layer elements so that they do not become part of the infoset.
When a DFDL Schema is used to both parse and unparse data, then a calculated element on parsing will normally have one or more calculated elements on unparsing.
These properties apply to elements of simple type, and to simple types.
Property Name |
Description |
---|---|
inputValueCalc |
DFDL Expression An expression that calculates the value of the element when parsing. The element having the inputValueCalc property is called a derived element, and the elements referenced from the inputValueCalc expression are called representation elements. An empty string is a valid return value for expression for a string-typed element if minLength allows length 0. An element that specifies an inputValueCalc expression has no representation of its own in the data stream. All other DFDL representation properties are ignored The element must not be optional nor an array The DFDL Expression must not refer to this element nor cause a circular reference to this element. The expression must not contain forward references to elements which have not yet been processed. It is a schema definition error if dfdl:inputValueCalc is specified on an element which has an xs:fixed or xs:default value. It is a schema definition error if dfdl:inputValueCalc and dfdl:outputValueCalc are specified on the same element. Annotation: dfdl:element |
outputValueCalc |
DFDL Expression An expression that calculates the value of the current element when unparsing. An empty string is a valid return value for expression for a string-typed element if minLength allows length 0. The element must not be optional nor an array The value for the element, is any, in the infoset is ignored. The DFDL expression must not refer to this element nor cause a circular reference to this element. The expression may contain forward references to elements which have not yet been processed. It is a schema definition error if dfdl:outputValueCalc is specified on an element which has an xs:fixed or xs:default value. It is a schema definition error if dfdl:inputValueCalc and dfdl:outputValueCalc are specified on the same element. Annotation: dfdl:element |
Example: 2d Nested Array
<xs:complexType name="array">
<xs:sequence dfdl:initiator="" >
<xs:sequence dfdl:hiddenGroupRef="tns:hiddenArrayCounts"/>
<xs:element name="rows" maxOccurs="unbounded"
dfdl:occursCountKind="expression"
dfdl:occursCount="{ ../nrows }">
<xs:complexType>
<xs:sequence>
<xs:element name="cols" type="xs:float"
maxOccurs="unbounded"
dfdl:occursCountKind="expression"
dfdl:occursCount=" { ../../ncols } " />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:group name="hiddenArrayCounts" >
<xs:sequence>
<xs:element name="nrows" type="xs:unsignedInt"
dfdl:representation="binary"
dfdl:lengthKind="implicit"
dfdl:outputValueCalc="{ count(../rows) }"/>
<xs:element name="ncols" type="xs:unsignedInt"
dfdl:representation="binary"
dfdl:lengthKind="implicit"
dfdl:outputValueCalc=
"{ if ( count(../rows) ge 1 )
then
count(../rows[1]/cols)
else
0
}"/>
</xs:sequence>
</xs:group>
Example: Three-Byte Date
Logically, the data is a date.
<xs:element name=“d” type=“date”/>
Physically, it is stored as 3 single byte integers.
The format of this data is expressed as this schema:
<xs:sequence dfdl:representation="binary”>
<xs:element name="mm" type="byte" />
<xs:element name="dd" type="byte” />
<xs:element name="yy" type="byte"/>
</xs:sequence>
<xs:sequence>
<xs:sequence dfdl:hiddenGroupRef="tns:hiddenpDate"/>
<xs:element name="d" type="date">
…
</xs:element>
…
</xs:sequence>
<xs:group name="hiddenpDate" >
<xs:sequence>
<xs:element name="pdate">
<xs:complexType>
<xs:sequence dfdl:representation="binary">
<xs:element name="mm" type="byte" />
<xs:element name="dd" type="byte" />
<xs:element name="yy" type="byte"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:group>
<xs:sequence>
… hidden pdate here …
<xs:element name="d" type="date">
<xs:annotation><xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:element>
<dfdl:property name="inputValueCalc">
{
fn:date(fn:concat(if(../pdate/yy gt 50 )then "19" else "20",
if ( ../pdate/yy gt 9 )
then fn:string(../pdate/yy)
else fn:concat("0",
fn:string(../pdate/yy)),
"-",
fn:string(../pdate/mm),
"-",
fn:string(../pdate/dd)))
}
</dfdl:property>
</dfdl:element>
</xs:appinfo></xs:annotation>
</xs:element>
…
</xs:sequence>
The expression above assembles a string resembling, for example, “2005-12-17” or “1957-3-9” which is the string representation of a date that is acceptable to the fn:date constructor function. The hidden element ‘pdate’ is referenced by relative paths. The expression ‘../pdate/yy’ accesses an element of type ‘int’, and the fn:string constructor function turns it into an integer.
<xs:sequence dfdl:representation="binary"
<xs:element name="mm" type="byte"
dfdl:outputValueCalc="{ fn:month-from-date(../d) }" />
<xs:element name="dd" type="byte"
dfdl:outputValueCalc="{ fn:day-from-date(../d) }" />
<xs:element name="yy" type="byte"
dfdl:outputValueCalc="{ fn:year-from-date(../d) idivmod 100 }"
/>
</xs:sequence>
<xs:sequence>
<xs:sequence dfdl:hiddenGroupRef="tns:hiddenpDate"/>
<xs:element name="d" type="date">
<xs:annotation><xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:element>
<dfdl:property name="inputValueCalc">
{
fn:date(fn:concat(if(../pdate/yy gt 50) then "19" else "20",
if ( ../pdate/yy gt 9 )
then fn:string(../pdate/yy)
else fn:concat("0",
fn:string(../pdate/yy)),
"-",
fn:string(../pdate/mm),
"-",
fn:string(../pdate/dd)))
}
</dfdl:property>
</dfdl:element>
</xs:appinfo></xs:annotation>
</xs:element>
…
</xs:sequence>
<xs:group name="hiddenpDate" >
<xs:sequence>
<xs:element name="pdate">
<xs:complexType>
<xs:sequence dfdl:representation="binary">
<xs:element name="mm" type="byte"
dfdl:outputValueCalc="{ fn:month-from-date(../d) }" />
<xs:element name="dd" type="byte"
dfdl:outputValueCalc="{ fn:day-from-date(../d) }" />
<xs:element name="yy" type="byte"
dfdl:outputValueCalc="{ fn:year-from-date(../d) idivmod 100 }"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:group>
Copyright (C) Open Grid Forum (2005-2010). All Rights Reserved.
This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the OGF or other organizations, except as needed for the purpose of developing Grid Recommendations in which case the procedures for copyrights defined in the OGF Document process must be followed, or as required to translate it into languages other than English.