ref属性中的Orbeon动态xpath

时间:2013-02-19 13:04:28

标签: xml xpath orbeon

我有以下实例:

<xforms:instance id="fr-form-instance">
    <form>
        <section-1>
            <control-1>
                <en>Nothing special.</en>
                <ro>Nimic special.</ro>
            </control-1>
        </section-1>
    </form>
</xforms:instance>

我想添加一个输入来读取和编辑所选语言的值,如下所示:

...
<xhtml:td>
    <xforms:output value="instance('fr-form-instance')/section-1/control-1/*[name()=xxforms:lang()]"/>
    <xforms:input id="control-1-control" ref="instance('fr-form-instance')/section-1/control-1/*[name()=xxforms:lang()]"/>
</xhtml:td>
...

问题是输出文本正确显示,如果我更改语言,文本也会更改,但输入字段不会出现。如果我将xpath更改为使用[name()='ro']而不是[name()=xxforms:lang],则可以使用。 如何使其动态工作?

1 个答案:

答案 0 :(得分:0)

这似乎对我有用。我明白了:

enter image description here

从语言选择器中选择“română”时:

enter image description here

我已粘贴到表单的完整源代码下方,以防您想要重现此内容。我用Orbeon Forms 4.0进行了测试。

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

            <!-- Main instance -->
            <xf:instance id="fr-form-instance">
                <form>
                    <section-1>
                        <control-1>
                            <en>Nothing special.</en>
                            <ro>Nimic special.</ro>
                        </control-1>
                    </section-1>
                </form>
            </xf:instance>

            <!-- Bindings -->
            <xf:bind xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel" id="fr-form-binds"
                     ref="instance('fr-form-instance')">
                <xf:bind id="section-1-bind" name="section-1" ref="section-1">

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

            <!-- Metadata -->
            <xf:instance xxf:readonly="true" id="fr-form-metadata">
                <metadata>
                    <application-name>a</application-name>
                    <form-name>a</form-name>
                    <title xml:lang="en"/>
                    <description xml:lang="en"/>
                    <title xml:lang="ro"/>
                    <description xml:lang="ro"/>


                </metadata>
            </xf:instance>

            <!-- Attachments -->
            <xf:instance id="fr-form-attachments">
                <attachments>
                    <css mediatype="text/css" filename="" size=""/>
                    <pdf mediatype="application/pdf" filename="" size=""/>
                </attachments>
            </xf:instance>

            <!-- All form resources -->
            <!-- Don't make readonly by default in case a service modifies the resources -->
            <xf:instance id="fr-form-resources" xxf:readonly="false">
                <resources>
                    <resource xml:lang="en">
                        <section-1>
                            <label/>
                            <help/>
                        </section-1>

                    </resource>
                    <resource xml:lang="ro">
                        <section-1>
                            <label/>
                            <help/>
                        </section-1>

                    </resource>

                </resources>
            </xf:instance>

            <!-- Utility instances for services -->
            <xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
                <request/>
            </xf:instance>

            <xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all">
                <response/>
            </xf:instance>

        </xf:model>
    </xh:head>
    <xh:body>
        <fr:view>
            <fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
                     xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel"
                     xmlns:oxf="http://www.orbeon.com/oxf/processors"
                     xmlns:p="http://www.orbeon.com/oxf/pipeline">
                <fr:section id="section-1-control" bind="section-1-bind">
                    <xf:label ref="$form-resources/section-1/label"/>
                    <xf:help ref="$form-resources/section-1/help"/>
                    <fr:grid>
                        <xh:tr>
                            <xh:td>
                                <xf:output value="instance('fr-form-instance')/section-1/control-1/*[name()=xxforms:lang()]"/>
                                <xf:input id="control-1-control"
                                          ref="instance('fr-form-instance')/section-1/control-1/*[name()=xxforms:lang()]"/>
                            </xh:td>
                            <xh:td/>
                        </xh:tr>
                    </fr:grid>
                </fr:section>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>