W3C home > Mailing lists > Public > www-forms@w3.org > January 2003

How to do a dynamic XML lookup within a repeat?

From: Dueck, Brian <bdueck@metasolv.com>
Date: Mon, 20 Jan 2003 12:02:01 -0600
Message-ID: <E8F1B37FC20ED74BAC2685B05C799714555A7B@srvtoemail.metasolv.com>
To: "'www-forms@w3.org'" <www-forms@w3.org>
Hello;

I have a question regarding the best way (or any way) to from within a
repeat element, lookup XML from a different instance document using
information from the repeat's current element.

Specifically, I have a scenario where my XForm has two XML instances: the
primary instance contains data, the second instance contains metadata about
the primary.

I have a repeat group in my form that processes the data in the primary
document, but during the repeat processing I need to do an XPath lookup to
the metadata document based on information in the current element in the
repeat. That "lookup" will be used to display things like labels, etc.

As you can see from the snippet below, the repeat element iterates through
the primary document, displays information from that primary document, and
then tries to do a lookup to the metadata. The metadata lookup doesn't work.


...
<xforms:repeat id="resultRepeat"
nodeset="xforms:instance('sampleDocument')/*">
	<!-- display the data -->
	<xforms:output ref=".">
<xforms:label>.=</xforms:label>
	</xforms:output>
	</br>
	<!-- The problem is here!
	The following lookup does not work as expected because the
local-name(.) part of this XPath statement refers to the enclosing element
xforms:instance('metaData'). What I need is a way to refer to the current
node in the nodeset of the repeat element.
	-->
	<!-- display the metadata-->
	<xforms:output
ref="xforms:instance('metaData')/element[@name=local-name(.)]/@label">
		<xforms:label>MetaData Lookup=</xforms:label>
	</xforms:output>
	</br>
</xforms:repeat>

Any and all help would be greatly appreciated.

Regards,

Brian.

------

What follows here is the complete XForm demonstrating the problem using the
IE XForms plug-in from http://www.formsplayer.com.

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms/cr"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:wr="http://www.unisys.com/WebServices/"
xmlns:ad="http://webservices.eraserver.net/" xmlns:fp="urn:formsplayer.com">
	<object id="FormsPlayer"
classid="CLSID:4D0ABA11-C5F0-4478-991A-375C4B648F58">
		<b>FormsPlayer has not loaded. Please check your
installation or install forms player from http://www.formsplayer.com</b>
		<br />
		<br />
	</object>
	<?import namespace="xforms" implementation="#FormsPlayer" ?>
	<head>
		<title>Test Case</title>
		<xforms:model id="mdlMetaData" functions="fp:HTMLserialise">
			<xforms:instance id="metaData">
				<metaData>
					<element name="address"
label="Address"/>
					<element name="phone"
label="Telephone Number"/>
					<element name="fname" label="First
Name"/>
					<element name="lname" label="Last
Name"/>
					<element name="pono" label="Purchase
Order Number"/>
					<element name="item" label="Item"/>
					<element name="deliveryDate"
label="Delivery Date"/>
					<element name="element"
label="Fooey"/>
				</metaData>
			</xforms:instance>
		</xforms:model>
		<xforms:model id="mdlSampleDocument"
functions="fp:HTMLserialise">
			<xforms:instance id="sampleDocument">
				<person>
					<fname>Fred</fname>
					<lname>Flintstone</lname>
					<address>123 Shale St.,
Bedrock</address>
					<phone>23</phone>
				</person>
			</xforms:instance>
		</xforms:model>
	</head>
	<body>
		<div class="body">
			<h1>Test Case</h1>
			<p>
			This test case shows a problem with referencing
other instance documents from within repeating groups.
		</p>
			<xforms:group
ref="xforms:instance('sampleDocument')">
				<xforms:output ref="fp:HTMLserialise(.)"
class="debug">
					<xforms:label>Contents of
document</xforms:label>
				</xforms:output>
			</xforms:group>
			<xforms:group>
				<xforms:repeat id="resultRepeat"
nodeset="xforms:instance('sampleDocument')/*">
					<!-- display the data -->
					<xforms:output ref=".">
	
<xforms:label>.=</xforms:label>
					</xforms:output>
					</br>
					<!-- The problem is here!
					The following 
					-->
					<!-- display the metadata-->
					<xforms:output
ref="xforms:instance('metaData')/element[@name=local-name(.)]/@label">
						<xforms:label>MetaData
Lookup=</xforms:label>
					</xforms:output>
					</br>
					<xforms:output ref="local-name(.)">
	
<xforms:label>local-name(.)=</xforms:label>
					</xforms:output>
					</br>
					<xforms:output
ref="xforms:instance('metaData')/element[@name='fname']/@label">
						<xforms:label>'fname' Label
Lookup=</xforms:label>
					</xforms:output>
				</xforms:repeat>
			</xforms:group>
		</div>
	</body>
</html>
Received on Monday, 20 January 2003 13:22:04 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:21:54 GMT