我发现了一些与我的问题相关的问题(Orbeon index of repeat in repeatable section,Orbeon relevant properties和Orbeon nested repeats),但我无法让它们正常工作。
我定义了一个可重复的部分,里面有几个问题和一些相关的规则。我还定义了一些事件来管理问题的可见性。当我创建几个重复的组时出现问题。当我选择其中一个答案时,将针对具有相同xpath路径的所有问题启动相关规则和事件
所以,我的问题是:有没有办法管理相同的事件和可重复部分的相同相关规则?也就是说,我可以根据用户当前选择的部分的索引定义某种动态路由并在相关规则和事件中使用它吗?
示例中使用的完整代码如下:
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:saxon="http://saxon.sf.net/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude">
<xh:head>
<xh:meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<xh:title>Test_repeatable</xh:title>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>Test_app</application-name>
<form-name>Test_repeatable_v1</form-name>
<title xml:lang="en">Test_repeatable</title>
<description xml:lang="en">Description of the form.</description>
<singleton>false</singleton>
</metadata>
</xf:instance>
<xf:instance id="fr-form-instance">
<form>
<Category>
<Group>
<Group-iterator>
<Question/>
<Question2/>
<Question3/>
</Group-iterator>
</Group>
</Category>
</form>
</xf:instance>
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="Category-bind" name="Category" ref="/form/Category">
<xf:bind id="Group-bind" name="Group" ref="/form/Category/Group">
<xf:bind id="Group-iterator-bind" name="Group-iterator"
ref="/form/Category/Group/Group-iterator">
<xf:bind id="Question-bind" name="Question" ref="Question" required="true()"/>
<xf:bind id="Question2-bind"
name="Question2"
readonly="false"
ref="Question2"
relevant="/form/Category/Group/Group-iterator/Question='Answer'"
required="true()"/>
<xf:bind id="Question3-bind"
name="Question3"
readonly="false"
ref="Question3"
relevant="/form/Category/Group/Group-iterator/Question='Answer2' or instance('visible')/Group/Group-iterator/Question2 != 'false' "
required="true()"/>
</xf:bind>
</xf:bind>
</xf:bind>
</xf:bind>
<xf:instance id="fr-form-attachments">
<attachments>
<css filename="" mediatype="text/css" size=""/>
<pdf filename="" mediatype="application/pdf" size=""/>
</attachments>
</xf:instance>
<xf:instance id="fr-form-resources" xxf:readonly="false">
<resources>
<resource xml:lang="en">
<Category>
<label>Category</label>
<hint/>
<alert/>
<Group>
<label>Group</label>
<hint/>
<alert/>
<Question>
<label>Question</label>
<hint/>
<alert/>
<item>
<label>Answer</label>
<hint/>
<value>Answer</value>
</item>
<item>
<label>Answer2</label>
<hint/>
<value>Answer2</value>
</item>
</Question>
<Question2>
<label>Question2</label>
<hint/>
<alert/>
</Question2>
<Question3>
<label>Question3</label>
<hint/>
<alert/>
</Question3>
</Group>
</Category>
</resource>
</resources>
</xf:instance>
<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:instance xxf:readonly="true" id="Group-template">
<Group-iterator>
<Question/>
<Question2/>
<Question3/>
</Group-iterator>
</xf:instance>
<!-- Keep track of visible/hidden status -->
<xf:instance id="visible">
<visible>
<Category>0</Category>
<Group>
<Group-iterator>
<Question>false</Question>
<Question2>false</Question2>
<Question3>false</Question3>
</Group-iterator>
</Group>
</visible>
</xf:instance>
<!-- Change the visibility status for 'Question'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question-control"
ref="instance('visible')/Group/Group-iterator/Question"
value="'true'"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question-control"
ref="instance('visible')/Group/Group-iterator/Question"
value="'false'"/>
<!-- Update category showed elements count for 'Question'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question-control"
ref="instance('visible')/Category"
value="instance('visible')/Category + 1"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question-control"
ref="instance('visible')/Category"
value="instance('visible')/Category - 1"/>
<!-- Change the visibility status for 'Question2'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question2-control"
ref="instance('visible')/Group/Group-iterator/Question2"
value="'true'"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question2-control"
ref="instance('visible')/Group/Group-iterator/Question2"
value="'false'"/>
<!-- Update category showed elements count for 'Question2'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question2-control"
ref="instance('visible')/Category"
value="instance('visible')/Category + 1"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question2-control"
ref="instance('visible')/Category"
value="instance('visible')/Category - 1"/>
<!-- Change the visibility status for 'Question3'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question3-control"
ref="instance('visible')/Group/Group-iterator/Question3"
value="'true'"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question3-control"
ref="instance('visible')/Group/Group-iterator/Question3"
value="'false'"/>
<!-- Update category showed elements count for 'Question3'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question3-control"
ref="instance('visible')/Category"
value="instance('visible')/Category + 1"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question3-control"
ref="instance('visible')/Category"
value="instance('visible')/Category - 1"/>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:xbl="http://www.w3.org/ns/xbl"
xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel">
<fr:section bind="Category-bind"
id="Category-control">
<xf:label mediatype="text/html"
ref="instance('fr-form-resources')/resource/Category/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/alert"/>
<fr:section bind="Group-bind"
id="Group-control"
max="100"
min="1"
repeat="content"
template="instance('Group-template')">
<xf:label mediatype="text/html"
ref="instance('fr-form-resources')/resource/Category/Group/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/Group/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/Group/alert"/>
<xh:tr>
<xh:td>
<xf:select1 appearance="full" bind="Question-bind"
id="Question-control">
<xf:label mediatype="text/html"
ref="instance('fr-form-resources')/resource/Category/Group/Question/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/Group/Question/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/Group/Question/alert"/>
<xf:itemset
ref="instance('fr-form-resources')/resource/Category/Group/Question/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
<xf:hint ref="hint"/>
</xf:itemset>
</xf:select1>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<xf:input bind="Question2-bind"
id="Question2-control">
<xf:label mediatype="text/html"
ref="instance('fr-form-resources')/resource/Category/Group/Question2/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/Group/Question2/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/Group/Question2/alert"/>
</xf:input>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<xf:input bind="Question3-bind"
id="Question3-control">
<xf:label mediatype="text/html"
ref="instance('fr-form-resources')/resource/Category/Group/Question3/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/Group/Question3/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/Group/Question3/alert"/>
</xf:input>
</xh:td>
</xh:tr>
</fr:section>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>
编辑:对上述代码的一点解释 这个例子有两个部分,一个是正常的,另一个是可重复的。 在可重复部分内部有三个问题。第一个问题有两个答案。当我选择第一个答案时,表格选手必须显示问题二和三。当选择第二个答案时,跑步者必须只显示第三个问题。如果我只有一个可重复的部分,这可以正常工作 当我创建一个新的可重复部分时会出现问题。如果我选择第一个问题的答案之一,则在两个可重复的组中同时显示以下问题。当我选择答案2时也一样 所以问题是:有没有办法告诉Orbeon跑步者它必须只将相关规则应用于事件发生的可重复组?
编辑2:好的,您的解决方案在“问题2”的情况下工作正常。 问题3附带问题。如果您检查Question3的代码,您可以看到我尝试访问另一个实例:
relevant="$Question='Answer2' or instance('visible')/Group/Group-iterator/Question2 != 'false' "
'visible'实例与任何控件或绑定无关,仅用于存储问题的内部值,并使用xforms事件进行更新,如下面的代码所示:
<xf:setvalue ev:event="xforms-enabled"
observer="Question2-control"
ref="instance('visible')/Group/Group-iterator/Question2"
value="'true'"/>
因此,我的新问题是:有没有办法在静态实例中为可重复部分的不同迭代存储不同的值,并使用动态路径访问它们(就像在你的第一个响应中使用$)?
答案 0 :(得分:1)
如果在xf:bind
Question2
中想要在同一次迭代中引用Question
的值,则只需使用$Question
。事实上,根据经验,您始终可以将另一个控件gaga
的值称为$gaga
,并相信正确的事情会发生。 (至少在大多数情况下会如此。)因此,xf:bind
Question2
将成为:{/ p>
<xf:bind id="Question2-bind" name="Question2"
readonly="false" ref="Question2"
relevant="$Question='Answer'"
required="true()"/>