Extensible Stylesheet Language (XSL) Basics
XSL is an XML language that is used to "transform" an XML document into a different
form. Generally, XSL is used to create a "template" that a Web browser uses to
transform an XML document into an HTML webpage. In this article, you'll learn how
easy it is to do powerful things with XSL.
First of all, you'll need some basic knowledge of XML, nothing advanced, but you
should know how to create a "well-formed" XML document. You can learn basic XML
from articles on this website and other sources. You need a basic knowledge of XML
because XSL works on XML and XSL itself is XML.
An XSL document, referred to as an "XSL style sheet", allows you to select, filter,
and sort the elements of an XML document for display as HTML in a Web browser. You
can even include scripts in an XSL style sheet that let you modify or add information
to the XML document. We'll stick with selecting, filtering, and sorting in this article.
Shown below is a very simple XML document. This document represents a book list that
contains only one "book" element. The book element has child nodes that contain the
"title, publisher, author, isbn, pubdate, and price of the book.
<title>XML in a Nutshell</title>
If you would like to follow along, create a new file in a simple ASCII text editor,
like Windows Notepad, paste the above XML into the text file, and save it with the
file name "booklist.xml".
Shown below is a very simple XSL document to display the data in the booklist XML document.
<xsl:value-of select="book/title" /></td></tr>
<xsl:value-of select="book/publisher" /></td></tr>
<xsl:value-of select="book/author" /></td></tr>
<xsl:value-of select="book/isbn" /></td></tr>
<tr><td>Pub Date: </td><td>
<xsl:value-of select="book/pubdate" /></td></tr>
<xsl:value-of select="book/price" /></td></tr>
If you would like to follow along, paste the above XSL into the text file and save
it with the file name "example1.xsl".