Hello DFDL community,

My input file has a number (num), followed by a comma-separated pair of values, 
enclosed within either round parentheses or square parentheses. If num=1 then 
the initiator and terminator are rounded parentheses. If num=2 then the 
initiator and terminator are square parentheses.

Below are two solutions to the problem. The first solution dynamically computes 
the initiator and terminator. The second solution uses a choice with 
dfdl:initiatedContent="yes".

Which solution is better?

Solution #1 Dynamically Compute initiator and terminator

<xs:element name="input">
    <xs:complexType>
        <xs:sequence dfdl:separator="%NL;" dfdl:separatorPosition="infix">
            <xs:element name="num" type="xs:integer" />
            <xs:sequence dfdl:initiator="{if (num eq 1) then '(' else '[' }"
                dfdl:terminator="{if (num eq 1) then ')' else ']' }"
                dfdl:separator="," dfdl:separatorPosition="infix">
                <xs:element name="A" type="xs:string" />
                <xs:element name="B" type="xs:string" />
            </xs:sequence>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Solution #2 Choice with initiatedContent="yes"

<xs:element name="input">
    <xs:complexType>
        <xs:sequence dfdl:separator="%NL;" dfdl:separatorPosition="infix">
            <xs:element name="num" type="xs:integer" />
            <xs:choice dfdl:initiatedContent="yes">
                <xs:element name="A" type="xs:string" dfdl:initiator="(" 
dfdl:terminator=")" />
                <xs:element name="B" type="xs:string"  dfdl:initiator="[" 
dfdl:terminator="]" />
            </xs:choice>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Reply via email to