开发者

Sorted and grouped data table in XForms

I am using Orbeon form runner to execute some XForms documents. I would like to manage a list of entries to do some time tracking. I am using xforms:repeat to generate a table with my data and xforms:trigger with xforms:insert to insert new entries. Now I would like to sort the entries by date and group the entries by month, as seen in the following picture:

Grouped table example

For each month I would like to calculate the total hours. Can somebody give a hint how to build this with XForms/ Orbeon, is t开发者_运维百科here a working example out there that is doing something similar?

Thank you!


Here is an example that does some similar grouping to output the following:

  • May 2011
    • 2011-05-10: Homer
    • 2011-05-09: Lisa
  • April 2011
    • 2011-04-07: Bart
    • 2011-04-05: Bart
    • 2011-04-02: Lisa

It is not exactly what you have in your screenshot, but should give you a good enough idea of how to do this grouping.

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜