I am using choice filter to filter the options. I want to skip the question or add “none” option if filtered option list is blank .
For example:
I have lists of State and car brands and I want to display the models based on selected state and brands.
If suppose that the selected state and brand do not have any list of model available. I that case I want to skip the question or if skipping is not possible display “None” option.
Here’s a form that will completely hide the selection question when the filter is such that there are no options that match (!). The trick is using a relevant to hide it, with the relevant expression effectively applying the same choice filter against the same options, but as a dataset filter.
This exploits a little known trick where you can also treat your selection choice lists as internal datasets, and look things up in them with an appropriate instance(‘my_list_name’)/root/item[my_filter]. By applying the same filter that you are using for your choice_filter, and count()’ing the resulting nodeset size, you can identify when the filter is going to return no results, and use this for your relevant expression to hide then the question.
As you can see in my form, the various choices are filtered depending on whether you enter male or female. In the case of the last selection question, all the choices in optionsC require that you enter female. If you enter male (or nothing) the instance() filter will return an empty nodeset, causing the question to be hidden.
Whereas the other two selection questions have no such show/hide logic, so they continue to present an empty list initially before you have answered male vs female.