在orbeon中格式化美元和美分字段的输出

时间:2012-11-21 19:34:48

标签: orbeon

我如何指定保存两个其他字段之和的字段应该能够显示高于$ 999.999.99的值作为美元和美分?

表格的源代码如下。

当我测试表单时,我在amount_1中输入999999.99并显示$ 999,999.99。我在amount_2输入.01。 total_amount字段显示$ 1.0E。我希望它显示$ 1,000,000.00并且给出错误或不正确的值错误。

我尝试过使用文本输出控件,但遇到了同样的问题。

我正在编写一个使用Form Runner从银行代理请求数据的银行应用程序,因此浮点字段不够准确。

我看了几篇与输出效果相关的帖子,但没有看到任何帮助。我正在使用各种数据类型的默认输出格式。

感谢您的帮助。

<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
        xmlns:xforms="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:xxforms="http://orbeon.org/oxf/xml/xforms"
        xmlns:exforms="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/">
<xhtml:head>
    <xhtml:title>Format Test Form</xhtml:title>
    <xforms:model id="fr-form-model">

        <!-- Main instance -->
        <xforms:instance id="fr-form-instance">
            <form>
                <section-1>
                    <amount_1/>
                    <amount_2/>
                    <total_amount/>

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

        <!-- Bindings -->
        <xforms:bind id="fr-form-binds" nodeset="instance('fr-form-instance')">
            <xforms:bind id="section-1-bind" nodeset="section-1">
                <xforms:bind id="amount_1-bind" nodeset="amount_1" type="xforms:decimal" name="amount_1"/>
                <xforms:bind id="amount_2-bind" nodeset="amount_2" type="xforms:decimal" name="amount_2"/>
                <xforms:bind id="total_amount-bind" nodeset="total_amount" name="total_amount"
                             type="xforms:decimal"
                             calculate="if ($amount_1 castable as xs:double and $amount_2 castable as xs:double) then $amount_1 + $amount_2 else 123456789012345"/>

            </xforms:bind>
        </xforms:bind>

        <!-- Metadata -->
        <xforms:instance id="fr-form-metadata" xxforms:readonly="true">
            <metadata>
                <application-name>BusTravelApp</application-name>
                <form-name>FormatTestForm</form-name>
                <title xml:lang="en">Format Test Form</title>
                <description xml:lang="en"/>
                <author/>
                <logo mediatype="" filename="" size=""/>
            </metadata>
        </xforms:instance>

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

        <!-- All form resources -->
        <!-- Don't make readonly by default in case a service modifies the resources -->
        <xforms:instance id="fr-form-resources" xxforms:readonly="false">
            <resources>
                <resource xml:lang="en">
                    <amount_1>
                        <label>Amount 1</label>
                        <hint/>
                        <help/>
                        <alert/>
                    </amount_1>
                    <amount_2>
                        <label>Amount 2</label>
                        <hint/>
                        <help/>
                        <alert/>
                    </amount_2>
                    <total_amount>
                        <label>Total Amount</label>
                        <hint/>
                        <help/>
                        <alert/>
                    </total_amount>
                    <section-1>
                        <label>Section-1</label>
                        <help/>
                    </section-1>

                </resource>
            </resources>
        </xforms:instance>

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

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

    </xforms:model>
</xhtml:head>
<xhtml:body>
    <fr:view>
        <xforms:label ref="instance('fr-form-metadata')/title"/>
        <fr:body>
            <fr:section id="section-1-section" bind="section-1-bind">
                <xforms:label ref="$form-resources/section-1/label"/>
                <xforms:help ref="$form-resources/section-1/help"/>
                <fr:grid columns="3">
                    <xhtml:tr>
                        <xhtml:td>
                            <fr:currency xmlns="http://orbeon.org/oxf/xml/form-builder"
                                         xmlns:exf="http://www.exforms.org/exf/1-0"
                                         xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
                                         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                         xmlns:oxf="http://www.orbeon.com/oxf/processors"
                                         xmlns:xbl="http://www.w3.org/ns/xbl"
                                         xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
                                         xmlns:pipeline="java:org.orbeon.oxf.processor.pipeline.PipelineFunctionLibrary"
                                         bind="amount_1-bind"
                                         id="amount_1-control">
                                <xforms:label ref="$form-resources/amount_1/label"/>
                                <xforms:hint ref="$form-resources/amount_1/hint"/>
                                <xforms:help ref="$form-resources/amount_1/help"/>
                                <xforms:alert ref="$fr-resources/detail/labels/alert"/>
                            </fr:currency>

                        </xhtml:td>
                        <xhtml:td>
                            <fr:currency xmlns="http://orbeon.org/oxf/xml/form-builder"
                                         xmlns:exf="http://www.exforms.org/exf/1-0"
                                         xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
                                         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                         xmlns:oxf="http://www.orbeon.com/oxf/processors"
                                         xmlns:xbl="http://www.w3.org/ns/xbl"
                                         xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
                                         xmlns:pipeline="java:org.orbeon.oxf.processor.pipeline.PipelineFunctionLibrary"
                                         bind="amount_2-bind"
                                         id="amount_2-control">
                                <xforms:label ref="$form-resources/amount_2/label"/>
                                <xforms:hint ref="$form-resources/amount_2/hint"/>
                                <xforms:help ref="$form-resources/amount_2/help"/>
                                <xforms:alert ref="$fr-resources/detail/labels/alert"/>
                            </fr:currency>
                        </xhtml:td>
                        <xhtml:td>
                            <fr:currency xmlns="http://orbeon.org/oxf/xml/form-builder"
                                         xmlns:exf="http://www.exforms.org/exf/1-0"
                                         xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
                                         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                         xmlns:oxf="http://www.orbeon.com/oxf/processors"
                                         xmlns:xbl="http://www.w3.org/ns/xbl"
                                         xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
                                         xmlns:pipeline="java:org.orbeon.oxf.processor.pipeline.PipelineFunctionLibrary"
                                         id="total_amount-control"
                                         bind="total_amount-bind">
                                <xforms:label ref="$form-resources/total_amount/label"/>
                                <xforms:hint ref="$form-resources/total_amount/hint"/>
                                <xforms:help ref="$form-resources/total_amount/help"/>
                                <xforms:alert ref="$fr-resources/detail/labels/alert"/>
                            </fr:currency>
                        </xhtml:td>
                    </xhtml:tr>
                </fr:grid>
            </fr:section>
        </fr:body>
    </fr:view>
</xhtml:body>

1 个答案:

答案 0 :(得分:0)

使用xforms:output并使用格式化这样的值。

<xforms:output bind="total_amount-bind" xxforms:format="format-number(., $ ###,###.##)" />

参考文献: http://wiki.orbeon.com/forms/doc/developer-guide/xforms-other-extensions#TOC-The-xxforms:format-attribute

http://www.w3schools.com/xsl/func_formatnumber.asp