I think the best approach is to restate the requirement as each section begins on a byte boundary.
So the start of each section should have dfdl:alignment="8" dfdl:alignmentUnits="bits". Alternatively, you can create a reusable "pad to byte boundary" group like this: <xs:group name="padToByteBoundary"> <xs:sequence dfdl:alignment="8" dfdl:alignmentUnits="bits"/> </xs:group> You can then reference that via a group reference at the end of your sections. The only thing this won't do for you is preserve the contents of the padding bits. They are skipped over on parse, and filled from the dfdl:fillByte on unparse. ________________________________ From: Costello, Roger L. <coste...@mitre.org> Sent: Friday, July 26, 2019 11:34:17 AM To: users@daffodil.apache.org <users@daffodil.apache.org> Subject: RE: How to create a hidden group for 0-7 padding bits? Hello DFDL community, The input file contains binary data. There are a series of "sections" in the input. The data for a section might not fill the last byte; if so, that byte is filled with padding bits - up to 7 padding bits. Here's what I tried. It doesn't work. What is the right way to implement this? ... consume/parse the section's data ... ... there may be padding bits after the last data item: <xs:sequence dfdl:hiddenGroupRef="padding0-7Bits" /> <xs:group name="padding0-7Bits"> <xs:sequence> <xs:element name="padding" type="xs:hexBinary" dfdl:alignment="implicit" dfdl:alignmentUnits="bits" dfdl:fillByte="%NUL;" dfdl:outputValueCalc="{xs:hexBinary('00')}" /> </xs:sequence> </xs:group>