Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    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">

    <xhtml:head>
        <xhtml:title>Simple Master-Detail</xhtml:title>
        <xforms:model>
            <xforms:instance>
                <oranges>
                    <orange><type>Persian</type><id>1</id></orange>
                    <orange><type>Navel</type><id>2</id></orange>
                    <orange><type>Valencia</type><id>3</id></orange>
                    <orange><type>Blood</type><id>4</id></orange>
                </oranges>
            </xforms:instance>
        </xforms:model>
    </xhtml:head>
    <xhtml:body>

        <!-- Button to add a row after currently selected row -->
        <xforms:trigger>
            <xforms:label>Add</xforms:label>
            <xforms:action ev:event="DOMActivate">
                <!-- Insert new row and populate id with max of exising ids + 1 -->
                <xforms:insert nodeset="*" at="index('orange-repeat')"
                               origin="xxforms:element('orange',
                                            (xxforms:element('type'),
                                             xxforms:element('id', max(for $n in /*/orange/id[. castable as xs:integer] return xs:integer($n)) + 1)))"/>
            </xforms:action>
        </xforms:trigger>

        <xhtml:h2>Master</xhtml:h2>

        <xhtml:table>
            <xforms:repeat nodeset="orange" id="orange-repeat">
                <xhtml:tr>
                    <xhtml:td>
                        <xforms:output ref="type">
                            <xforms:label>Orange type:</xforms:label>
                        </xforms:output>
                    </xhtml:td>
                </xhtml:tr>
            </xforms:repeat>
        </xhtml:table>

        <xhtml:hr/>

        <xhtml:h2>Detail</xhtml:h2>

        <xforms:group ref="orange[index('orange-repeat')]">
            <xforms:input ref="type">
                <xforms:label>Orange type:</xforms:label>
            </xforms:input>
            <xforms:input ref="id">
                <xforms:label>Orange id:</xforms:label>
            </xforms:input>
        </xforms:group>

    </xhtml:body>

</xhtml:html>