Count choices in filtered option list of cascade

I have a cascading select for locations and sub-locations. Not all locations have a sub-location and if that is the case, I want to use relevant to hide the sub-location question. Is there a way to do this?

I tried what is described in the post linked below, but it seems to always count the total number of sub-location options, not the length of the filtered list.
count_filtered_cascade_options.xlsx (16.2 KB)

Your count just needs to be a tiny bit more specific and include a filter to only count those that match location.

count(instance('sub_locations')/root/item[${location}=location_filter])

count_filtered_cascade_options_edit.xlsx (16.4 KB)

2 Likes

BTW, now that all choice lists in XLSForms are converted to nodesets (see https://github.com/XLSForm/pyxform/pull/614) there is no longer any need for circa 2019 'tricks' to accomplish this. :tada:

So as @ahblake most astutely states, you just need to perform a little XPath 'black magic' to include the equivalent cascading select filter into your count() input nodeset. Yes it is a bit obscure, but there is tremendous (hidden) power in these XPath expressions that let you accomplish magical things like this! :magic_wand:

2 Likes

Terrific. Thanks both! Much appreciated.