Search code examples
xformsxsltforms

Insert a node based on boolean value


I have a XForm (in XSLTForms) where I have a checkbox (i.e. xf:input which has be binded to a xs:boolean type). Is it possible to (on submit) insert a node in my model based on the value of that checkbox?

To clarify, if I have the following model:

<xf:model>
    <xf:instance id="data">
        <data xmlns="">
            <element1/>
        </data>
    </xf:instance>
    <xf:instance id="helper">
        <data xmlns="">
            <bool1/>
        </data>
    </xf:instance>
    <xf:bind nodeset="instance('helper')/bool1" type="xs:boolean" />
</xf:model>

and this in my form:

<xf:input ref="instance('helper')/bool1" incremental="false">
    <xf:label>Some checkbox:</xf:label>
</xf:input>

I want to read the value of the checkbox and if it is true i need to insert a element2 node in my data instance. If it is false nothing is inserted. So if the checkbox is set I want to end with this:

<data xmlns="">
    <element1/>
    <element2/>
</data>

Solution

  • Instead of inserting element2 before submitting, it would be easier to declare it relevant according to the node associated to the checkbox and to restrict the submission to relevant nodes.

    -Alain