<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../xsltforms/xsltforms.xsl" type="text/xsl"?> 
<?xsltforms-options debug="no"?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://www.w3.org/1999/xhtml"
      xmlns:xf="http://www.w3.org/2002/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<head>
	<title>Expenses</title>
	<style type="text/css">
	body { font-family: sans-serif}
	.h {background: blue; color: white}
	.strong {font-weight: bold}
        .xforms-repeat-item-selected { background: yellow}
	label { display: inline-block; width: 4em; margin: 0 0.5em; text-align: right }
	</style> 
	<model xmlns="http://www.w3.org/2002/xforms">
	    <instance src="amounts.xml"/>
	    <instance src="currencies.xml" id="currencies"/>

	    <bind nodeset="total"
                   calculate="sum(../declarations/item/home)"/>
	    <bind nodeset="declarations/item/date"
                   type="xsd:date"/>
	    <bind nodeset="declarations/item/amount"
		   type="xsd:decimal"/>
	    <bind nodeset="declarations/item/home"
		   calculate="../amount * ../rate"/>

	    <submission id="save" method="put"
		   action="expenses.xml" replace="none"/>

	</model>
</head>
<body>
    <group xmlns="http://www.w3.org/2002/xforms">
	<output class="h" ref="total"><label>Total &#x20ac;</label></output>
<h:br/>

	<repeat nodeset="declarations/item">
	    <input ref="date"><label>Date</label></input>
	    <input ref="what"><label>What</label></input>
	    <input ref="amount" incremental="true"><label>Amount</label></input>
	    <select1 ref="rate" incremental="true">
	        <label></label>
	        <itemset nodeset="instance('currencies')/currency">
	            <label ref="name"/>
	            <value ref="rate"/>
	        </itemset>
	    </select1>
	    <output ref="home"><label> =&#x20AC;</label></output>
	</repeat>

<br/>
	<trigger><label>Another</label>
	      <action ev:event="DOMActivate">
			<insert  
	           		nodeset="declarations/item"
	           		position="after" at="count(declarations/item)"/>
			<setvalue ref="declarations/item[last()]/date" value="substring-before(now(),'T')"/>
			<setvalue ref="declarations/item[last()]/rate" value="1"/>
			<setvalue ref="declarations/item[last()]/what"/>
			<setvalue ref="declarations/item[last()]/amount" value="0"/>
	      </action>
	</trigger>
    </group>
</body>
</html>
