The following example XML file associates a style sheet, samplexStylesheet.xsl:

<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="C:\samplexStylesheet.xsl "?>
<source>
    <title>XSL tutorial</title>
    <author>John Smith</author>
</source>

The following example XSLT code transforms XML to HTML. The style sheet uses XPath expressions to add the title and author from the XML file to the generated HTML output. The style sheet also contains required HTML formatting, such as table and border formats, to add to the generated HTML output.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:output method="html"/>
    <xsl:template match="/">
        <head>
            <title>Generated HTML Output</title>
        </head>
        <body>
            <table border="1"> 
                <tr> 
                    <td>Title</td> 
                    <td>Author</td> 
                </tr> 
                <tr> 
                    <td><xsl:value-of select="//title"/></td> 
                    <td><xsl:value-of select="//author"/></td> 
                </tr> 
               </table> 
            </body> 
        </xsl:template> 
<xsl:stylesheet>

The previous example XSLT code generates the following HTML:

<head> 
    <title>Generated HTML Output</title> 
</head> 
<body> 
    <table border="1"> 
        <tr> 
            <td><b>Title</b></td> 
            <td><b>Author</b></td> 
        </tr> 
        <tr> 
            <td>XSL Tutorial</td> 
            <td>John Smith</td> 
        </tr> 
    </table> 
</body>

The previous HTML code appears as follows when viewed in a browser: