80 likes | 201 Views
Calculated Values. DFDL supports limited layering Properties: inputValueCalc outputValueCalc outputLengthCalc Note: inputLengthCalc is just length=“{ … }”. Calculated Values Example. M. M. D. D. Y. Y. Logically, the data is a date. <element name=“d” type=“date”/>
E N D
Calculated Values • DFDL supports limited layering • Properties: • inputValueCalc • outputValueCalc • outputLengthCalc • Note: inputLengthCalc is just length=“{ … }” 1
Calculated Values Example M M D D Y Y • Logically, the data is a date. <element name=“d” type=“date”/> • Physically, it is stored as 6 packed-decimal digits, unsigned • Like so: 2
Physical Layer’s Shape M M D D Y Y <sequence> <element name="mm" type="int“ /> <element name="dd" type="int“ /> <element name="yy" type="int“ /> </sequence> 3
Physical Layer Representation M M D D Y Y <sequence dfdl:representation="binary" dfdl:numberRepresentation="packedDecimal" dfdl:decimalSigned="false“ > <element name="mm" type="int" dfdl:numberPattern="##“ /> <element name="dd" type="int" dfdl:numberPattern="##“ /> <element name="yy" type="int" dfdl:numberPattern="##“ /> </sequence> 4
Hide Physical Layer M M D D Y Y Physical layer (hidden) Logical layer <sequence> <annotation><appinfo ...> <dfdl:hidden> <element name="pdate"> <complexType> • <sequence dfdl:representation="binary" • dfdl:numberRepresentation="packedDecimal" • dfdl:decimalSigned="false“ > • <element name="mm" type="int" • dfdl:numberPattern="##“ /> • <element name="dd" type="int" • dfdl:numberPattern="##“ /> • <element name="yy" type="int" • dfdl:numberPattern="##“ /> • </sequence> </complexType> </element> </dfdl:hidden> </appinfo></annotation> <element name="d" type="date"> … </element> 5
Parsing: Calculate Logical from Physical M M D D Y Y dfdl:property annotations to avoid quoting hell <sequence> … hidden pdate here … <element name="d" type="date"> <annotation><appinfo> <dfdl:format> <dfdl:property name="inputValueCalc"> { fn:date(fn:concat(if ( ../pdate/yy > 50 ) then "19" else "20", fn:string(../pdate/yy), "-", fn:string(../pdate/mm), "-", fn:string(../pdate/dd))) } </dfdl:property> </dfdl:format> </appinfo></annotation> </element> 6
Unparsing: Calculate Physical from Logical M M D D Y Y <sequence dfdl:representation="binary" dfdl:numberRepresentation="packedDecimal" dfdl:decimalSigned="false" <element name="mm" type="int" dfdl:numberPattern="##" dfdl:outputValueCalc="{ fn:month-from-date(../d) }" /> <element name="dd" type="int" dfdl:numberPattern="##" dfdl:outputValueCalc="{ fn:day-from-date(../d) }" /> <element name="yy" type="int" dfdl:numberPattern="##" dfdl:outputValueCalc="{ fn:year-from-date(../d) idiv 100 }" /> </sequence> 7