Gaining customer insight has very high business value. In the last blog, I showed you how you can gain customer insight without introducing bias by randomizing the answers to each question you ask. In a prior blog, I showed you how you can make the presentation layer be dynamically responsive to the type of question you are asking. In this blog, we'll cover how to randomly select the subset of questions to be asked of a particular user. This is important in avoiding survey fatigue and low response rates that can result from surveys that take too long to complete.
As in the prior blog entry that presented survey items of different types, suppose you have an XForms instance that includes any number of items of interest, where each <item> includes a prompting question, a type of answer, storage space for an answer, and so forth. The goal is to have the form template initialize itself with a small subset of these <item> elements, and once again to do so randomly, i.e. without bias, so that over a large customer population, we will get a close-to-equal response rate on all items of interest.
Let the following two XForms instances exist:
<xforms:instance id="AllItems" xmlns="">
<!-- All survey item elements -->
<xforms:instance id="ChosenItems" xmlns="">
<items random="" i="" number="3">
<!-- Initially empty, will contain "number" item elements chosen from AllItems -->
Data initialization in XForms can be done in the xforms-ready event but is more typically done in the xforms-model-construct-done event because it is more efficient to manipulate the data before the user interface is created. So, you'd randomly choose some survey items from all the items like this:
<xforms:action if="count(instance('ChosenItems')/item) = 0"
<xforms:setvalue ref="instance('ChosenItems')/@random" value="random(true())"/>
<xforms:action while="instance('ChosenItems')/@i <= instance('ChosenItems')/@number">
<xforms:setvalue ref="instance('ChosenItems')/@random" value="random(false())"/>
The if statement on the main action ensures that the random selection only happens once, when a copy of the form template is used for the first time, thereby becoming a form. The first setvalue action seeds the random number generator, and the second action initializes the loop variable. The main loop randomly chooses "number" items from AllItems and places them in the ChosenItems. Each selected item is then deleted from AllItems to avoid duplicate items.
The "number" of questionnaire items to select is shown to be 3 in the example, but it is really up to the designer(s) of the survey to set that number into the form template based on how many questions they feel their customers will answer without impeding the return rate due to survey fatigue.
Finally, rather than binding a user interface to the 'AllItems' data instance, you simply bind it to the 'ChosenItems instance instead. An XForms repeat iterates the user inteface controls within it for each of a set of nodes identified by the XPath in its nodeset attribute, like this:
<!-- XForms user interface controls, like input and select1, go here -->
Inside the repeat is where you could use simple XForms input controls for typed answers or select1 controls for choice-based answers, or this is where you could use dynamic user interface techniques to show different kinds of user interface controls based on a type of survey item.