ODK XForms spec proposal: add `normalize-space` XPath 2.0 function

Problem description

I would like to be able to easily strip leading and trailing whitespace in ODK. Because of how keyboards on Android tablets or phones work, spaces are often added at the end text entry. This can be a problem when trying concat(${name}, '-', ${age}) and expecting there not to be whitespace. Another issue would be if pressing and a newline is at the end of ${name}.

Proposed solution

I propose to implement the normalize-space XPath 2.0 function in Javarosa. For a definition, see https://www.w3.org/TR/xpath-functions-31/#func-normalize-space.

This function works on whitespace in the middle of text as well, but that is suitable to me.

I am interested in the one-argument form, but the spec defines a zero-argument form as well. What comments are there surrounding these two forms? Which to include?

This function would fit nicely in the spec at https://opendatakit.github.io/xforms-spec/#fn:String-Functions

Related material

Source github issue: https://github.com/opendatakit/javarosa/issues/460

Postscriptum

@LN would you please tag important stakeholders for this topic?

4 Likes

I agree!

Only proposed change is to refer XPath 1.0 instead (for consistency): https://www.w3.org/TR/1999/REC-xpath-19991116/#function-normalize-space (I'm assuming it has remained unchanged in 2.0).

(P.S. this function is already accidentally supported in Enketo but it has been a secret until now)

I strongly agree, probably much for the same reason as @martijnr: libxml2 already supports the XPath1.0 version of normalize-space() so its no work for me either, ha! :grin:

[unless of course I get tapped to have to do the javaRosa implementation... :wink: ]

Oh, great, then it's really a no-brainer! For some reason I got the impression it wasn't in XPath 1.0.

Perfect, let's make it so, then.