Can't get the "Dynamic defaults in repeats example" work

I try to make use of dynamic default but I can't get the example work.

tree_default_example.xlsx (459,6 Ko)

Here is the error I get from central :

Le XLSForm n'a pas pu être converti : ODK Validate Errors:
>> XForm is invalid.
: Invalid XPath in value set action declaration: ' ${tree} [position() = position(current()/..) – 1]/species'
    Problem found at nodeset: /html/body/group[@ref=${tree}]/repeat[@nodeset=${tree}]/setvalue
    With element <setvalue ref="${species}" value=" ${tree} [position() = position(current()/..) – 1]/species" event="odk-instance-first-load odk-new-repeat"/>


The following files failed validation:
${tmp1u0tfwsc}

Result: Invalid

I check twice and I can't find the error :frowning:

Hello, @mathieubossaert

Your file just needs a small adjustment to the minus characters. For some reason, your XLSX file uses a different dash “–” instead of the standard minus operator “-”. Possibly due to your spreadsheet editor.

To fix this, simply replace that character, and your formula should work correctly.

Here’s the corrected version:

${tree}[position()=position(current()/..)-1]/species

I also recommend avoiding spaces in mathematical operations to prevent similar issues caused by autocorrect features in editors like Excel, LibreOffice, etc.

Hope this helps! Let me know if you need further assistance.

Best,

tree_default_example.xlsx (458.2 KB)

2 Likes

When a 'non-breaking hyphen' becomes a breaking hyphen :smiley: (ok, so it's an en-dash, but that ruins the joke)

@mathieubossaert did you author the expression in Word or similar? Entering a minus (unicode 45) followed by a space and then more text autocorrects to an en-dash (unicode 8211)

2 Likes

:sob:

I did a copy/paste from Firefox to LO calc.

Thanks a lot for your help. I'll be aware next time.