Search code examples
orbeonxforms

How to implement case/switch in xforms


I have got xsd with choice statement

<xs:complexType name="opt_type">
    <xs:choice>
        <xs:element name="opt_1_1" minOccurs="0">
            <xs:simpleType>
                <xs:restriction base="xsd:string">
                    <xs:enumeration value="opt_1_1 value 1"/>
                    <xs:enumeration value="opt_1_1 value 2"/>
                    <xs:enumeration value="opt_1_1 value 3"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="opt_1_2" minOccurs="0">
            <xs:simpleType>
                <xs:restriction base="xsd:string">
                    <xs:enumeration value="opt_1_2 value"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="opt_1_3" minOccurs="0">   
            <xs:simpleType>
                <xs:restriction base="xsd:string">
                    <xs:enumeration value="opt_1_3 value"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
    </xs:choice>
</xs:complexType>

...

<xs:element name="opt" maxOccurs="unbounded">
    <xs:complexType>
        <xs:sequence>
            ...
            <xs:element name="opt_1" type="myns:opt_type" minOccurs="0"></xs:element>
            ...
        </xs:sequence>
    </xs:complexType>
</xs:element>

I need xforms (I'm working with Orbeon), which will give me, depending on users choice, xml with nodes like those:

<myns:opt_1>
    <myns:opt_1_1>opt_1_1 value 1</myns:opt_1_1> 
</myns:opt_1>

or

<myns:opt_1>
    <myns:opt_1_1>opt_1_1 value 2</myns:opt_1_1> 
</myns:opt_1>

or

<myns:opt_1>
    <myns:opt_1_1>opt_1_1 value 3</myns:opt_1_1> 
</myns:opt_1>

or

<myns:opt_1>
    <myns:opt_1_2>opt_1_2 value</myns:opt_1_1> 
</myns:opt_1>

or

<myns:opt_1>
    <myns:opt_1_3>opt_1_3 value</myns:opt_1_1> 
</myns:opt_1>

How can I achieve that? How should xforms be constructed?


Solution

  • In short you want to change the structure of the XML (using different element names). To do this, your tools should be actions using xf:insert and xf:delete, to insert and delete elements. You need to do this "by hand", as the XForms engine will not do this for you automatically based on the schema.