【问题标题】:Fomat output of dollars and cents field in orbeonOrbeon 中美元和美分字段的格式输出
【发布时间】:2012-11-21 19:34:47
【问题描述】:

我如何指定要保存两个其他字段之和的字段应该能够以美元和美分的形式显示高于 $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>

【问题讨论】:

    标签: orbeon


    【解决方案1】:

    使用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

    【讨论】:

    • 谢谢你,Kaipa M Sama。您的回答和参考资料正是我所需要的。我不得不将 Dollars and Cents 控件更改为文本输出控件,因为该格式不适用于 Dollars and Cents (Currency) 控件。
    • 很高兴听到。如果您认为这是正确的答案,请采纳答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 2014-04-15
    • 2021-06-15
    相关资源
    最近更新 更多