There is an example of doing dfdl:occursCountKind 'expression' on github in the CSV example here:
https://github.com/DFDLSchemas/CSV/blob/master/src/main/resources/com/tresys/csv/xsd/csvHeaderEnforced.dfdl.xsd Line 75 of this file, it uses this technique to ensure each row has the same number of items as there were titles in the initial header row. Your case you want a different expression to pick out the exact count from an earlier element, but the example may help. ________________________________ From: Steve Lawrence <slawre...@apache.org> Sent: Wednesday, July 21, 2021 9:52 AM To: users@daffodil.apache.org <users@daffodil.apache.org> Subject: Re: variable length CSV records via 'lengthKind' property You cannot dynamically set maxOccurs--that has to be either a static number or "unbounded". This is a restriction of XML Schema that DFDL is based off of. But Daffodil does support what you're trying to do . First, you'll want to set maxOccurs="unbounded" (since we don't know how many parameter instances there might be). Bbut then we can use the dfdl:occursCountKind="expression" and dfdl:occursCount properties to evaluate an expression at parse time to set the number of occurrences to the value of the third field. For example: ... <xs:element name="field3" type="xs:int" ... /> <xs:element name="parameters" type="..." maxOccurs="unbounded" dfdl:occursCountKind="expression" dfdl:occursCount="{ ../field3 }" ... /> ... So we parse field3 to an integer and then use that value in an expression to determine the number of occurrences of the parameters array. On 7/21/21 8:04 AM, Horvath, Attila J CTR (USA) wrote: > ALCON - see attached PDF version of this message > > I have a Character Separated Values [CSV] ASCII input file where: > > - fields are ASCII STX character [0x02] separated > > - variable number of fields per below > > - records are ASCII DC4 character [0x14] terminated > > - file is ASCII EOT character [0x04] terminated > > In following sample excerpt, highlighted in YELLOW is last record of data > file. > > 3rd field [31 30] specifies 10 fields to follow each STX [0x02] delimited, > > followed by record and file terminators [0x14 0x04] respectively... > > Is it possible to read the 3rd field ['10'], save it via [*_dfdl:lengthKind_* > and/or *_dfdl:defineVariable_*] as "NUM_FIELDS" and pass that value to > 'maxOccurs' attribute on per record basis? > > EG:... > > <xs:element name="parameters" maxOccurs=NUM_FIELDS minOccurs="1"> > > ... > > </xs:element> > > Thx in advance > > Attila >