XQuery/HTML Table View

Motivation
When we have an XML file with uniform tabular structure, with no repeated or compound children, a generic table view is handy. We can use the XML element names as the column headers.

Sequence as HTML Table
Here is a function which achieves this. It takes a sequence of elements and creates an HTML table, one row per node in the sequence. It uses a little introspection with the name function to get the names of the children of the first node to form the column headings. For each node, the children is accessed by node name so that there is no requirement that all elements are present or in the same order as in the first node.

};

Example
Given XML with a [/transform/furniture.xml uniform tabular structure]

the following script will create the HTML table:

[/transform/xml-to-html-table.xq Execute ]

Discussion
This approach is ideal if you know that the first node in a dataset has all the elements for all the columns in the table.

This approach is used in the later Database example to display computed sequences.

The following line must be added if you are using strict XHTML. This puts all the HTML tags (

Sequence as CSV
A similar approach can be used to export the sequence as CSV.

[/transform/xml-to-csv.xq Execute]

Discussion
To save the file directly from the browser to a named file for loading intol a spreadsheet, add :