2

我正在编写一个表单(betterFORMs/Xforms),通过选择复选框向用户显示。如果复选框为空,则表单应将“N”绑定到元素中。勾选时,一个“Y”。我意识到这个问题已经有了答案,但我已经尝试了所有已回答的解决方案,但没有运气。

我尝试使用的第一个解决方案 在这里 - stackoverflow 链接

(第一个解决方案看起来不错,但我在解决方案 2 上取得了更大的成功,因为我没有使用 Orbeon)

给出的答案是我正在寻找的,但我无法在我的表单中实现它。我没有使用 Xhtml 或 Orbeon,因此我使用的绑定似乎与解决方案中使用的不同。)我尝试调整此代码以适合我的表单,但每次加载时我都会从 xml 解析器中收到重复错误该页面 - 但它并没有指向与新代码相关的任何地方。

我尝试过的下一个解决方案在 这里找到 - stackoverflow 链接

这个答案在我的代码中得到了最好的结果,因为复选框值在不使用和取消选择时会更改为 N。我对这个解决方案的问题是表单元素中设置的 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。我知道我可以为每个复选框使用一个布尔值来做到这一点,复选框值对应于布尔值,这反过来会更新绑定值。我宁愿不必有一大块布尔元素和绑定,因为我有大量的复选框。这个解决方案在这里有一个例子- stackoverflow 链接

4

1 回答 1

2

选择控件允许您选择多个项目,我想知道这是否是您使用的 XForms 实现添加方括号的原因(根据规范,选择的值必须用空格字符分隔,这并不总是很方便道路)。

恐怕 XForms 1.1 和 XForms 2.0 需要使用额外的中间节点和绑定。能够为绑定添加 2 个 XPath 表达式会很有用:一个将节点值转换为控制值,另一个从控制值转换回节点值。

作为一种解决方法,我在 XSLTForms 中使用了另一个扩展:用于转换实例的 XSLT 样式表。

-阿兰

于 2014-01-04T07:50:21.547 回答