Expressions: Support of statements and user defined functions

Dear All,
I’m new to KoBoToolbox, so, i would like to know if we use programming statements such as Do, While, For, If for constructing expressions.
Another, i would like to know if i can construct my own user defined function to validate data.

Best, Regards,

ODK Collect/KoboCollect is build upon the W3C XForms standard, which in turn use XPath expressions for its calculations and expressions. Currently XPath 1.0 - plus a few extensions - are supported, which unfortunately doesn’t include the likes of do/while/for loops, although the if() function is supported.

[Realistically, full advanced XPath 2.0/3.0 support probably isn’t coming anytime soon - its nontrivial to implement].

KoBoCollect/ODK Collect are open source projects, so absolutely you can implement whatever additional functions you desire [indeed I’ve contributed a few myself: substring-before(), substring-after(), translate()]. The changes have to be made in javaRosa - the core library that underlies most of the client’s XForm processing; specifically I’d recommend start looking look at:

Once you added you own function(s) you’d need to rebuild your client app from source - eg KoboCollect, ODK Collect - using your new javaRosa library, at which point you’d be able to use these in your own XForms. Alternatively (and preferably?), if you can make a good case why these changes should go into mainline, then you may be able to submit a javaRosa PR (Pull Request) and the open source maintainers will consider pulling your changes in and update the code-base, which would appear in the next release.


Thanks @Xiphware . I have combined your response into one to form a comprehensive solution to this.

1 Like

Dear @Xiphware, @stephanealoo,
Thank you for your reply. However, it will be very difficult to implement librairies of function from scratch in Java. But, i’ll analyze. I already look at for analyzing. I’ll be back to you for more explanations.

Best Regards,