Yxf: Convert from XLSForm to YAML and back

If you are someone who manages many ODK forms, you might want to explore yxf: https://github.com/Sjlver/yxf.

yxf is a tool that converts forms from the XLSForm format to a text-based format. Both versions contain exactly the same information, but text files are a lot easier to store, compare, or bulk-update than spreadsheets.

The text-based format can be converted back into a valid XLSForm file. As a bonus, the result likely looks a lot prettier than the original.

To give an example: yxf allows you to go from a form to this representation:

survey:
- '#': Converted by yxf, from paani.xlsx. Edit the YAML file instead of the Excel
    file.
- type: start
  name: start
- type: end
  name: end
- type: select_multiple qe3sk00
  name: Question
  label: Question
  required: false
- type: begin_group
  name: group_A
  label: Question A
  relevant: selected(${Question}, 'A')
  appearance: field-list
- type: ...

... and back to this:

This is super cool (in my opinion) because it allows you to treat forms like code. You can now store them using a tool like git, easily compare them, perform bulk changes across many versions of a form, etc. For example, here is a comparison between two versions of a form, after a question has been made required:

 survey:
 - '#': Converted by yxf, from paani.xlsx. Edit the YAML file instead of the Excel
     file.
 - type: start
   name: start
 - type: end
   name: end
 - type: select_multiple qe3sk00
   name: Question
   label: Question
-  required: false
+ required: true
 - type: begin_group
   name: group_A
   label: Question A
   relevant: selected(${Question}, 'A')
   appearance: field-list
 - type: ...

yxf is in a very early stage of development. We welcome feedback, bug reports, and contributions. If you find yxf useful, let us know, too :slight_smile:

9 Likes

This is really a great idea, thanks a lot for sharing! I was already thinking about versioning CSV versions of XlsForms in Git, but it's not as human-readable. I will definetly look into that YAML variant!

1 Like

Yes, CSV is an idea that we had as well. I prefer YAML for a few reasons:

  • It can store all the sheets of the form (survey, choices, settings).
  • There's one line per cell, rather than one line per questions. This makes it easier to spot differences between forms.
  • It's just more readable.
  • When converting back to XLSForm, yxf can apply formatting to make the result look nice (see screenshot in the post).

Another idea we considered is to store the XML version (the XForm). But this is not that easy to read, and there is no way to convert it back into an XLSForm.

3 Likes

At the suggestion of Joshua Beretta, yxf now supports Markdown as an optional format, in addition to the default YAML.

Example conversion:
image

## survey

Converted by yxf, from basics.xlsx. Edit the Markdown file instead of the Excel file.

Hello, this is *an emphasized* <u>comment</u>.

| type             | name | label                                                         |
| ---------------- | ---- | ------------------------------------------------------------- |
| text             | name | What is \| your name? Please tell me, I'm **really curious**! |
| integer          | age  | How old are you?                                              |
| select_one foods | food | What is your favourite meal?                                  |
1 Like