Orbeon动态下拉列表链接到另一个字段

时间:2018-01-01 05:45:49

标签: orbeon xforms

使用表单生成器对示例动态下拉列表示例的变体,如何将下拉列表引用到另一个字段的值。我可以进行调试'使用../pet更改文本字段,但项目[@ group = context()/../ pet]未按预期工作。

注意:' petnames'包含模型,但我无法在内部引用它,因此我引用了相同格式的外部XML文件。

<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
         xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
         xmlns:ev="http://www.w3.org/2001/xml-events"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         xmlns:saxon="http://saxon.sf.net/"
         xmlns:xs="http://www.w3.org/2001/XMLSchema"
         xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
         xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
         xmlns:sql="http://orbeon.org/oxf/xml/sql"
         xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
         xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
         xmlns:xf="http://www.w3.org/2002/xforms"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:exf="http://www.exforms.org/exf/1-0"
         fr:data-format-version="4.0.0">
    <xh:head>
        <xh:title>Example Dynamic data dropdown</xh:title>
        <xf:model id="fr-form-model" xxf:expose-xpath-types="true">

            <!-- Main instance -->
            <xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
                <form>
                    <section-1>
                        <pet/>
                        <control-4/>
                        <mypetname itemset-empty="true"/>

                    </section-1>
                </form>
            </xf:instance>

            <xf:instance id="petnames">
                <root>
                    <item group="cat" value="Kitty"/>
                    <item group="cat" value="Garfield"/>
                    <item group="dog" value="Spot"/>
                    <item group="dog" value="Rover"/>
                    <item group="fish" value="Bubbles"/>
                    <item group="fish" value="Bob"/>
                    <item group="cobra" value="King"/>
                    <item group="cobra" value="Shelby"/>
                </root>
            </xf:instance>

            <!-- Bindings -->
            <xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
                <xf:bind id="section-1-bind" name="section-1" ref="section-1">
                    <xf:bind id="pet-bind" ref="pet" name="pet"/>
                    <xf:bind id="mypetname-bind" ref="mypetname" name="mypetname"/>
                    <xf:bind id="control-4-bind" ref="control-4" name="control-4" xxf:whitespace="trim"
                             calculate="../pet"/>

                </xf:bind>
            </xf:bind>

            <!-- Metadata -->
            <xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
                <metadata>
                    <application-name>samples</application-name>
                    <form-name>DynamicDataDropdown</form-name>
                    <title xml:lang="en">Example Dynamic data dropdown</title>
                    <description xml:lang="en"/>
                </metadata>
            </xf:instance>

            <!-- Attachments -->
            <xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
                <attachments>
                    <css mediatype="text/css" filename="" size=""/>
                    <pdf mediatype="application/pdf" filename="" size=""/>
                </attachments>
            </xf:instance>

            <!-- All form resources -->
            <xf:instance xxf:readonly="true" id="fr-form-resources" xxf:exclude-result-prefixes="#all">
                <resources>
                    <resource xml:lang="en">
                        <pet>
                            <label>Pick a pet</label>
                            <hint/>
                            <item>
                                <label>Cat</label>

                                <value>cat</value>
                            </item>
                            <item>
                                <label>Dog</label>

                                <value>dog</value>
                            </item>
                            <item>
                                <label>Fish</label>

                                <value>fish</value>
                            </item>
                            <item>
                                <label>Cobra</label>

                                <value>cobra</value>
                            </item>
                        </pet>
                        <control-4>
                            <label>debug</label>
                            <hint/>
                        </control-4>
                        <mypetname>
                            <label>Your pet names</label>
                            <hint/>
                        </mypetname>
                        <section-1>
                            <label>Untitled Section</label>
                        </section-1>

                    </resource>
                </resources>
            </xf:instance>
        </xf:model>
    </xh:head>
    <xh:body>
        <fr:view>
            <fr:body xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xbl="http://www.w3.org/ns/xbl"
                     xmlns:oxf="http://www.orbeon.com/oxf/processors">
                <fr:section id="section-1-control" bind="section-1-bind">
                    <xf:label ref="$form-resources/section-1/label"/>
                    <fr:grid>
                        <xh:tr>
                            <xh:td>
                                <xf:select1 id="pet-control" bind="pet-bind" appearance="dropdown">
                                    <xf:label ref="$form-resources/pet/label"/>
                                    <xf:hint ref="$form-resources/pet/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>


                                    <xf:itemset ref="$form-resources/pet/item">
                                        <xf:label ref="label"/>
                                        <xf:value ref="value"/>
                                    </xf:itemset>
                                </xf:select1>

                            </xh:td>
                            <xh:td>
                                <xf:input id="control-4-control" bind="control-4-bind">
                                    <xf:label ref="$form-resources/control-4/label"/>
                                    <xf:hint ref="$form-resources/control-4/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>


                                </xf:input>
                            </xh:td>
                            <xh:td>
                                <fr:databound-select1 xmlns="http://orbeon.org/oxf/xml/form-builder"
                                                      xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
                                                      id="mypetname-control"
                                                      resource="http://192.168.0.80/petnames.xml"
                                                      bind="mypetname-bind">
                                    <xf:label ref="$form-resources/mypetname/label"/>
                                    <xf:hint ref="$form-resources/mypetname/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>


                                    <xf:itemset ref="/root/item[@group=context()/../pet]">
                                        <xf:label ref="@value"/>
                                        <xf:value ref="@value"/>
                                    </xf:itemset>
                                </fr:databound-select1>
                            </xh:td>
                        </xh:tr>
                    </fr:grid>
                </fr:section>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>

1 个答案:

答案 0 :(得分:0)

您可以使用以下内容:

<xf:itemset ref="/root/item[@group = xxf:instance('fr-form-instance')/section-1/pet]">

在这种情况下,context()将无效,因为ref中的XPath表达式是在XBL组件内部进行评估的,并且无法访问组件外部的内容。但是,在某些情况下,打破封装很有用,对于这些情况,扩展函数xxf:instance()允许您这样做。