Calculate using a field from a cascading select instance

I want to populate two nodes with the answer from a select 1 question in a cascading select.

I'm trying to use the calculate function in the bind for the second node.

<h:head>
<h:title>Cascading Regional</h:title>

	<instance>
		<cr id="cascading_regional_0.3" version="2015081701">
			<activity/>
		</cr>
	</instance>
	
	<instance id="activity">
		<root>
			<item>
				<value>Repair Pothole (201)</value>
				<name>repair_pothole_201</name>
				<unitl>Each</unitl>
				<unitv>each</unitv>
			</item>
			<item>
		</root>
	</instance>
	
	<bind nodeset="/cr/activity" type="select1"/>
	<bind nodeset="/cr/quantity_and_units/unit" calculate="instance('activity')/root/item/unitv [name= /cr/activity ]" type="string"/>
</model>

</h:head>

<h:body>

<select1 ref="/cr/activity">
	<label>Activity</label>
		<itemset nodeset="instance('activity')/root/item">
			<value ref="name"/>
			<label ref="value"/>
		</itemset>
</select1>

</h:body>
</h:html>

Is this possible or should I be using a different method?

(I deleted your other post -- both questions have the same answer)

This is a quirk of XPath. In this bind:

<bind nodeset="/cr/quantity_and_units/unit"
calculate="instance('activity')/root/item/unitv
[name= /cr/activity]" type="string"/>

The selection condition (in bold above) is evaluated in the context of the
instance('activity').

So it is looking for 'name' under the instance('activity'
)/root/item/unitv node.
But it is also looking for '/cr/activity' under the instance('activity')
root-level node.

When writing these formulas, you need to explicitly specify whether the
field is in the main (un-named) instance, or one of these read-only named
instances. The correct expression is:

<bind nodeset="/cr/quantity_and_units/unit"
calculate="instance('activity')/root/item/unitv
[*name= instance()/cr/activity* ]" type="string"/>

This also applies to expressions like position(..) -- you need to write
this as position(instance()..)
Not sure if that parses correctly. If not, you can always store
position(..) in a field, then reference that field.

Note that *instance()foo *will reference the 'foo' field in the current
repeat group.

··· On Sun, Aug 16, 2015 at 8:12 PM, wrote:

I want to populate two nodes with the answer from a select 1 question in a
cascading select.

I'm trying to use the calculate function in the bind for the second node.

<h:head>
<h:title>Cascading Regional</h:title>

            <instance>
                    <cr id="cascading_regional_0.3" version="

2015081701">


            <instance id="activity">
                    <root>
                            <item>
                                    <value>Repair Pothole (201)</value>
                                    <name>repair_pothole_201</name>
                                    <unitl>Each</unitl>
                                    <unitv>each</unitv>
                            </item>
                            <item>
                    </root>
            </instance>

            <bind nodeset="/cr/activity" type="select1"/>
            <bind nodeset="/cr/quantity_and_units/unit"

calculate="instance('activity')/root/item/unitv [name= /cr/activity ]"
type="string"/>

</h:head>

<h:body>

    <select1 ref="/cr/activity">
            <label>Activity</label>
                    <itemset nodeset="instance('activity')/root/item">
                            <value ref="name"/>
                            <label ref="value"/>
                    </itemset>
    </select1>

</h:body>
</h:html>

Is this possible or should I be using a different method?

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

(I deleted your other post -- both questions have the same answer)

This is a quirk of XPath. In this bind:

The selection condition (in bold above) is evaluated in the context of the instance('activity').

So it is looking for 'name' under the instance('activity')/root/item/unitv node.
But it is also looking for '/cr/activity' under the instance('activity') root-level node.

When writing these formulas, you need to explicitly specify whether the field is in the main (un-named) instance, or one of these read-only named instances. The correct expression is:

This also applies to expressions like position(..) -- you need to write this as position(instance()..)
Not sure if that parses correctly. If not, you can always store position(..) in a field, then reference that field.

Note that instance()foo will reference the 'foo' field in the current repeat group.

I want to populate two nodes with the answer from a select 1 question in a cascading select.

I'm trying to use the calculate function in the bind for the second node.

<h:head>

<h:title>Cascading Regional</h:title>

    <model>



            <instance>

                    <cr id="cascading_regional_0.3" version="2015081701">

                            <activity/>

                    </cr>

            </instance>



            <instance id="activity">

                    <root>

                            <item>

                                    <value>Repair Pothole (201)</value>

                                    <name>repair_pothole_201</name>

                                    <unitl>Each</unitl>

                                    <unitv>each</unitv>

                            </item>

                            <item>

                    </root>

            </instance>



            <bind nodeset="/cr/activity" type="select1"/>

            <bind nodeset="/cr/quantity_and_units/unit" calculate="instance('activity')/root/item/unitv [name= /cr/activity ]" type="string"/>

    </model>

</h:head>

<h:body>

    <select1 ref="/cr/activity">

            <label>Activity</label>

                    <itemset nodeset="instance('activity')/root/item">

                            <value ref="name"/>

                            <label ref="value"/>

                    </itemset>

    </select1>

</h:body>

</h:html>

Is this possible or should I be using a different method?

--

--

Post: opend...@googlegroups.com

Unsubscribe: opendatakit...@googlegroups.com

Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups "ODK Community" group.

To unsubscribe from this group and stop receiving emails from it, send an email to opendatakit...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

Mitch Sundt
Software Engineer
University of Washington
mitche...@gmail.com

Thanks heaps Mitch, it even makes sense to this noob.

Richard

··· On Tuesday, 18 August 2015 03:21:03 UTC+10, Mitch Sundt wrote: > On Sun, Aug 16, 2015 at 8:12 PM, wrote:

(I deleted your other post -- both questions have the same answer)

This is a quirk of XPath. In this bind:

The selection condition (in bold above) is evaluated in the context of the instance('activity').

So it is looking for 'name' under the instance('activity')/root/item/unitv node.
But it is also looking for '/cr/activity' under the instance('activity') root-level node.

When writing these formulas, you need to explicitly specify whether the field is in the main (un-named) instance, or one of these read-only named instances. The correct expression is:

This also applies to expressions like position(..) -- you need to write this as position(instance()..)
Not sure if that parses correctly. If not, you can always store position(..) in a field, then reference that field.

Note that instance()foo will reference the 'foo' field in the current repeat group.

I want to populate two nodes with the answer from a select 1 question in a cascading select.

I'm trying to use the calculate function in the bind for the second node.

<h:head>

<h:title>Cascading Regional</h:title>

    <model>



            <instance>

                    <cr id="cascading_regional_0.3" version="2015081701">

                            <activity/>

                    </cr>

            </instance>



            <instance id="activity">

                    <root>

                            <item>

                                    <value>Repair Pothole (201)</value>

                                    <name>repair_pothole_201</name>

                                    <unitl>Each</unitl>

                                    <unitv>each</unitv>

                            </item>

                            <item>

                    </root>

            </instance>



            <bind nodeset="/cr/activity" type="select1"/>

            <bind nodeset="/cr/quantity_and_units/unit" calculate="instance('activity')/root/item/unitv [name= /cr/activity ]" type="string"/>

    </model>

</h:head>

<h:body>

    <select1 ref="/cr/activity">

            <label>Activity</label>

                    <itemset nodeset="instance('activity')/root/item">

                            <value ref="name"/>

                            <label ref="value"/>

                    </itemset>

    </select1>

</h:body>

</h:html>

Is this possible or should I be using a different method?

--

--

Post: opend...@googlegroups.com

Unsubscribe: opendatakit...@googlegroups.com

Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups "ODK Community" group.

To unsubscribe from this group and stop receiving emails from it, send an email to opendatakit...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

Mitch Sundt
Software Engineer
University of Washington
mitche...@gmail.com

[name= instance()/cr/activity ]

gave the below error in ODK validate?

org.javarosa.xpath.XPathUnsupportedException: XPath evaluation: unsupported construct [instance() function used with 0 arguements. Expecting 1 arguement]

··· On Tuesday, 18 August 2015 03:21:03 UTC+10, Mitch Sundt wrote: > On Sun, Aug 16, 2015 at 8:12 PM, wrote:

Argh! So much for writing responses from memory!

The two forms are:

current()

and

instance('instancename')

So wherever I said instance(), replace that with current()

Sorry.

··· On Mon, Aug 17, 2015 at 3:28 PM, wrote:

On Tuesday, 18 August 2015 03:21:03 UTC+10, Mitch Sundt wrote:

(I deleted your other post -- both questions have the same answer)

This is a quirk of XPath. In this bind:

The selection condition (in bold above) is evaluated in the context of
the instance('activity').

So it is looking for 'name' under
the instance('activity')/root/item/unitv node.
But it is also looking for '/cr/activity' under the instance('activity')
root-level node.

When writing these formulas, you need to explicitly specify whether the
field is in the main (un-named) instance, or one of these read-only named
instances. The correct expression is:

This also applies to expressions like position(..) -- you need to write
this as position(instance()..)
Not sure if that parses correctly. If not, you can always store
position(..) in a field, then reference that field.

Note that instance()foo will reference the 'foo' field in the current
repeat group.

On Sun, Aug 16, 2015 at 8:12 PM, richard...@gmail.com wrote:
I want to populate two nodes with the answer from a select 1 question in
a cascading select.

I'm trying to use the calculate function in the bind for the second node.

<h:head>

<h:title>Cascading Regional</h:title>

    <model>



            <instance>

                    <cr id="cascading_regional_0.3" version="

2015081701">

                            <activity/>

                    </cr>

            </instance>



            <instance id="activity">

                    <root>

                            <item>

                                    <value>Repair Pothole

(201)

                                    <name>repair_pothole_201</name>

                                    <unitl>Each</unitl>

                                    <unitv>each</unitv>

                            </item>

                            <item>

                    </root>

            </instance>



            <bind nodeset="/cr/activity" type="select1"/>

            <bind nodeset="/cr/quantity_and_units/unit"

calculate="instance('activity')/root/item/unitv [name= /cr/activity ]"
type="string"/>

    </model>

</h:head>

<h:body>

    <select1 ref="/cr/activity">

            <label>Activity</label>

                    <itemset

nodeset="instance('activity')/root/item">

                            <value ref="name"/>

                            <label ref="value"/>

                    </itemset>

    </select1>

</h:body>

</h:html>

Is this possible or should I be using a different method?

--

--

Post: opend...@googlegroups.com

Unsubscribe: opendatakit...@googlegroups.com

Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google
Groups "ODK Community" group.

To unsubscribe from this group and stop receiving emails from it, send
an email to opendatakit...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

Mitch Sundt
Software Engineer
University of Washington
mitche...@gmail.com

[name= instance()/cr/activity ]

gave the below error in ODK validate?

org.javarosa.xpath.XPathUnsupportedException: XPath evaluation:
unsupported construct [instance() function used with 0 arguements.
Expecting 1 arguement]

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com