Hi Mike

Are you sure about this?   The spec section 15.1.2 which describes direct dispatch choice says ...

"When a match is found, it is as if a dfdl:discriminator had evaluated to true on that branch. It is selected as resolution of the choice, and there is no backtracking to try other alternative selections if a Processing Error occurs."

I don't see why you are needing the extra discriminator, it sounds like this is a bug in Daffodil.

Regards
 
Steve Hanson

IBM Integration, Hursley, UK
Architect, IBM DFDL
Co-Chair, OGF DFDL Working Group
smh@uk.ibm.com
tel:+44-7717-378890
Note: I work Tuesday to Friday

-----Original Message-----
From: Mike Beckerle <mbeckerle@apache.org>
Reply-To: mbeckerle@apache.org
To: DFDL-WG <dfdl-wg@ogf.org>
Subject: [EXTERNAL] [DFDL-WG] default case needed for choice-by-dispatch
Date: Mon, 16 May 2022 11:57:54 -0400

I know this feature was discussed at one time. The priority of this has gone up for us substantially, as the idiom in DFDL v1.0 for a choice-by-dispatch to have a default case when the choiceDispatchKey doesn't match any choiceBranchKey
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
 
ZjQcmQRYFpfptBannerEnd
I know this feature was discussed at one time.

The priority of this has gone up for us substantially, as the idiom in DFDL v1.0 for a choice-by-dispatch to have a default case when the choiceDispatchKey doesn't match any choiceBranchKey is far too complex.

This appears to be what is needed:

<!-- just a shorthand so we can discriminate true on one DFDL line --> 
<group name="discriminateTrue">
        <sequence>
            <annontation><appinfo ...>
                 <dfdl:discriminator>{ fn:true() }</dfdl:discriminator>
            </appinfo></annotation>
        </sequence>
</group>

....
  <choice>
        <choice dfdl:choiceDispatchKey='{ ... dispatch key expr... }'>
            <sequence dfdl:choiceBranchKey="key1">
               <group ref="p:discriminateTrue"/>
                ... parse the key1 branch ....
            </sequence>
            ... 
            <sequence dfdl:choiceBranchKey="keyN">
               <group ref="p:discriminateTrue"/>
                ... parse the keyN branch ....
            </sequence>
        </choice>
     <!-- default case below if the dispatch key does not match anything --> 
     <element name="invalidKey" ....>
       ...
     </element>
  </choice>
.....

The need for a discriminator for the outer choice on every single branch of the inner choice is tedious at best. This is needed because if you don't have this discriminator, then the backtrack will choose the other choice alternative for any failure of a branch, not just no branch key match, and one will get a diagnostic that the branch key was not found when it was found but the subsequent parse failed. 

This structure is too complex for DFDL schema authors to get right. A way to specify an additional choice branch which is the default to be used on no-match to the other branch keys, is needed. 

An explicit dfdlx:choiceBranchDefault="yes" is one way to do this. 

A final choice branch with no dfdl:choiceBranchKey would also work but seems too error-prone for my taste. A default case should be explicitly marked as such, even if we require it to be the last branch. 



          
Mike Beckerle 
Apache Daffodil PMC | daffodil.apache.org
OGF DFDL Workgroup Co-Chair | www.ogf.org/ogf/doku.php/standards/dfdl/dfdl
Owl Cyber Defense | www.owlcyberdefense.com


--
  dfdl-wg mailing list
  dfdl-wg@ogf.org
  https://www.ogf.org/mailman/listinfo/dfdl-wg 
Unless otherwise stated above:

IBM United Kingdom Limited
Registered in England and Wales with number 741598
Registered office: PO Box 41, North Harbour, Portsmouth, Hants. PO6 3AU