| Exporting text files | Creating formatted web pages from a spreadsheet | Excel to XML VBA |

Adding XML files to HTML web pages

This page is probably mostly redundant - simple data islands as a method of including XML files in a web page will no longer work in most browsers. More complex solutions are required.

I have rewritten my own projects using iFrames and HTML tables rather than XML files.


Previous examples have shown how unformatted XML files can be created from either Excel or Access. These data files can be viewed directly in a browser - but this is not a very user friendly format.

There are many options if you wish to enhance the display of XML data in your web browser. The solutions shown below are basic examples which require very little programming knowledge beyond HTML. If you understand Javascripts or ASP then there are smarter methods available.

XML using XSL styles

The following methods are only intended to be examples - very little explanation is offered and so it should be viewed in conjunction with an XML and XSL tutorial such as that offered by W3C schools. I am only illustrating the display of tables of data, not individual records. If you wish to copy the files in order to adapt them for your own purposes, it is easier to use the text files which are not affected by any formatting applied by your browser.

Note that these examples work in IE but not with the Firefox browser.

A Plain Table

An improved XML file can be displayed on a new web page. The original unformatted XML data file is modified and a new second line inserted giving a reference to a XSL stylesheet which causes the data to be displayed in an attractive table. Note that the XSL code adds a page heading, table column titles and applies CSS styles. The CSS is unnecessary if you are happy with standard formats for HTML tags such as <Table> and <H1>. No sorting or selection has been incorporated within this XSL.[View page] [View code]

A Table with Sorted Data

The XML file can receive instructions from the XSL file for formatting, sorting and criteria. If you want to offer users more than one option for the sorting order you can create a corresponding number of XML data files, each of which has a reference (on the second row) to a different version of the XSL instruction files. If you have large data files (XML) it may not be convenient to save numerous copies, merely to give different formatting, selection or sorting options. [View page] [View code]

A Table and Button Option

Another solution is to use short JavaScript instructions linked to buttons on a page. The buttons give the user the options of sorting by alternative fields or selecting just records which match a particular value. A new XSL file must be created for each button option but only a single XML file is required, making this more appropriate for larger data files. It also uses a simpler XSL file which doesn't contain any formatting details - only the data sort and criteria. The file ('authsig_java2.htm') uses XSL files: 'sortname.xsl', 'sortcode.xsl' and 'getfin.xsl'. Note that it is possible to sort by more than one field using a semi-colon to separate each of the field names. [View page] [View code]

A Table within an HTML page

An unformatted XML file can be displayed directly within any web page by including the displayed code (below) at the appropriate place in your HTML code. There is no reference to an XSL and therefore no sorting or selection.

Directorate

Code

Name

Value

Joined

<XML id="myauthsigs" src="myxml/xl_xml_data.xml"></XML>
<table class="red" datasrc="#myauthsigs">
<thead><tr>
<th>Directorate</th>
<th>Code</th>
<th>Name</th>
<th>Value</th>
<th>Joined</th>
</tr></thead>
  <tr>
    <td><div datafld="directorate"></div></td>
    <td><div datafld="acode"></div></td>
    <td><div datafld="name"></div></td>
    <td align="right"><div datafld="value"></div></td>
    <td><div datafld="start_date"></div></td>
  </tr>
</table>

This is a complicated topic and I have shown a few relatively simple solutions. Programming knowledge will enable you to produce more sophisticated solutions but that is beyond the scope of this site. The examples above will enable you to quickly share  up-to-date information on a web page.

Get this information as a document
accompanied by Excel worksheets
Click here for details about
obtaining this file

Page file: xl_xml2.htm © MeadInKent.co.uk 2011 Page last updated Nov07