Although XML and XSL are very complex technologies, with the simple examples in this article you learn that you don't need extensive knowledge to do some powerful things. You can store your data in an XML document and use a basic XSL style sheet to select, filter, and sort the elements of an XML document for display as HTML in a Web browser.
Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

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.

<?xml version="1.0"?>

<book>
  <title>XML in a Nutshell</title>
  <publisher>O'Reilly</publisher>
    <author>
      <firstname>Scott</firstname>
      <lastname>Means</lastname>
    </author>
  <isbn>0596007647</isbn>
  <pubdate>2004</pubdate>
  <price>26.37</price>
</book>

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.

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  <xsl:template match="/">
    <p>Book List</p>
    <table>
    <tr><td>Title: </td><td>
    <xsl:value-of select="book/title" /></td></tr>
    <tr><td>Publisher: </td><td>
    <xsl:value-of select="book/publisher" /></td></tr>
    <tr><td>Author: </td><td>
    <xsl:value-of select="book/author" /></td></tr>
    <tr><td>ISBN: </td><td>
    <xsl:value-of select="book/isbn" /></td></tr>
    <tr><td>Pub Date: </td><td>
    <xsl:value-of select="book/pubdate" /></td></tr>
    <tr><td>Price: </td><td>
    <xsl:value-of select="book/price" /></td></tr>
    </table>
  </xsl:template>
</xsl:stylesheet>

If you would like to follow along, paste the above XSL into the text file and save it with the file name "example1.xsl".

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro


Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2024 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268