Examples of cascading selections.

Hi,

Would some one be able to share or point me to some example forms
that use cascading selections?
I am fairly new to Kobo/XForms and was not able to build one myself
using either the Form Builder or manually.

Thanks.

best regards,

Y. Assefa

Assefa,

I will be happy to provide some examples and instructions for Cascading Selections.

Cascading selections are sets of questions where the first selection constrains the options in the second selection. Often used for things like “1.Country, 2.state in that country, 3.city in that state, 4.neighborhood in that city” arrangement of questions.

The KoBoForm builder is unique in that it has a function for including itemsets and filtering question options by previous answers.

You want to select District, then a County from that District, then a neighborhood from the selected County.

The Solution is Cascading Selections from Itemsets!

You will see in KoBoForm that there is an “Add Data Instance” button in the top menu. This is how you create Itemsets which contain your cascading selection options. Detailed instructions are available in the UserGuide, I will explain briefly here:

  1. Under the drop down menu for “Add Data Instance” click “import CSV”
  2. You can either paste the CSV into the window, or you can upload it. See “How to Format your CSV” below for requirements and tips.
  3. KoBoForm will automatically add a set of cascading questions, in your case 1 for District, Tehsil, and UC, with filtering by selection.
  4. You can edit the text of the questions, i.e. KoBoForm will create a District question from the header of your CSV, so the text will be “District”. Edit it to read “What is the District the Respondent lives in?” or something like that.

That is the short version, I have appended below much more detail below on the formatting of your CSV and Itemset details.

~Neil

How to Format your CSV

To expedite adding large sets of data the “Import CSV” feature which can be accessed by clicking on the “Import CSV” button. This will bring up a dialog that allows the user to paste in CSV data and a text box for specifying the name of the to be created data instance. The CSV should be in the format of

You can do this by entering all your Districts, Counties, and Neighborhoods as elements in a Data Instance. ****

level_1_header,level_2_header,level_3_header,...,level_N_header

level1data,level2data,level3data,...,leveNdata

level1data,level2data,level3data,...,leveNdata

level1data,level2data,level3data,...,leveNdata

level1data,level2data,level3data,...,leveNdata

For example:

Districts, Counties, and Neighborhoods

···
District,County,Neighborhood

Charsadda,Charsadda,Agra

Charsadda,Charsadda,Amba Dheri

Charsadda,Charsadda,Behlola

Charsadda,Charsadda,Charsadda MC-I

Charsadda,Tangi,Abazai

Charsadda,Tangi,Dakai

Charsadda,Tangi,Deri Zardal

Charsadda,Tangi,Dhakki

Charsadda,Shabqadar,Shabqadar1

Charsadda,Shabqadar,Shabqadar2

Charsadda,Shabqadar,Shabqadar3

Charsadda,Shabqadar,Shabqadar4

DI Khan,Paharpur,Paharpur1

DI Khan,Paharpur,Paharpur2

DI Khan,Paharpur,Paharpur3

DI Khan,Paharpur,Paharpur4

DI Khan,Kulachi,Kulachi1

DI Khan,Kulachi,Kulachi2

DI Khan,Kulachi,Kulachi3

DI Khan,Daraban,Daraban1

DI Khan,Daraban,Daraban2

DI Khan,Daraban,Daraban3

DI Khan,DI Khan,DI Khan4

DI Khan,DI Khan,DI Khan5

Hangu,HanguTehsil1,HanguTehsil1UC1

Hangu,HanguTehsil1,HanguTehsil1UC2

Hangu,HanguTehsil1,HanguTehsil1UC3

Hangu,HanguTehsil2,HanguTehsil2UC1

Hangu,HanguTehsil2,HanguTehsil2UC2

Hangu,HanguTehsil2,HanguTehsil2UC3

Hangu,HanguTehsil3,HanguTehsil3UC1

Hangu,HanguTehsil3,HanguTehsil3UC2

Hangu,HanguTehsil3,HanguTehsil3UC3

More details on specific functions and elements of the data model:

Itemsets allow a select or select1 question to use nodes from a data model instance as the options.

The label and value elements in the itemset element are used to set which attributes are to be used as the label (shown to the user) and value (stored in the database) of the select options.

The form builder now has an “Add Data” menu that allows the user to add new instances solely for storing data for itemsets and adding new elements to the data instances.

The “Add Data Instance” button adds a new data model instance to the xform.

The “Add Data Element” will add a new element to a data instance. By default the data elements contain a value and label attribute for storing the value saved in the database and the label shown to the user.

The data instance properties view only allows the user to change the data instance id. This is the ID of the instance in the xform. This also changes the name of the root node in the data instance.

The data element properties view allows the user to set the name of the element. The name of the element must conform to XML rules and cannot have reserved characters, such as spaces. The properties view also lets the user add, edit, and remove attributes of the given data element.

To use an item set on a select or select1 question, in the question’s properties view check the “Use Itemset” check box. The form builder will now show the item set as a child of the select or select1 question.

The itemset properties view allows the user to pick the data instance to use, the value attribute and label attribute to use, as well as the various levels and predicates into the item set. Due to limited development time, the form builder only supports one predicate per level. For example: nodeset: “instance(‘locales’)/locales/province= /myForm/province?/district” as opposed to: nodeset: “instance(‘locales’)/locales/province= /myForm/isNorthern?> /myForm/population?/district”

Also, due to limited development time, the form builder only support the equals binary comparison operator. The ODK collect client should support any binary comparision operator, for example, the form builder has no way to create the following, even though it will work in Collect: nodeset: “instance(‘locales’)/locales/province> /myForm/population?/district”

When editing a itemset in the FB the user will need to keep in mind that there must be at least one “level” so the user has something to choose from. Each time there is more than one level, and the user wants to select only certain elements from the previous element, the use should add a predicate that filters based on the given attribute by another question in the form.

To expedite adding large sets of data the “Import CSV” feature which can be accessed by clicking on the “Import CSV” button. This will bring up a dialog that allows the user to paste in CSV data and a text box for specifying the name of the to be created data instance. The CSV should be in the format of

level_1_header,level_2_header,level_3_header,...,level_N_header level1data,level2data,level3data,...,leveNdata level1data,level2data,level3data,...,leveNdata level1data,level2data,level3data,...,leveNdata level1data,level2data,level3data,...,leveNdata

For example

Country,Province USA,Alabama USA,Alaska Nigeria, Lagos State Nigeria, Abuja

The header row, which is the first row, will be used as the name for the elements of different levels, and thus must conform to XML rules and not contain reserved characters (spaces, <, >, and such). The data in the following rows of the CSV file will be used as the label attribute of the elements created. The value attribute will be created automatically as a incrementing integer. For example in the above example of countries and provinces the following data instance would be created if I gave the instance the name “countries”

<instance id="countries">         <countries>           <Country label="USA" value="1">             <Province label="Alabama" value="1"/>             <Province label="Alaska" value="2"/>           </Country>           <Country label="Nigeria" value="2">             <Province label=" Lagos State" value="3"/>             <Province label=" Abuja" value="4"/>           </Country>         </countries>       </instance>}}}

☞§※☼:airplane::open_umbrella::slight_smile:

~Neil

On Wed, Dec 28, 2011 at 11:12 AM, assefa ass...@gmail.com wrote:

Hi,

Would some one be able to share or point me to some example forms

that use cascading selections?

I am fairly new to Kobo/XForms and was not able to build one myself

using either the Form Builder or manually.

Thanks.

best regards,

Y. Assefa

You received this message because you are subscribed to the Google Groups “Kobo Users” group.

To post to this group, send email to kobo-...@googlegroups.com.

To unsubscribe from this group, send email to kobo-users+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/kobo-users?hl=en.

Thanks Neil. I am trying it now based on these instructions. I will
update as soon as I have something.

best regards,

Hi,
Based on Neil's instructions, I created a form that contains the
cascading styles. The steps I took are simple using the form
builder: - create a new form - do the Import CSV - paste the
example given above - save the form into an xml - copy the xml on my
phone. - kobo collect downloaded from : Google Code Archive - Long-term storage for Google Code Project Hosting.
(It says Kob admin based on Open Data Kit (1.1.7-rc-1)
When trying to open the form and start the questionnaire, I get the
error: "XPath evaluation: unsupported construct [filter expression]"I
can not figure out what would be wrong. Basically the file is all
generated by the form builder and I only edited the title.Is there
something missing or obviously wrong.
Thanks
Y. Assefa

The xml generated is as follows:
<?xml version="1.0" encoding="UTF-8"?><h:html xmlns:h="http://
XHTML namespace" xmlns="http://www.w3.org/1999/xhtml&quot;
xmlns:xsd="http://www.w3.org/2001/XMLSchema&quot; xmlns:jr="http://
openrosa.org/javarosa"> <h:head> <h:title>Test cascading</
h:title> <model> <instance> <Test_cascading
id="Test_cascading"> <deviceid/> <start/>
<end/> <A01/> <District/> <County/>
<Neighborhood/> </Test_cascading> </instance> <bind
id="deviceid" nodeset="/Test_cascading/deviceid" type="xsd:string"
jr:preload="property" jr:preloadParams="deviceid"/> <bind
id="start" nodeset="/Test_cascading/start" type="xsd:time"
jr:preload="timestamp" jr:preloadParams="start"/> <bind id="end"
nodeset="/Test_cascading/end" type="xsd:time" jr:preload="timestamp"
jr:preloadParams="end"/> <bind id="A01" nodeset="/Test_cascading/
A01" type="xsd:string" required="true()"/> <bind id="District"
nodeset="/Test_cascading/District" type="xsd:string" required="true()"/

  &lt;bind id=&quot;County&quot; nodeset=&quot;/Test\_cascading/County&quot;

type="xsd:string" required="true()"/> <bind id="Neighborhood"
nodeset="/Test_cascading/Neighborhood" type="xsd:string"
required="true()"/> <instance id="data_ins_id">
<data_ins_id> <District label="Charsadda" value="1">
<County label="Charsadda" value="1"> <Neighborhood
label="Agra" value="1"/> <Neighborhood label="Amba Dheri"
value="2"/> <Neighborhood label="Behlola" value="3"/>
<Neighborhood label="Charsadda MC-I" value="4"/>
</County> <County label="Tangi" value="2">
<Neighborhood label="Abazai" value="5"/> <Neighborhood
label="Dakai" value="6"/> <Neighborhood label="Deri
Zardal" value="7"/> <Neighborhood label="Dhakki"
value="8"/> </County> <County label="Shabqadar"
value="3"> <Neighborhood label="Shabqadar1" value="9"/>
<Neighborhood label="Shabqadar2" value="10"/>
<Neighborhood label="Shabqadar3" value="11"/>
<Neighborhood label="Shabqadar4" value="12"/> </County>
</District> <District label="DI Khan" value="2">
<County label="Paharpur" value="4"> <Neighborhood
label="Paharpur1" value="13"/> <Neighborhood
label="Paharpur2" value="14"/> <Neighborhood
label="Paharpur3" value="15"/> <Neighborhood
label="Paharpur4" value="16"/> </County> <County
label="Kulachi" value="5"> <Neighborhood label="Kulachi1"
value="17"/> <Neighborhood label="Kulachi2" value="18"/>
<Neighborhood label="Kulachi3" value="19"/> </

        &lt;County label=&quot;Daraban&quot; value=&quot;6&quot;&gt;             

<Neighborhood label="Daraban1" value="20"/> <Neighborhood
label="Daraban2" value="21"/> <Neighborhood
label="Daraban3" value="22"/> </County> <County
label="DI Khan" value="7"> <Neighborhood label="DI Khan4"
value="23"/> <Neighborhood label="DI Khan5" value="24"/>
</County> </District> <District
label="Hangu" value="3"> <County label="HanguTehsil1"
value="8"> <Neighborhood label="HanguTehsil1UC1"
value="25"/> <Neighborhood label="HanguTehsil1UC2"
value="26"/> <Neighborhood label="HanguTehsil1UC3"
value="27"/> </County> <County
label="HanguTehsil2" value="9"> <Neighborhood
label="HanguTehsil2UC1" value="28"/> <Neighborhood
label="HanguTehsil2UC2" value="29"/> <Neighborhood
label="HanguTehsil2UC3" value="30"/> </County>
<County label="HanguTehsil3" value="10"> <Neighborhood
label="HanguTehsil3UC1" value="31"/> <Neighborhood
label="HanguTehsil3UC2" value="32"/> <Neighborhood
label="HanguTehsil3UC3" value="33"/> </County> </

    &lt;/data\_ins\_id&gt;      &lt;/instance&gt;      &lt;itext&gt;       

<translation lang="English"> <text id="A01">
<value>QuestionA01</value> </text> <text
id="A01_1"> <value>OptionA01_1</value> </text>
</translation> </itext> </model> </h:head> <h:body>
<select1 bind="A01"> <label ref="jr:itext('A01')"/> <item>
<label ref="jr:itext('A01_1')"/> <value>1</value> </

&lt;/select1&gt;    &lt;select1 bind=&quot;District&quot;&gt;      &lt;label&gt;District&lt;/
  &lt;itemset nodeset=&quot;instance\(&#39;data\_ins\_id&#39;\)/data\_ins\_id/

District"> <label ref="@label"/> <value ref="@value"/>
</itemset> </select1> <select1 bind="County">
<label>County</label> <itemset nodeset="instance('data_ins_id')/
data_ins_id/District[@value = /Test_cascading/District]/County">
<label ref="@label"/> <value ref="@value"/> </itemset>
</select1> <select1 bind="Neighborhood">
<label>Neighborhood</label> <itemset
nodeset="instance('data_ins_id')/data_ins_id/District[@value = /
Test_cascading/District]/County[@value = /Test_cascading/County]/
Neighborhood"> <label ref="@label"/> <value ref="@value"/

···
  &lt;/itemset&gt;    &lt;/select1&gt;  &lt;/h:body&gt;&lt;/h:html&gt;

On Dec 29, 1:50 pm, assefa <ass...@gmail.com> wrote:

Thanks Neil. I am trying it now based on these instructions. I will
update as soon as I have something.

best regards,

Hi Assefa,

I tried following Neil’s instructions as well and it worked for me. Could you email your xml file to kobo-...@googlegroups.com? The pasted xml doesn’t work because of all the line breaks.

Tino

···

On Thu, Dec 29, 2011 at 7:28 AM, assefa ass...@gmail.com wrote:

Hi,

Based on Neil’s instructions, I created a form that contains the

cascading styles. The steps I took are simple using the form

builder: - create a new form - do the Import CSV - paste the

example given above - save the form into an xml - copy the xml on my

phone. - kobo collect downloaded from : http://code.google.com/p/kobo/downloads/list

(It says Kob admin based on Open Data Kit (1.1.7-rc-1)

When trying to open the form and start the questionnaire, I get the

error: "XPath evaluation: unsupported construct [filter expression]"I

can not figure out what would be wrong. Basically the file is all

generated by the form builder and I only edited the title.Is there

something missing or obviously wrong.

Thanks

Y. Assefa

The xml generated is as follows:

<?xml version="1.0" encoding="UTF-8"?>www.w3.org/1999/xhtml" xmlns=“http://www.w3.org/1999/xhtml

xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns:jr="http://

openrosa.org/javarosa"> <h:head> <h:title>Test cascading</

h:title> <Test_cascading

id=“Test_cascading”>

</Test_cascading> <bind

id=“deviceid” nodeset=“/Test_cascading/deviceid” type=“xsd:string”

jr:preload=“property” jr:preloadParams=“deviceid”/> <bind

id=“start” nodeset=“/Test_cascading/start” type=“xsd:time”

jr:preload=“timestamp” jr:preloadParams=“start”/> <bind id=“end”

nodeset=“/Test_cascading/end” type=“xsd:time” jr:preload=“timestamp”

jr:preloadParams=“end”/> <bind id=“A01” nodeset="/Test_cascading/

A01" type=“xsd:string” required=“true()”/> <bind id=“District”

nodeset=“/Test_cascading/District” type=“xsd:string” required=“true()”/

 <bind id="County" nodeset="/Test_cascading/County"

type=“xsd:string” required=“true()”/> <bind id=“Neighborhood”

nodeset=“/Test_cascading/Neighborhood” type=“xsd:string”

required=“true()”/>

<data_ins_id>

<Neighborhood

label=“Agra” value=“1”/> <Neighborhood label=“Amba Dheri”

value=“2”/>

      <Neighborhood label="Charsadda MC-I" value="4"/>           

<Neighborhood

label=“Dakai” value=“6”/> <Neighborhood label="Deri

Zardal" value=“7”/> <Neighborhood label=“Dhakki”

value=“8”/> <County label=“Shabqadar”

value=“3”>

        <Neighborhood label="Shabqadar2" value="10"/>             

  </District>          <District label="DI Khan" value="2">       

<County label="Paharpur" value="4">              <Neighborhood

label=“Paharpur1” value=“13”/> <Neighborhood

label=“Paharpur2” value=“14”/> <Neighborhood

label=“Paharpur3” value=“15”/> <Neighborhood

label=“Paharpur4” value=“16”/> <County

label=“Kulachi” value=“5”> <Neighborhood label=“Kulachi1”

value=“17”/>

        <Neighborhood label="Kulachi3" value="19"/>            </
       <County label="Daraban" value="6">             

<Neighborhood

label=“Daraban2” value=“21”/> <Neighborhood

label=“Daraban3” value=“22”/> <County

label=“DI Khan” value=“7”> <Neighborhood label=“DI Khan4”

value=“23”/>

      </County>          </District>          <District

label=“Hangu” value=“3”> <County label=“HanguTehsil1”

value=“8”> <Neighborhood label=“HanguTehsil1UC1”

value=“25”/> <Neighborhood label=“HanguTehsil1UC2”

value=“26”/> <Neighborhood label=“HanguTehsil1UC3”

value=“27”/> <County

label=“HanguTehsil2” value=“9”> <Neighborhood

label=“HanguTehsil2UC1” value=“28”/> <Neighborhood

label=“HanguTehsil2UC2” value=“29”/> <Neighborhood

label=“HanguTehsil2UC3” value=“30”/>

<Neighborhood

label=“HanguTehsil3UC1” value=“31”/> <Neighborhood

label=“HanguTehsil3UC2” value=“32”/> <Neighborhood

label=“HanguTehsil3UC3” value=“33”/> </

   </data_ins_id>      </instance>      <itext>       

QuestionA01 <text

id=“A01_1”> OptionA01_1

</translation>      </itext>    </model>  </h:head>  <h:body>   

  <label ref="jr:itext('A01_1')"/>        <value>1</value>      </

District</

 <itemset nodeset="instance('data_ins_id')/data_ins_id/

District">

</itemset>    </select1>    <select1 bind="County">     

County <itemset nodeset="instance(‘data_ins_id’)/

data_ins_id/District[@value = /Test_cascading/District]/County">

Neighborhood <itemset

nodeset="instance(‘data_ins_id’)/data_ins_id/District[@value = /

Test_cascading/District]/County[@value = /Test_cascading/County]/

Neighborhood"> <value ref=“@value”/

 </itemset>    </select1>  </h:body></h:html>

On Dec 29, 1:50 pm, assefa ass...@gmail.com wrote:

Thanks Neil. I am trying it now based on these instructions. I will

update as soon as I have something.

best regards,

You received this message because you are subscribed to the Google Groups “Kobo Users” group.

To post to this group, send email to kobo-...@googlegroups.com.

To unsubscribe from this group, send email to kobo-users+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/kobo-users?hl=en.

Hi,

Attached is the xml. Sorry about the best. If you also have a

working xml and willing to share, can you send it to me?

best regards,

cascading_styles_2.xml (5.43 KB)

···

http://
www.w3.org/1999/xhtmlhttp://www.w3.org/1999/xhtml
http://www.w3.org/2001/XMLSchemahttp://
openrosa.org/javarosa

On Dec 29, 1:50 pm, assefa <ass...@gmail.com >
wrote:

            > Thanks Neil. I am trying it now based on these

instructions. I will

            > update as soon as I have something.

            >

            > best regards,

            --

            You received this message because you are subscribed to

the Google Groups “Kobo Users” group.

            To post to this group, send email to kobo-...@googlegroups.com.

            To unsubscribe from this group, send email to kobo-users+...@googlegroups.com.

            For more options, visit this group at [http://groups.google.com/group/kobo-users?hl=en](http://groups.google.com/group/kobo-users?hl=en).

kobo-...@googlegroups.com
kobo-users+...@googlegroups.com
http://groups.google.com/group/kobo-users?hl=en

Hi all,

The xml I produced seems to be valid and was tested by Tino. He also
sent me an example of xml produced by him and working on his phone.
His xml did not work on my phone (giving the same Xpath evaluation
error).
The only difference as suggested by Tino, might be that I downloaded
the application from the http://code.google.com/p/kobo/downloads/list
(I did not have access to android market on one of the phones).
Using another phone with android market, I was able today to get kobo
and successfully run the cascading styles xmls.

Can some one confirm that the versions of KoboCollect in the market
and the download site are different?

Thanks.

best regards,

Addition info on this: I downloaded the source code
(hg clone Google Code Archive - Long-term storage for Google Code Project Hosting.) and did a local build that
I installed on my phone.
I have the exact error message (XPath evaluation) with the locally
build version when using forms that contain the cascading styles.
Hopefully this is meaningful information.

best regards,

PS:Happy New Year

···

On Dec 31, 8:53 am, assefa <ass...@gmail.com> wrote:

Hi all,

The xml I produced seems to be valid and was tested by Tino. He also
sent me an example of xml produced by him and working on his phone.
His xml did not work on my phone (giving the same Xpath evaluation
error).
The only difference as suggested by Tino, might be that I downloaded
the application from thehttp://code.google.com/p/kobo/downloads/list
(I did not have access to android market on one of the phones).
Using another phone with android market, I was able today to get kobo
and successfully run the cascading styles xmls.

Can some one confirm that the versions of KoboCollect in the market
and the download site are different?

Thanks.

best regards,

Assefa,

I’m glad that worked for you. In fact, the code site may reflect a more experimental version of the KoBo App, the most current stable version is always found in the Android Market.

☞§※☼:airplane::open_umbrella::slight_smile:

~Neil

···

On Fri, Dec 30, 2011 at 11:53 PM, assefa ass...@gmail.com wrote:

Hi all,

The xml I produced seems to be valid and was tested by Tino. He also

sent me an example of xml produced by him and working on his phone.

His xml did not work on my phone (giving the same Xpath evaluation

error).

The only difference as suggested by Tino, might be that I downloaded

the application from the http://code.google.com/p/kobo/downloads/list

(I did not have access to android market on one of the phones).

Using another phone with android market, I was able today to get kobo

and successfully run the cascading styles xmls.

Can some one confirm that the versions of KoboCollect in the market

and the download site are different?

Thanks.

best regards,

You received this message because you are subscribed to the Google Groups “Kobo Users” group.

To post to this group, send email to kobo-...@googlegroups.com.

To unsubscribe from this group, send email to kobo-users+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/kobo-users?hl=en.

Thanks.

 But I am facing an issue: most of the phones do not have access to Android Market so I can not get them from there. That is the reason I tried the download and also built the application locally.

I have done the built using latest code from the repository as well as the version tagged rc1 (from July 24th 2011). In both builds (as well as the apk found on the download site), the test cascading forms give the "Xpath evaluation error" (These are the exact same forms that worked with the kobo version from the market). 

Is there any reason that you might think of that can explain that?

What would the revision or tag version that I can grab from the repository that would give me the same source base used to produce the market version of the application?

Thanks

best regards,
···

kobo-...@googlegroups.com
kobo-users+...@googlegroups.com
http://groups.google.com/group/kobo-users?hl=en