<?xml version="1.0" encoding="UTF-8"?>
<!-- basic FO page definition stuff -->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xfm="http://www.w3.org/2002/xforms" 
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
	<head>
		<title>Repeat + calculations + schema</title>
        		<link rel="stylesheet" type="text/css" href="xformsdemo.css" />
		<style type="text/css">
		h2 {padding-left: 20px; color:white;background-color:blue;}
		body { font-style: normal; font-weight: 500; background-color: rgb(230,230,230); color: black;;}
		input::value {background-color: rgb(255,255,255);}
		output::value {background-color: rgb(240,240,240);}
		secret::value {background-color: rgb(255,255,255);}
		range::value {}
		p.headline {background-color:red; color:white;}
		.addbuttons {padding-left:200px;}
		*::repeat-index,  input::value {background-color: rgb(230,230,230);}
		.itemsection {margin:10px;}
		input.name::value {width:150pt;}
		.price::value {width:40pt;}
		.selection {list-ui:listbox;}
div.payment *::value,div.payment input, div.payment select1 {display:block;}
div.payment *::value {width:150px;}
		output.total::value {font-size:12pt;color:red;width:100pt;margin-left: 10px;caption-side: left;}
		output.total label {font-size:12pt;width: 100px;}
		.padded {padding-left: 320px;}
		.itemcount {caption-side:left;}
		output.itemcount, output.itemcount label, output.itemcount::value {display:inline;font-size:12pt;}
		output.itemcount::value {width:50px;}
		thead td {font-size:12pt;}
		div.itemsection {border-style:solid;border-width:2px;border-color:black;padding:10px;margin:10px;}
		select1 {display:block;}
	
	
		repeat {display:table-row-group;}
		repeat::repeat-item {display:table-row;}
		repeat::repeat-index {display:table-row;}
		thead {display:table-header-group;}

		</style>

		<xfm:model><!-- schema="purchase2.xsd"-->
							<xfm:submission id="submit1" method="post" action="http://sinex.tml.hut.fi:8080/xforms/request"/>
		
			<xfm:submission id="submit12" method2="postxml" localfile="temp2.xml" target2="http://www.hut.fi/" />
			<xfm:instance src="purchaseorder.xml" />
			<xfm:bind ref="/purchaseOrder/items/item/units" constraint=". &gt; 0" readonly=". &gt; 19" type="xsd:integer"/>
			<!--
						<xfm:bind ref="/purchaseOrder/totals/subtotal" calculate="sum(../../items/item/total)"/>
						<xfm:bind ref="/purchaseOrder/totals/tax" calculate="round(../subtotal * ../../info/tax)"/>
						<xfm:bind ref="/purchaseOrder/totals/total" calculate="../subtotal + ../tax"/>
						<xfm:bind ref="/purchaseOrder/totals/rowcount" calculate="count(/purchaseOrder/items/item)"/>
					-->
			<xfm:bind ref="/purchaseOrder/totals">
				<xfm:bind ref="subtotal" calculate="sum(../../items/item/total)" />
				<xfm:bind ref="tax" calculate="round(../subtotal * ../../info/tax)" />
				<xfm:bind ref="total" calculate="../subtotal + ../tax" />
				<xfm:bind ref="rowcount" calculate="sum(/purchaseOrder/items/item/units)" />
			</xfm:bind>
			<xfm:bind ref="/purchaseOrder/items/item/total" calculate="../units * ../price - ((../units * ../price)>1000)*(../units * ../price * 0.1)" relevant="../units &gt; 0" />
			<xfm:bind ref="/purchaseOrder/items/item/discount" calculate=" ((../units * ../price)>1000)*(../units * ../price * 0.1)" relevantXXX=". &gt; 0" />
			<xfm:bind ref="/purchaseOrder/payment/as" relevant="/purchaseOrder/totals/rowcount &gt; 0" />
			<xfm:bind ref="/purchaseOrder/payment/cc" relevant="../as='credit'" />
			<xfm:bind ref="/purchaseOrder/payment/exp" relevant="../as='credit'" type="xsd:date"/>
			<xfm:bind ref="/purchaseOrder/payment/customernumber" relevant="../as='cash'" />
		</xfm:model>
	</head>
	<body>
		<h2>X-Smiles shop with XForms</h2>
		<p></p>

		<div class="itemsection">
		<table>
			<thead>
			<tr>
				<td>Amount</td>
				<td>Name</td>
				<td>Price</td>
				<td>Discount</td>
				<td>Discounted price</td>
				</tr>
			</thead>
		<xfm:repeat ref="/purchaseOrder/items/item" id="repeat1" x-number="4" x-startindex="1">
				<td>
				<!-- REPEAT START -->
				<xfm:input ref="units" incremental="true">
					<xfm:hint>The units of this item</xfm:hint>
				</xfm:input>
				<!--
				<xfm:range start="0" end="20" stepsize="1" ref="units">
					<xfm:hint>The units of this item</xfm:hint>
				</xfm:range>
				-->
				</td>
				<td>
				<xfm:input ref="name" class="name">
					<!--<xfm:label style="caption-side:left"></xfm:label>-->
					<xfm:hint>The name of this item</xfm:hint>
				</xfm:input>
				</td>
				<td>
				<xfm:input cols="3" ref="price" class="price" incremental="true">
					<xfm:hint>The price of this item</xfm:hint>
				</xfm:input>
				</td>
				<td>
				<xfm:output cols="5" ref="discount" class="price">
					<xfm:hint>The discount value of this item</xfm:hint>
				</xfm:output>
				</td>
				<td>
				<xfm:output cols="6" ref="total" class="price">
					<xfm:hint>The total value of this item</xfm:hint>
				</xfm:output>
				</td>
		</xfm:repeat>
		</table>
			<xfm:output ref="/purchaseOrder/totals/rowcount" class="itemcount">
			<!--				<xfm:label>Items in your basket:  </xfm:label>				-->
			</xfm:output>
		<p class="padded">
			<xfm:output ref="/purchaseOrder/totals/subtotal" cols="8" class="total">
				<xfm:label style="font-weight:bold;">Subtotal</xfm:label>
				<xfm:hint>Subtotal</xfm:hint>
			</xfm:output>
		</p><p class="padded">
			<xfm:output ref="/purchaseOrder/totals/tax" cols="18" class="total">
				<xfm:label style="font-weight:bold;">Tax</xfm:label>
				<xfm:hint>Tax</xfm:hint>
			</xfm:output>
		</p><p class="padded">
			<xfm:output ref="/purchaseOrder/totals/total" cols="10" class="total">
				<xfm:label style="font-weight:bold;">Total</xfm:label>
				<xfm:hint>Total</xfm:hint>
			</xfm:output>
		</p>

		<p>
			<xfm:trigger id="insertbutton">
				<xfm:label>Add item</xfm:label>
				<xfm:action ev:event="click">
					<xfm:insert ref="/purchaseOrder/items/item" at="index('repeat1')" />
					<xfm:setvalue ref="/purchaseOrder/items/item[index('repeat1')]/price" value="'100'"/>
					<xfm:setvalue ref="/purchaseOrder/items/item[index('repeat1')]/units" value="'1'"/>
				</xfm:action>
			</xfm:trigger>
			<xfm:trigger id="delete">
				<xfm:label>Delete item</xfm:label>
				<xfm:action ev:event="click">
					<xfm:delete ref="/purchaseOrder/items/item" at="index('repeat1')" />
				</xfm:action>
			</xfm:trigger>

		</p>


		</div>
		<div class="payment">
		<p>
			<xfm:select1 ref="/purchaseOrder/payment/as" appearance="compact">
				<xfm:label>Select payment method</xfm:label>
				<xfm:item>
					<xfm:value>credit</xfm:value>
					<xfm:label>Credit card</xfm:label>
				</xfm:item>
				<xfm:item>
					<xfm:value>cash</xfm:value>
					<xfm:label>Bill me!</xfm:label>
				</xfm:item>
			</xfm:select1>
			</p><p>
			<xfm:input ref="/purchaseOrder/payment/cc" incremental="true" >
				<xfm:label style="font-weight:bold;">Credit card number</xfm:label>
			</xfm:input>
			<xfm:input ref="/purchaseOrder/payment/exp" class="cardexpiration">
				<xfm:label style="font-weight:bold;">Expiration date</xfm:label>
			</xfm:input>
		</p><p>
			<xfm:input ref="/purchaseOrder/payment/customernumber" incremental="true" class="customernumber">
				<xfm:label style="font-weight:bold;">Customer number</xfm:label>
			</xfm:input>
		</p>
		</div>


<p>
			<xfm:submit name="Submit"  submission="submit1" >
				<xfm:hint>Click to submit</xfm:hint>
				<xfm:label>Buy!</xfm:label>
			</xfm:submit>
		</p>
		<p style="margin-top:150px;"></p>
	</body>
</html>
