<xhtml:htmlxmlns: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:actionev:event="DOMActivate"><!-- Insert new row and populate id with max of exising ids + 1 --><xforms:insertnodeset="*"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:repeatnodeset="orange"id="orange-repeat"><xhtml:tr><xhtml:td><xforms:outputref="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:groupref="orange[index('orange-repeat')]"><xforms:inputref="type"><xforms:label>Orange type:</xforms:label></xforms:input><xforms:inputref="id"><xforms:label>Orange id:</xforms:label></xforms:input></xforms:group></xhtml:body></xhtml:html>