Example markup for nested models

From W3C XForms Group Wiki (Public)
Jump to: navigation, search

Describe Example markup for nested models here.


<?xml version="1.0" encoding="utf-8" ?>
		<title>Simple XForms</title>

		<h1>Example of nested model syntax...</h1>
		<!-- consume generic flight info service and adapt to our airline and set defaults
		     appropriate to common usage, e.g. today's date, our airline, etc -->
		<xf:model id="AA_flight_info_service">
			<xf:instance id="AA_defaults">  
				<instanceData xmlns="">
			<!-- set up query parms using context info to simplify data entry from mobile device:
				today's date
				current location, if available from GPS or other accessible locator info
				default carrier 
				locator code checksum for quick validation -->
			<xf:bind nodeset="instance('')/time" calculate="now()" />
			<xf:bind nodeset="instance('AA_defaults')/departure_city" calculate="...LatLongToCity(GPScoord())..."/>
			<xf:bind nodeset="instance('AA_defaults')/locator_code" constraint="...AA locator checksum..."/>
			<xf:bind nodeset="instance('AA_defaults')/date" calculate="...dateFromDatename(../datename)..."/>
			<xf:instance id="offered_dates">	
				<instanceData xmlns="">
			<xf:instance id="valid_arrival_cities">
				<instanceData xmlns="">
					<city/>  <!-- computed once we have a departure city...looks up AA routes from that city -->
			<xf:bind nodeset="arrival_city" relevant="../departure_city <> '' "/>
			<!-- add web service lookup for valid arrival cities below... -->
			<xf:submission id="AA_query" />  
			<!-- want to be able to set parms and redirect to submodel submission, maybe after doing our own web service invocation to fill in values... -->			

			<!-- wire up instance elements in the AA model to the underlying generic query service -->
			<!-- start and end dates are the same for the AA service...only does single date query -->
			<xf:bind nodeset="instance('query_parms')/start_date" calculate="instance('AA_defaults')/date"/>
			<xf:bind nodeset="instance('query_parms')/end_date" calculate="instance('AA_defaults')/date"/>
			<!-- time is always set to now() -->
			<xf:bind nodeset="instance('query_parms')/time" calculate="now()" />
			<!-- airline is always AA -->
			<xf:bind nodeset="instance('query_parms')/airline" calculate="AA" />
			<!-- would be nice if the following could be "linked" by reference from the AA instance, vs. copied -->
			<xf:bind nodeset="instance('query_parms')/departure_city" calculate="instance('AA_defaults')/departure_city" />
			<xf:bind nodeset="instance('query_parms')/arrival_city" calculate="instance('AA_defaults')/arrival_city" />
			<xf:bind nodeset="instance('query_parms')/flight_no" calculate="instance('AA_defaults')/flight_no" />
			<xf:bind nodeset="instance('query_parms')/locator" calculate="instance('AA_defaults')/locator" />

			<!-- this model corresponds to a generic flight info web service -->
			<xf:model id="flight_info_service">  
				<xf:instance id="query_parms">  
					<instanceData xmlns="">
						<start_date/>			<!-- start date for flight queries, required -->
						<end_date/>			<!-- end date for flight queries, required -->
						<time/>				<!-- if provided, find flights near this time -->
						<airline/>			<!-- required -->
						<departure_city/>		<!-- one of departure city or arrival city must be filled in if locator_code and flight_no are blank --> 
						<locator_code/>			<!-- if provided, search for flights in this specific reservation -->
						<flight_no/>			<!-- if provided, override time preference -->
				<xf:instance id="search_results">
						<departure_datetime/>	<!-- ISO datetime -->
						<arrival_datetime/>	<!-- ISO datetime -->
				<xf:submission id="submit1" method="..." action="..." />
		<!-- model as generated -->
		<!-- UI using generated model -->

		<xf:group model="AA_flight_info_service"> 
			<xf:input ref="departure_city">
				<xf:label>Departure City:</xf:label>
			<xf:select1 ref="instance('AA_flight_info_service')/arrival_city">
				<xf:label>Arrival City:</xf:label>
				<xf:itemset nodeset="instance('valid_arrival_cities')/city">
					<xf:label ref="."/>
					<xf:value ref="."/>
			<xf:select1 ref="instance('AA_flight_info_service')/datename">
				<xf:itemset nodeset="instance('offered_dates')/date">
					<xf:label ref="."/>
					<xf:value ref="."/>
			<xf:submit submission="AA_query">