| Feedback | Displaying XML files |

Using An XSL file and styles to display anXML file

The following file can be used to format the display of XML files. The XML file must be amended to include a second line with the following reference:

<?xml-stylesheet type="text/xsl" href="authsig_newpage.xsl"?>

The reference within the XSL file to some styles is optional and can be amended to reflect your own preferences. It allows you to control the formatting of a table, rather than the data being presented using the defaults chosen by Internet Explorer.

save as: 'authsig_newpage.xsl' (without sorting or selecting the XML data)
 

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<title>MeadInKent display XML using XSL</title>
<body>
<style type='text/css'>
body {font-family: Arial, Helvetica; font-size: 10pt; margin-left: 10; margin-right: 10}
td {padding: 1pt 3pt 2pt 3pt; border-style: solid; border-width: 1; border-color: #0F5BB9}
table {border-collapse: collapse; border-width: 1 ; border-style: solid; border-color: #0F5BB9 }
</style>

<h1>A list of authorised signatories</h1>
<table>
<tr>
<th>Directorate</th>
<th>User Code</th>
<th>Manager</th>
<th>Value</th>
<th>Start Date</th>
</tr>
<xsl:for-each select="meadinkent/record">
<tr>
<td><xsl:value-of select="directorate"/></td>
<td><xsl:value-of select="acode"/></td>
<td><xsl:value-of select="name"/></td>
<td align='right'><xsl:value-of select="value"/></td>
<td><xsl:value-of select="start_date"/></td>
</tr>
</xsl:for-each>
</table>
<p>Excel to XML - unsorted</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Note: if you wish to sort the XML data, replace the highlighted line above with something like this:

<xsl:for-each select="meadinkent/record" order-by="name">

or 

<xsl:for-each order-by="acode" select="meadinkent/record[directorate$eq$'Finance']">

To Copy and Paste the code shown above, it is best to Paste it initially into NotePad (or a plain text editor) in order to avoid any of the unwanted formatting instructions being included.


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