Listing 1 XML data
<?xml version="1.0" encoding="UTF-8"?>
<Report ReportTitle="Library Inventory Report">
<Record>
<Title>Java and XML</Title>
<Author>Brett McLaughlin</Author>
<ReceivedDate>01/17/2001</ReceivedDate>
<Copies>2</Copies>
</Record>
<Record>
<Title>Java and XSLT</Title>
<Author>Eric M. Burke</Author>
<ReceivedDate>10/24/2001</ReceivedDate>
<Copies>2</Copies>
</Record>
<Record>
<Title>XML by Example </Title>
<Author>Benoit Marchal</Author>
<ReceivedDate>09/03/2001</ReceivedDate>
<Copies>1</Copies>
</Record>
</Report>

Listing 2 XSL stylesheet
<xsl:template match="Report">
<Row ss:Index="3" ss:AutoFitHeight="0" ss:Height="20.25">
<Cell ss:Index="2" ss:MergeAcross="1" ss:StyleID="s22">
<Data ss:Type="String"><xsl:value-of select=
"@ReportTitle"/></Data>
</Cell>
</Row>
<Row ss:Index="5">
<Cell ss:StyleID="s23">
<Data ss:Type="String">Title</Data>
</Cell>
<Cell ss:StyleID="s23">
<Data ss:Type="String">Author</Data>
</Cell>
<Cell ss:StyleID="s23">
<Data ss:Type="String">Received Date</Data>
</Cell>
<Cell ss:StyleID="s23">
<Data ss:Type="String">Copies</Data>
</Cell> </Row>
<xsl:for-each select="Record">
<Row>
<Cell ss:StyleID="s24">
<Data ss:Type="String"><xsl:value-of select="Title"/>
</Cell>
<Cell ss:StyleID="s24">
<Data ss:Type="String"><xsl:value-of select=
"Author"/></Data>
</Cell>
<Cell ss:StyleID="s24">
<Data ss:Type="String"><xsl:value-of select=
"ReceivedDate"/></Data>
</Cell>
<Cell ss:StyleID="s24">
<Data ss:Type="Number"><xsl:value-of select=
"Copies"/></Data>
</Cell>
</Row>
</xsl:for-each>
</xsl:template>

Listing 3 Java code for XSL transformation
import org.xml.sax.SAXException;
import org.apache.xalan.xslt.*;
public class XSLProcessor
{
public static void main(String[] args)
{
try
{
// create an instance of the XSLT processor.
XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
// perform the XSL transformation giving the "XML file name"
// and "XSL file name" as input
processor.process
(new XSLTInputSource(new java.io.FileInputStream(args[0])),
new XSLTInputSource(new java.io.FileInputStream
(args[1])),
new XSLTResultTarget(System.out));
}
catch( Exception e)
{
System.out.println("Exception in XSL processing" + e);
}
}
}

Listing 4 Entire XSL stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" xmlns:fo=
"http://www.w3.org/1999/XSL/Format" xmlns:x="urn:schemas-
microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<xsl:output method="xml"/>
<xsl:template match="/">
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:
office:office">
<Author>Prasad</Author>
<LastAuthor>Prasad</LastAuthor>
<Created>2001-12-24T15:03:24Z</Created>
<Company></Company>
<Version>10.2625</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:
office:office">
<DownloadComponents/>
<LocationOfComponents HRef="file:///D:\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:
office:excel">
<WindowHeight>8835</WindowHeight>
<WindowWidth>11340</WindowWidth>
<WindowTopX>480</WindowTopX>
<WindowTopY>120</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s22">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Font x:Family="Swiss" ss:Size="16" ss:Bold="1"/>
</Style>
<Style ss:ID="s23">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Font x:Family="Swiss" ss:Bold="1"/>
</Style>
<Style ss:ID="s24">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Font x:Family="Swiss"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="4" ss:ExpandedRowCount=
"100" x:FullColumns="1" x:FullRows="1">
<Column ss:AutoFitWidth="0" ss:Width="111.75"/>
<Column ss:AutoFitWidth="0" ss:Width="120"/>
<Column ss:AutoFitWidth="0" ss:Width="121.5"/>
<Column ss:AutoFitWidth="0" ss:Width="135"/>
<xsl:apply-templates/>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:
office:excel">
<Print>
<ValidPrinterInfo/>
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>600</VerticalResolution>
</Print>
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>4</ActiveRow>
<ActiveCol>2</ActiveCol>
</Pane> </Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="Sheet2">
<WorksheetOptions xmlns="urn:schemas-microsoft-com:
office:excel">
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="Sheet3">
<WorksheetOptions xmlns="urn:schemas-microsoft-com:
office:excel">
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
</xsl:template>
<xsl:template match="Report">
<Row ss:Index="3" ss:AutoFitHeight="0" ss:Height="20.25">
<Cell ss:Index="2" ss:MergeAcross="1" ss:StyleID="s22">
<Data ss:Type="String"><xsl:value-of select=
"@ReportTitle"/></Data>
</Cell>
</Row>
<Row ss:Index="5">
<Cell ss:StyleID="s23">
<Data ss:Type="String">Title</Data>
</Cell>
<Cell ss:StyleID="s23">
<Data ss:Type="String">Author</Data>
</Cell>
<Cell ss:StyleID="s23">
<Data ss:Type="String">Received Date</Data>
</Cell>
<Cell ss:StyleID="s23">
<Data ss:Type="String">Copies</Data>
</Cell>
</Row>
<xsl:for-each select="Record">
<Row>
<Cell ss:StyleID="s24">
<Data ss:Type="String"><xsl:value-of select=
"Title"/></Data>
</Cell>
<Cell ss:StyleID="s24">
<Data ss:Type="String"><xsl:value-of select=
"Author"/></Data>
</Cell>
<Cell ss:StyleID="s24">
<Data ss:Type="String"><xsl:value-of select=
"ReceivedDate"/></Data>
</Cell>
<Cell ss:StyleID="s24">
<Data ss:Type="Number"><xsl:value-of select=
"Copies"/></Data>
</Cell>
</Row>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>