Thanks Mike. That is a great example of using a discriminator in an array!

But, but, but, ....

Yesterday you recommended using dfdl:occursCountKind="expression" rather than 
discriminators in an array. I am seeking an example to illustrate your 
recommendation.

I think that I created an example. The below DFDL schema uses a discriminator 
in an array. It would be better implemented using 
dfdl:occursCountKind="expression". Do you agree?

<xs:element name="name" type="xs:string" maxOccurs="unbounded">
    <xs:annotation>
        <xs:appinfo source="http://www.ogf.org/dfdl/";>
            <dfdl:discriminator test="{ fn:exists(.) }" />
        </xs:appinfo>
    </xs:annotation>
</xs:element>


From: Beckerle, Mike <[email protected]>
Sent: Tuesday, October 8, 2019 11:21 AM
To: [email protected]
Subject: [EXT] Re: How to use dfdl:discriminator with an array?

I have a super example:

In the mil-std-2045 schema (which is public, on github), there is a fantastic 
very non-trivial discriminator.

Line 141 of milstd2045_application_header.dfdl.xsd

<xs:element maxOccurs="unbounded" minOccurs="1" name="recipient_address_group"
            dfdl:lengthKind="implicit" dfdl:occursCountKind="implicit">
            <xs:complexType>
              <xs:sequence>
                <xs:sequence>
                  <xs:annotation>
                    <xs:appinfo source="http://www.ogf.org/dfdl/";>
                      <dfdl:discriminator>{ if (dfdl:occursIndex() eq 1) then
                        fn:true() else
                        ../recipient_address_group[dfdl:occursIndex()-1]/GRI
                        eq 1 }
                      </dfdl:discriminator>
                    </xs:appinfo>
                  </xs:annotation>
                </xs:sequence>
               .... rest of the element contents ...
</xs:element>


This discriminator says: look at the GRI flag in the prior element. If true 
then this element exists!

These array elements are repeating, but each has a flag that indicates whether 
this is the last element of the array, or there is (at least) one more after 
this. Such an array always has at least one element, but then each element 
tells you if the next one will be present or not.

This is not a discriminator you can replace by any sort of one-time expression. 
It has to be done as a discriminator, evaluated one by one as each array 
element is created.

...mikeb

________________________________
From: Costello, Roger L. <[email protected]<mailto:[email protected]>>
Sent: Tuesday, October 8, 2019 10:39 AM
To: [email protected]<mailto:[email protected]> 
<[email protected]<mailto:[email protected]>>
Subject: How to use dfdl:discriminator with an array?


Hello DFDL community,



Yesterday Mike said this:



  *   A dfdl:discriminator says if something is true, then ... optional/array 
uncertainty is closed off, and no longer uncertain.
  *   I avoid using discriminators because I find ... for optional/array 
elements using dfdl:occursCountKind="expression" are superior.



Would you provide an example of using dfdl:discriminator with an 
optional/array, please?



/Roger

Reply via email to