Transform with Processing Instructions

Another way to perform a transformation is to include an xml-stylesheet processing instruction in the XML spreadsheet. The mso-application instruction supersedes other instructions, so you must replace that processing instruction in order to have a browser perform the translation. The following XML shows the changes you must make to the XML spreadsheet file: deletions are shown in strikethrough, and additions are shown in bold:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="worksheet.xslt"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
...

Now when a user opens the XML file, the file is transformed and displayed in the browser as shown in Figure 15-3.

The transformation shown in Figure 15-3 converts cells in a worksheet to HTML table elements. It also displays document properties of the workbook. The transformation is performed by the following XSLT fragment:

<xsl:template match="ss:Workbook"> <html> <body> <h1>Display XML Spreadsheets as HTML Tables</h1> Author: <xsl:value-of select="o:DocumentProperties/o:Author" /> <br /> LastSaved: <xsl:value-of select="o:DocumentProperties/o:LastSaved" /> <br /> Number of worksheets: <xsl:value-of select="count(ss:Worksheet)" /> <xsl:for-each select="ss:Worksheet"> <h2><xsl:value-of select="@ss:Name" /></h2> <table border="1" frame="box"> <xsl:for-each select="ss:Table/ss:Row"> <tr> <xsl:for-each ...

Get Programming Excel with VBA and .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.