XLSForm Docs
XLSForm Docs
The columns you add to your Excel workbook, whether they are mandatory or optional, may
appear in any order. Optional columns may be left out completely. Rows or columns may be
left blank to aid readability, but data after 20 adjacent blank columns or rows on a sheet will
not be processed. All .xlsx file formatting is ignored, so you can use dividing lines, shading,
and other font formatting to make the form more readable.
One thing to keep in mind when authoring forms in Excel is that the syntax you use must be
precise. For example, if you write Choices or choice instead of choices, the form won't work.
Question types
XLSForm supports a number of question types. These are just some of the options you can
enter in the type column in the survey worksheet in your XLSForm:
GPS
For example, to collect the name and GPS coordinates of a store, you would write the
following:
To collect a line or shape of GPS coordinates, you can use one of the following:
See the question_types XLSForm for a look at each question type being used in a form.
Multiple choice
XLSForm supports both select_one (select only one answer) and select_multiple (select
multiple answers) questions. Writing a multiple choice question requires adding a choices
worksheet to your Excel workbook. Here is an example of a select_one question:
Note that the yes_no in the survey worksheet must match the yes_no in the list name
column in the choices worksheet. This ensures that the form displays the correct list of
answer choices for a particular question.
We can also add multiple choice questions that allow multiple answers to be selected, like so:
Choice names
The name column of the choices sheet defines the values that will be saved when each choice
is selected during data collection. Choice names for select_multiple must not contain spaces
because spaces are used as a separator when an answer with multiple selected choices is
saved. Choice names for select_one questions may contain spaces. However, we
recommend avoiding them to make analysis easier. Additionally, this makes it possible to
convert the question to a select_multiple in a future form version.
In general, choice names should be unique within a single choice list. If two choices from the
same list have the same name, they will be impossible to tell apart in analysis. If you have
duplicate choice names, you will get an error, and your form will not be converted. However, it
may sometimes be appropriate to have duplicate choice names. An example would be if you
use a cascading select, and the choices with the same name are differentiated by a preceding
question. If you do need to use duplicate choice names, you can suppress the error by using
the allow_choice_duplicates setting:
allow_choice_duplicates
yes
◄► survey choices settings +
Specify other
For multiple choice questions, surveys often include an option of marking other when their
answer choice is not listed. Then, they are usually asked to specify the other option. This is
possible through XLSForm by including or_other after the answer choice list name in the
survey worksheet. The choices worksheet stays the same. See below:
Caveat
When you export data using this or_other option, in the favorite_topping column, you will
see a value other. A separate column will have the answer for the questions in which the user
selected other. This makes data analysis more cumbersome, so we do not recommend the
or_other construct for large scale data collection efforts. See the Relevant section below for
an alternative method more appropriate for large scale projects.
Location widget
A user may want to select a location from a map view during data collection. To enable this
feature, you need to add the map or quick map appearance attribute to a select_one
question. The choices sheet will also need a geometry column added for the list_name noted
in the select_one questions. The geometry must be specified using the ODK format. This
feature is only currently available on ODK Collect. See below:
The files require a specific format. A CSV file requires a name and label column which
represent the value and label of the options. An XML file requires a structure as shown below:
<root>
<item>
<name/>
<label/>
...
</item>
</root>
A GeoJSON requires each feature, or point, to have an id and title property, or an attribute of
the point. The GeoJSON must be defined by a single top-level FeatureCollection, and it
currently only works for point geometry, as noted in detail on the ODK documentation site.
CSV, XML, and GeoJSON files may have additional columns, XML nodes, or features and
custom properties as long as the above-mentioned basic requirements are met.
If the CSV, XML, or GeoJSON files use different names for the choice name and label, add a
column to the survey sheet named parameters, and specify the custom names with the
value and label parameters. See usage examples below:
Note that, this question type is generally the preferred way of building select questions from
external data as it is the most versatile and works across applications. However, if your
external data file consists of many thousands of lines, please test carefully whether the
performance is satisfactory on the lowest spec device you intend to use. If it is too slow,
consider using External Selects or Dynamic selects from preloaded data if your data collection
application supports it.
Rank
The rank widget can be used to let respondents order a list of options. The answer is saved
as an ordered, space-separated list of option values where all options are always included.
The syntax is very similar to multiple-choice questions.
rank pizza_toppings toppings Order pizza toppings with your favorite on top
◄► survey choices settings +
To prevent bias it is often recommended to use the randomize feature in conjunction with this
widget.
Range
To restrict integer or decimal inputs to a specific range, you can use the range question. This
question can be used with 3 optional space-separated parameters: start, end, and step in a
parameters column. The default values are 0, 10, and 1 respectively. The example below will
create a question that allows input from 0 until 17 with a step of 1. Using a decimal step will
result in decimal values being collected.
range amount What is the age of the child? start=0 end=17 step=1
◄► survey choices settings +
To display a range question as a rating widget using stars, you can add the rating
appearance as shown below:
range rated What rating do you give? rating start=1 end=5 step=1
◄► survey choices settings +
Image
To upload an image file the image question type can be used. To ensure the images are not
too large, you can optionally set the max-pixels parameter which will automatically downsize
the uploaded image to match the largest side of the image with the pixel value provided.
Metadata
XLSForm has a number of data type options available for meta data collection:
Note that some metadata fields only apply for mobile phone-based forms.
For example, if you wanted to collect all of these types of metadata, put the following in your
form (typically at the beginning, but can be at any point of your form):
start start
end end
today today
deviceid deviceid
phonenumber phonenumber
username username
email email
audit audit [optional, see below]
◄► survey choices settings +
Notice that there are no labels associated with the metadata question types. This is because
the phone captures these variables automatically. These questions will not appear on the
screen of the phone, but you will see them when viewing your submitted survey data. The
Tutorial XLSForm shows how metadata is used in a form.
Note: For now this feature is only available in Collect, but not in Enketo webforms.
The audit metaquestion will enable ODK Collect to log how people navigate through a form
during data entry. For example, this can be used to measure how much time an enumerator
took to fill in a question, responses that were edited later on, or when the form was saved.
Optionally, the audit metaquestion can be configured to also record the location of the
enumerator throughout the interview. This may be useful for quality control or to record exact
paths taken between each respondents. To do this, add a column called parameters to your
form and enter three required parameters: location-priority, location-min-interval, and
location-max-age.
This example below would collect the precise GPS location every 180 seconds and will
discard coordinates collected more than 300 seconds ago.
location-priority=high-accuracy location-min-
audit audit
interval=180 location-max-age=300
◄► survey choices settings +
See this page in the ODK Collect documentation for full details about the audit metaquestion,
available location tracking parameters, and the format of the [Link] log file created for
each submission.
If your external data file consists of many thousands of lines, please test carefully whether the
performance is satisfactory on the lowest spec device you intend to use. If it is too slow,
consider using External Selects instead if your data collection application supports this.
xml-external houses
integer rooms How many rooms?
count(instance('houses')/house[rooms =
calculate count
current()/../rooms ])
◄► survey choices settings +
Hints
Regular hints
Sometimes you want to add a small hint to a question on your form, instructing the user how
to answer the question, but you don't want the hint to be part of the question itself. It’s easy to
add hints to questions in XLSForms. Simply add a hint column and add your hint message.
See below for an example.
Guidance hints
There is a special kind of hint that is normally not shown in the form. It is only shown in
special views. An example would to show these hints on print-outs or during a training for
enumerators. These hints are called guidance hints and can be added in the guidance_hint
column. See below for an example.
Formulas
Formulas are used in the constraint, relevant, calculation, and trigger columns and optionally
also in the default, and required columns. Formulas allow you to add additional functionality
and data quality measures to your forms.
Formulas are composed of functions and operators (+,*,div,etc.). A well-documented full list of
operators and functions can be found in the ODK documentation. For the technically inclined,
the underlying XForms specification is the actual source document for the supported
functions.
Constraints
One way to ensure data quality is to add constraints to the data fields in your form. For
example, when asking for a person's age, you want to avoid impossible answers, like -22 or
200. Adding data constraints in your form is easy to do. You simply add a new column, called
constraint, and type in the formula specifying the limits on the answer. In the example below,
the answer for the person's age must be less than or equal to 150. Note how the . in the
formula refers back to the question variable.
In this example, the formula . <= 150 is saying that the value entered . for the question must
be less than or equal to 150. If the user puts 151 or above as the answer, s/he will not be
allowed to move on to the next question or submit the form.
Other useful expressions to use in the constraint column can be found here. Look under the
Operators section.
Constraint message
If you want to include a message with your constraint, telling the user why the answer is not
accepted, you can add a constraint_message column to your form. See the example below.
In this example, if the user enters an age less than 18, then the error message in the
constraint_message column appears. More examples on constraints have been illustrated in
this XLSForm.
Relevant
One great feature of XLSForm is the ability to skip a question or make an additional question
appear based on the response to a previous question. Below is an example of how to do this
by adding a relevant column for a select_one question, using our pizza topping example
from before:
Do you like
select_one yes_no likes_pizza
pizza?
select_multiple pizza_toppings ${likes_pizza} =
favorite_topping Favorite toppings
or_other 'yes'
◄► survey choices settings +
In this example, the respondent is asked, “Do you like pizza?” If the answer is yes, then the
pizza topping question appears below. Note the ${ } around the variable likes_pizza. These
are required in order for the form to reference the variable from the previous question.
In the next example, below, we use relevant syntax for a select_multiple question, which is
slightly different from the select_one question example above.
Since the pizza topping question allows multiple responses, we have to use the
selected(${favorite_topping}, 'cheese') expression, because we want the cheese
question to appear every time the user selects cheese as one of the answers (regardless of
whether additional answers are selected).
Earlier we mentioned there was an alternative method for specifying other for multiple choice
questions which is more appropriate for large scale surveys. This can be done using the same
relevant syntax from the example above:
Note that you must include other as an answer choice in the choices worksheet.
Calculation
Your survey can perform calculations using the values of preceding questions. In most cases
using a calculate type question is appropriate. For example, in the survey below, we have
calculated the tip for a meal and displayed it to the user:
Note that the ${tip} in the last line will be replaced with the actual tip amount when viewing
and filling out the form.
The calculate type calculates text but calculations can also be added to any other question
types. Non-text types can be useful for data analysis, e.g if a date or date-time is calculated. If
no label and no hint is included, the calculation will be hidden. See example below which
is the equivalent of the previous form:
And this is an example when a non-text type is needed because of data analysis
requirements:
Note that using non-text calculation types has no effect on using the calculation result
within the form itself. This is a common misunderstanding.
If a label or hint is included, the question will be visible on the form and the calculated value
will be shown in the input field or widget. This is generally only recommended for readonly
questions to avoid re-calculating (erasing) a user-entered value. See example below:
Note the difference with the first form in this section is how the calculated tip value is
displayed. In the first example it was shown in the label and in the last example it is shown
inside a readonly input field.
Trigger
A trigger column can be used to run a calculation only when another visible question in the
form changes. This means that the question that is serving as the trigger has to have a
label or a hint (otherwise it will be hidden). See a simple but very useful example below:
This will calculate a timestamp immediately after a respondent enters a temperature. If the
user goes back and changes the temperate, the timestamp will be re-calculated.
All the regular calculation features apply to these special value-change-triggered calculations
as well. So you can e.g. use a label or hint to display the calculation question on the form to
the user.
Multiple questions may have the same trigger. See this example, where two calculations are
triggered by the temperature question (one is hidden, and the other is shown):
In the form above the temp_F question is shown to the user and the temp_K question is
hidden, just as they would be if trigger was not used.
An important and powerful difference with regular calculations is that the calculation value
with a trigger may also be empty, which serves to clear a value from the form. See example
below:
If the respondent using this form has entered the name and age of person A and subsequently
finds out there is an older person B, the age field will be cleared as soon as the name of
person B has been entered.
Required
It's simple to mark certain questions as required in your form. Marking them as required
means the user will not be able to move on to the next question or submit the form without
entering an answer for that question.
To make questions required, add a required column to your survey worksheet. Under that
column, mark questions as required by writing yes. See the example below:
Required message
If you want to customize the message displayed to users when they leave a required question
blank, you can add a required_message column to your form. See the example below.
Randomize Choices
For any question type that shows a list of choices the shown order of the choices displayed
to the user can be randomized with the parameters column. See below:
For reproducible randomization, a seed can be explicitly provided as shown below. To learn
more about the randomization algorithm used, see here.
once(decimal-date-
calculate sd
time(now()))
select_one randomize=true,
top Favorite?
toppings seed=${sd}
◄► survey choices settings +
Note that once() is used to prevent re-randomizing for example when a draft record is loaded
for editing.
Grouping questions
To create a group of questions in your form try the following:
This is a good way to group related questions for data export and analysis. Notice how end
group doesn't require a name or label, because it is hidden in the form.
You always have to end the most recent group that was created first. For instance, the first
end group you see closes the HIV medication group, and the second one closes the
beginning hospital group. When working with groups and you keep getting error messages
when trying to upload your form, double-check that for each begin group you have one end
group.
Skipping
One neat feature of XLSForm is the ability to skip a group of questions by combining the
group feature with relevant syntax. If you want to skip a group of questions all at once, put the
relevant attribute at the beginning of a group like follows:
In this example, the two child group questions (muac and mrdt) will only appear if the child's
age from the first question is less than or equal to five.
Repeats
A user can repeat questions by using the begin repeat and end repeat construct:
In this example, the name, birthweight, and sex fields are grouped together in a repeat, and
the user can collect the same information about multiple children by selecting the option in the
form to add another repeat.
The label column is optional for begin repeat. Assigning a label to a repeat will add the label
as a title to the block of repeat questions in the form.
When a repeat is shown in a table of contents, the label used to represent each repeat is the
label of the first group inside that repeat. In the example below, if a repeat is filled out with
values Preity for first_name, Zinta for last_name and 71 for age, that repeat will be
summarized as "Preity Zinta - 71":
teach the people filling out the form to delete the first repeat added
if the exact number of repeats is known ahead of time, use a dynamic repeat count
if the exact number of repeats is not known ahead of time, use relevant to only prompt
the user for repeats if there are some to add
integer age How old are you? ¿Cuántos años tienes? . <= 150
◄► survey choices settings +
You can also add different language columns for hints and media files by using the same
::language (code) construct, as shown in the example below. See also the XLSForm
reference table, which includes a list of all column headers that can accept a language
modification.
Form language and user interface language may be the determined separately by the
application and may not match. To facilitate matching both (in the future), it is recommended,
though optional, to add a 2-character language code after the language name. The official 2-
character language codes, called subtags are published here (search the page with Ctrl-F or
Cmd-F).
Media
You can include questions in your form that display images or that play video or audio files. If
using the ODK mobile client for form submission, you need to put the media files that you
want to include in the /odk/forms/formname-media folder on your phone, and then reference
the exact file name in the media column in your form. See below for an example of how to do
this.
Check out the Birds XLSForm which illustrates the use of media files. You can also click on
the link to see the Birds webform .
Media is translatable in the same way as labels and hints as explained in the languages
section.
Upload one or more .csv files as support files when you upload your form definition (the
same way you upload media support files as explained in the Media section).The first row
of each .csv file should be a header that includes short:
unique names for each column
subsequent rows which should contain the data itself
Each csv file should contain at least one column that can be used to uniquely identify each
row. Such columns will be used, at survey time, to look up which row's data to pull into the
survey. For the columns that will be used for looking up rows add _key to the end of the
column name in the first row. Any columns with names ending in _key will be indexed for
faster look-ups on your survey devices. See below an example of the columns on a .csv file:
name_key name
mango Mango
orange Orange
Once you have loaded .csv data into a survey field using the pulldata() function, you can
reference that field in later relevance conditions, constraints, and labels, just as you would
reference any other field that was filled in by the user.
Click on the link to see an example of a pre-loading sample form and the .csv file used with
form can be found here
Compress a large .csv file into a .zip archive before uploading it.
Save .csv file in UTF-8 format if pre-loaded data contains non-English fonts or special
characters this enables your Android device to render the text correctly.
Data fields pulled from a .csv file are considered to be text strings therefore use the int() or
number() functions to convert a pre-loaded field into numeric form.
If the .csv file contains sensitive data that you may not want to upload to the server, upload
a blank .csv file as part of your form, then replace it with the real .csv file by hand-copying
the file onto each of your devices.
Once your form has one or more pre-loaded .csv files, you can dynamically pull the choice
lists for select_one and select_multiple fields from those .csv files. Multiple-choice fields
with dynamic choice lists follow the same general syntax as regular, static select_one and
select_multiple fields as previously covered in the Multiple choice questions section.
There are three differences when the choice list should be pulled from one of your pre-loaded
.csv files:
Click on the link to see an example of a search-and-select sample form and the .csv file used
with form can be found here.
There are a series of options to indicate which .csv rows to include in the choice list using the
search() expression, see this post for additional information on these search() expressions.
Cascading selects
A lot of forms start out by asking the location of the respondent, with each location selection
specifying what the subsequent location choices will be (e.g., state » district » village).
Instead of adding a select_one field for each location option, you can use cascade select. In
order to use cascade selects, you will need to create a choice_filter column in your survey
worksheet and add the location attribute columns in your choices worksheet. Check out an
example XLSForm here.
External selects
If a form has selects with a large number of choices (e.g., hundreds or thousands), that form
can slow down form loading and navigation if Multiple Choice from File is used. The best
workaround to this issue is to use external selects in those data collection applications (such
as ODK Collect) that support it.
See select_one_external form for an example that uses normal and external choices.
When an XLSForm with external choices is converted to an XForm, two files will be produced,
the XForm (e.g., [Link]) with all the normal choices, and an [Link] with the
external choices.
The [Link] file can be uploaded to any ODK-compatible server (e.g., ODK Aggregate)
as a media file. It will be downloaded to any ODK-compatible (e.g., ODK Collect) like any
other media file and saved to the [form-filename]-media folder. Clients like ODK Collect load
media files from the SD card and so your form with a large number of choices will now load
very quickly.
Default
Adding a default field means that a question will be pre-populated with an answer when the
user first sees the question. This can help save time if the answer is one that is commonly
selected or it can serve to show the user what type of answer choice is expected. See the
example below.
The respondent can simply change the answer by tapping in the answer field and entering
another answer.
You can also add a default calculation, which will only be calculated only once when the form
loads or - if the question is inside a repeat - when the repeat is added.
Read only
Adding a read only field means that a question can not be edited. Read only fields can be
combined with default fields to deliver information back to a user.
Appearance
The appearance column allows you to change the appearance of questions in your form. The
following table lists the possible appearance attributes and how the question appears in the
form.
Appearance
Question type Description
attribute
An XLSForm with all of the appearance attributes in this table is available here.
Settings worksheet
The settings worksheet is optional, but it is highly recommended to specify form_title,
form_id and version at a minimum. Other settings allow you to further customize your form,
including setting an overall style theme or encrypting your records.
concat(${firstname},
Example ex_id 2017021501 English (en) IIBIjANBg…
' ', ${lastname})
◄► survey choices settings +
form_title: The title of the form that is shown to users. The form title is pulled from form_id
if form_title is blank or missing.
form_id: The name used to uniquely identify the form on the server. The form id is pulled
from the XLS file name if form_id is blank or missing.
version: String that represents this version. A common convention is to use strings of the
form 'yyyymmddrr'. For example, 2017021501 is the 1st revision from Feb 15th, 2017.
instance_name: Expression using form fields to identify for each form submission. Learn
more.
default_language: In localized forms, this sets which language should be used as the
default. The same format as described for adding translations should be used, including
the language code.
public_key: For encryption-enabled forms, this is where the public key is copied and
pasted. Learn more.
submission_url: This url can be used to override the default server where finalized
records are submitted to. Learn more.
style: For web forms, specify the form style. Learn more.
name: XForms root node name. This is rarely needed, learn more.
Encrypted forms
Encryption-enabled forms provide a mechanism to keep finalized records private at all times.
This includes the time after a record is marked as final that it is stored on the device and
server as well as during transport, even when http is used for communication. Encrypted
records including their uploaded files, such as photos, are completely inaccessible to anyone
not possessing the private key.
To encrypt XLS forms, add the public_key column to the settings worksheet and paste the
base64-encoded public RSA key as its value.
form_id public_key
mysurvey IIBIjANBgklawWEserewrwesgdreewrwe32serfserfewrwerewtwer23sgfrqjwerk3423432…
◄► survey choices settings +
For more information on encrypted forms and how to generate the RSA keys have a look at
the ODK documentation and at this example form.
If this column is left out or kept empty, submissions will go the default destination for the
provider you are using for your surveys.
Check out this example XLSForm that calculates the instance name as the user's last and
first names coupled with the form submission uuid.
An example of a form divided into multiple pages can be seen on the Widgets on Pages
webform.
In the settings tab, create a column called style and set it to pages, as follows:
In your survey tab, group together the questions you would like to appear on each page and
then set the appearance for the group to field-list. See the example below.
See this blog post for more information on creating multi-page web forms. The XLSForm
source is here.
To create a Grid form, in the settings tab, under the style column, write theme-grid, as
follows:
In your survey tab, group together the questions you would like to appear in each section and
then set the appearance for each field according to the desired width (the default width is 4).
See the example below.
See this blog post for more information on creating Grid forms. The Grid theme XLSForm
example is here.
Styling prompts
Markdown support in XLSForm allows for increased emphasis through bold and italics,
different sized headers, various fonts and colors, and clickable web links in ODK Collect 1.4.9
and Enketo.
The survey sheet has support for 3 column prefixes (instance::, bind::, body::) that add
attributes to the XForm output, either in the primary instance, bind, or form control. To learn
more about XForms visit the ODK XForms Specification. The example below adds a custom
"hxl" attribute to the primary instance node of a question.
The settings sheet has support for defining (multiple space-separated) additional custom
namespaces and namespace prefixes using the namespaces column. You'll then be able to
use those namespaces in the survey sheet, for example to properly define a custom attribute
with your organisation's own namespace. See example below that adds 2 additional
namespaces and uses them to add custom attributes:
title namespaces
More resources
The XLSform standard document can guide you through the specific input types, column
headers, and so on that are legitimate syntax in XLSForms. If you want to dig in deeper to
understand XForms and go beyond XLSForms, here are some resources to understand them:
If you want to contribute to or improve this documentation, please visit our project's GitHub
repo.
History
The XLSForm was originally developed by Andrew Marder and Alex Dorey of the Sustainable
Engineering Lab at Columbia University. As XLSForms became adopted by the ODK
Community, SEL worked with the ODK Team to develop the current specification. PyXForm,
the library used to convert XLSForms to XForms, is an open source project supported by
members of ODK, SEL, Ona, SurveyCTO, and KoBoToolbox.
[Link]
[Link] This site will help you author XLSForms. XLSForm is a tool
info@[Link] used to simplify the creation of forms. XLSForm will convert
forms authored in Excel into XForms that can be used with a
number of web or mobile platforms.