Possible to set two values for two different nodes from user input in XForms?

Posted by iHeartGreek on Stack Overflow See other posts from Stack Overflow or by iHeartGreek
Published on 2010-06-10T19:28:39Z Indexed on 2010/06/10 20:32 UTC
Read the original article Hit count: 222

Filed under:
|
|
|

Hi!

I would like to set two values for two different nodes from user input in XForms. I am curious about how this is done, if at all possible.

For example, if I have the following data model:

<xf:instance id="criteria_data" xmlns="">
    <criteria>
        <set>
           <root></root>
           <criterion></criterion>
        </set>
    </criteria>
</xf:instance>

<xf:instance id="choices" xmlns="">
    <choices>
        <root label="The Choices">/AAA</root>
        <choice label="BBB">/@BBB</choice>
    </choices>
</xf:instance>

<xf:instance id="choices" xmlns="">
    <choices>
        <root>/AAA</root>
        <choice label="BBB">/@BBB</choice>
        <choice label="CCC">/@CCC</choice>
    <choices>
</xf:instance>

<xf:bind id="data_criterion" nodeset="instance('criteria_data')/criteria/set/criterion"/>         
<xf:bind id="data_root" nodeset="instance('criteria_data')/criteria/set/root"/>
<xf:bind id="choices_root" nodeset="instance('choices')/root"/>
<xf:bind id="choices" nodeset="instance('choices')/choice"/>

and my ui code looks like:

<xf:select bind="data_criterion" appearance="full">
    <xf:label>Your choices:</xf:label>    
    <xf:itemset bind="choices">
       <xf:label ref="@label"></xf:label>
       <xf:value ref="."></xf:value>
    </xf:itemset>
</xf:select>    

But I essentially want it to be like this (though this is invalid and does not produce any xml at all):

<xf:select appearance="full">
    <xf:label>Your choices:</xf:label>    
    <xf:itemset bind="choices">
        <xf:label ref="@label"></xf:label>
        <xf:value bind="data_criterion" ref="."></xf:value>
        <xf:value bind="data_root" ref="instance('choices')/root"></xf:value>
    </xf:itemset>
</xf:select>    

The XML output I want to achieve (if user checks "BBB"):

<criteria>
    <set>
       <root>/AAA</root>
       <criterion>/@BBB</criterion>
    </set>
</criteria>

How can I achieve setting these two nodes for the one checkbox seletion?

Hope that all made sense...

Thanks! :)

© Stack Overflow or respective owner

Related posts about Xml

Related posts about binding