【问题标题】:Sorted and grouped data table in XFormsXForms 中的排序和分组数据表
【发布时间】:2011-05-09 14:10:39
【问题描述】:

我正在使用 Orbeon 表单运行程序来执行一些 XForms 文档。我想管理一个条目列表来做一些时间跟踪。我正在使用 xforms:repeat 使用我的数据生成一个表,并使用 xforms:trigger 和 xforms:insert 来插入新条目。现在我想按日期对条目进行排序并按月份对条目进行分组,如下图所示:

Grouped table example

我想计算每个月的总小时数。有人可以提示如何使用 XForms/Orbeon 构建它,是否有一个工作示例正在做类似的事情?

谢谢!

【问题讨论】:

    标签: xforms orbeon


    【解决方案1】:

    这是一个执行一些类似分组以输出以下内容的示例:

    • 2011 年 5 月
      • 2011-05-10:荷马
      • 2011-05-09:丽莎
    • 2011 年 4 月
      • 2011-04-07:巴特
      • 2011-04-05:巴特
      • 2011-04-02:丽莎

    这与您在屏幕截图中的内容不完全一样,但应该让您对如何进行此分组有一个足够好的了解。

    <xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
          xmlns:xforms="http://www.w3.org/2002/xforms"
          xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
          xmlns:ev="http://www.w3.org/2001/xml-events"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
        <xhtml:head>
            <xhtml:title>Timesheet</xhtml:title>
            <xforms:model>
                <xforms:instance>
                    <instance>
                        <entry>
                            <start>2011-05-10</start>
                            <person>Homer</person>
                        </entry>
                        <entry>
                            <start>2011-05-09</start>
                            <person>Lisa</person>
                        </entry>
                        <entry>
                            <start>2011-04-07</start>
                            <person>Bart</person>
                        </entry>
                        <entry>
                            <start>2011-04-05</start>
                            <person>Bart</person>
                        </entry>
                        <entry>
                            <start>2011-04-02</start>
                            <person>Lisa</person>
                        </entry>
                    </instance>
                </xforms:instance>
            </xforms:model>
            <xhtml:style type="text/css">
                .xforms-repeat-selected-item-1, .xforms-repeat-selected-item-2 { background: transparent }
            </xhtml:style>
        </xhtml:head>
        <xhtml:body>
            <xxforms:variable name="entries" select="entry"/>
            <xxforms:variable name="months" select="distinct-values($entries/start/substring(., 1, 7))"/>
            <xhtml:ul>
                <xforms:repeat nodeset="$months">
                    <xxforms:variable name="current-month" select="."/>
                    <xhtml:li>
                        <xforms:output value="format-date(xs:date(concat(., '-01')), '[MNn] [Y]')"/>
                        <xhtml:ul>
                            <xforms:repeat nodeset="$entries[substring(start, 1, 7) = $current-month]">
                                <xhtml:li>
                                    <xforms:output ref="start"/>:
                                    <xforms:output ref="person"/>
                                </xhtml:li>
                            </xforms:repeat>
                        </xhtml:ul>
                    </xhtml:li>
                </xforms:repeat>
            </xhtml:ul>
        </xhtml:body>
    </xhtml:html>
    

    【讨论】:

    • 感谢您的回答,您的榜样让我向前迈出了一大步!我还有两个问题:(1) 在我的示例中,我有一个开始和结束时间 (xs:time)。我想计算 xforms:output 中 (xs:time(end) - xs:time(start)) 之间的小时数,我该怎么做? xforms/xpath 中的时间计算似乎很奇怪... (2) 是否可以对所有$entries 进行排序?用户可以按任意顺序输入日期,因此 2011 年 5 月可能会在 2011 年 6 月之后。
    • 如果两个dateTime之间的时间不足1个月,您可以使用以下公式计算它们之间的小时数。请注意,我在这里通过声明两个变量$t1$t2 来启动表达式;通常您会引用包含此信息的节点。 for $t1 in '2011-05-12T13:24:20.929-07:00', $t2 in '2011-05-13T17:56:20.929-07:00' return for $d in xs:dateTime($t2) - xs:dateTime($t1) return days-from-duration($d)*24 + hours-from-duration($d)
    猜你喜欢
    • 2021-10-31
    • 2020-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-28
    相关资源
    最近更新 更多