代码之家  ›  专栏  ›  技术社区  ›  developer

可以从XForms中的用户输入为两个不同的节点设置两个值吗?

  •  1
  • developer  · 技术社区  · 15 年前

    我想从XForms中的用户输入为两个不同的节点设置两个值。如果可能的话,我很好奇这是怎么做到的。

    例如,如果我有以下数据模型:

    <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"/>
    

    我的用户界面代码如下:

    <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>    
    

    但我本质上希望它是这样的(尽管这是无效的,根本不生成任何XML):

    <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>    
    

    我要实现的XML输出(如果用户选中“bbb”):

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

    如何为一个复选框选择设置这两个节点?

    希望一切都有意义…

    谢谢!:)

    2 回复  |  直到 15 年前
        1
  •  0
  •   Alain Couthures    15 年前

    您应该声明要在事件“xforms select”上执行的特定操作,例如“xf:setvalue”。

    阿兰

        2
  •  0
  •   Tambet    15 年前

    您还可以使用计算:

    <xf:bind nodeset="instance('criteria_data')/criteria/set/root" calculate="instance
    ('choices')/choice[. = instance('criteria_data')/criteria/set/criterion]/../root">