A few ways to handle this:

1) Daffodil has an extension to allow a space separated list of
choiceBranchKeys, so if you know all the keys for the third branch you
can do this:

  dfdl:choiceBranchKey="3 4 5 6"

But if you need it to be portable to other DFDL implementations (e.g.
IBM), or if you need something more generic (e.g. all nums greater than
3 should have no parents) then you need to go a different route.

2) Have a more complex dispatch expression, something like:

dfdl:choiceDispatchKey="{
  if (./num eq 1) then 'rounded'
  else if (./num eq 2) then 'square'
  else 'none' }"

And change your choiceBranchKeys to "rounded", "square", and "none".

This works well if there aren't too many different keys/branches, but if
there are, then the if else expression can get pretty complicated, so we
sometimes use the next alternative.

3) Nested choices act sort of like a default if the dispatch doesn't
match anything:

  <xs:choice>
    <xs:choice dfdl:choiceDispatchKey="{ ./num }">
      <xs:element name="A" dfdl:choiceBranchKey="1" ... />
      <xs:element name="B" dfdl:choiceBranchKey="2" ... />
    </xs:choice>
    <xs:element name="C" ... />
  </xs:choice>

So we first try the first branch of the outer choice, which is a choice
dispatch. If the dispatch key doesn't match any of the branch keys, then
we try the second branch of the outer choice. Which in this case is our
element C with no parens.



On 6/7/19 10:28 AM, Costello, Roger L. wrote:
> Hello DFDL community,
> 
> My input file has a number (num), followed by a comma-separated pair of 
> values, 
> enclosed within either round parentheses, square parentheses, or no 
> parentheses.
> 
>   * If num=1 then the initiator and terminator are rounded parentheses.
>   * If num=2 then the initiator and terminator are square parentheses.
>   * If num=3, 4, 5, … then there is no parentheses.
> 
> The below DFDL schema works for num=1, num=2, and num=3. But it is silent on 
> other values of num (4, 5, …). Is there a way to have a choiceBranchKey for 
> multiple values, e.g.,
> 
>                  dfdl:choiceBranchKey="3…infinity"
> 
> <xs:element name="input">
>      <xs:complexType>
>          <xs:sequence dfdl:separator="%NL;" dfdl:separatorPosition="infix">
>              <xs:element name="num" type="xs:integer" />
>              <xs:choice dfdl:choiceDispatchKey="{ ./num }">
>                  <xs:element name="A" type="xs:string"
>                                  dfdl:initiator="(" dfdl:terminator=")"
>                                  dfdl:choiceBranchKey="1" />
>                  <xs:element name="B" type="xs:string"
>                                  dfdl:initiator="[" dfdl:terminator="]"
>                                  dfdl:choiceBranchKey="2" />
>                  <xs:element name="C" type="xs:string"
>                                  dfdl:initiator="%WSP*;" 
> dfdl:terminator="%NL;"
>                                  dfdl:choiceBranchKey="3" />
>              </xs:choice>
>          </xs:sequence>
>      </xs:complexType>
> </xs:element>
> 

Reply via email to