XML to HTML table

These scripts illustrate ways in which a tabular XML document can be transformed to an HTML table
This set uses a common XML document which has a simple tabular structure.

1. Hard-coded

A script specific to this table.

2. Generic conversion

It is tedious to write a hard-coded script. If the structure of the file changes then the script would also have to change. An alternative is write a generic function which, using reflection on the data itself, could transform any tabular XML. To do this we use the XPath function fn:name() to obtain the name of an element, and the expression $row/*[name(.)= $header] to access the element in a sequence with a variable name. In this script we assume all items in the sequence have the same simple element structure determined by the structure of the first item.

3. Generic conversion assuming no missing cells

If there are no missing elements in any rows, a faster algorithm is possible.

5. Transformation with a mapping schema

The generic function produces a table but headings and the order of columns is determined by the data alone. To get more control over the format, we can create a configuration file. This also allows us to define an alternative column heading.

6. Mapping with data transformations

You might also want to transform data for presentation. We could add XPath expressions to the schema.

7. Code generation with a mapping schema

There is a performance penalty for using reflection. An alternative would be to generate code which could then be stored and compiled.

8. Executing the generated code

The generated code is included in a script.

9. Code generation and execution

We could generated the code and use util:eval to evaluate it in one script.