我正在编写一个表单(betterFORMs/Xforms),通过选中的复选框显示给用户。如果复选框为空,表单应将"N“绑定到元素中。当滴答声中,"Y“。我意识到这个问题已经有答案了,但我已经尝试了所有答案,但没有运气。
我尝试使用的第一个解决方案是 here - stackoverflow link
(第一个解决方案看起来不错,但我在解决方案2方面取得了更大的成功,因为我没有使用Orbeon)
给出的答案是我正在寻找的,但我在实现这一点在我的形式有困难。我不使用Xhtml或Orbeon,因此我使用的绑定似乎与解决方案中使用的绑定不同。)我尝试过调整这些代码以适应我的表单,但是每次加载页面时,我都会从xml解析器那里得到一个重复的错误--但是它并没有指向与新代码相关的任何地方。
我尝试过的下一个解决方案是找到 here - stackoverflow link
这个答案在我的代码中得到了最好的结果,因为复选框值在不使用和被取消选中时更改为N。这个解决方案的问题是form元素中的Y集包含在大括号中- []。
输出示例:
<addressProof>N</addressProof><other>[Y]</other><otherText>_text_</otherText>下面是我表单的一个片段:
模型:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns="http://www.w3.org/2002/06/xhtml2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
<xsl:output method="xml" />
<xsl:template match="/">
<xforms:model id="documentsChecklist">
<xforms:instance>
<actionform xmlns="">
<xforms:model id="documentsChecklist">
<xforms:instance>
<actionform xmlns="">
<detail>
<other></other>
<otherText></otherText>
</detail>
</actionform>
</xforms:instance>
<xforms:bind id="other" nodeset="/actionform/detail/other" calculate="choose(. = 'Y', ., 'N')"/>
<xforms:bind nodeset="/actionform/detail/otherBox" relevant="/actionform/detail/other ='Y'" />
</xforms:model> 表格:
<div id="formBody"><br />
<xforms:select bind="other" appearance="full" align="right">
<xforms:item>
<xforms:label>Other</xforms:label>
<xforms:value>Y</xforms:value>
</xforms:item>
</xforms:select>
<xforms:input ref="/actionform/detail/otherText">
<xforms:label>Please specify:*</xforms:label>
</xforms:input>
</div>
</xsl:template>
</xsl:stylesheet>为什么复选框值现在被设置为"Y“而不是"Y"?(这是否与数组有关?)谢谢。
PS。我知道我可以为每个复选框使用一个布尔值,并使用对应于布尔值的复选框值,后者反过来更新绑定值。我不希望有大量的布尔元素和绑定块,因为我有大量的复选框。此解决方案有一个示例here - stackoverflow link
发布于 2014-01-04 07:50:21
select控件允许您选择多个项,我不知道这是否是您使用的XForms实现添加方括号的原因(根据所选值的规范,必须用空格字符分隔,顺便说一句,这并不总是非常方便)。
恐怕XForms 1.1和XForms 2.0需要使用额外的中间节点和绑定。能够为绑定添加两个XPath表达式是有用的:一个将节点值转换为控制值,另一个将控制值转换为节点值。
作为解决办法,我在XSLTForms中使用了另一个扩展:用于转换实例的XSLT样式表。
-Alain
https://stackoverflow.com/questions/20908491
复制相似问题