Publishing Books Using XML Technologies
Dr. Herong Yang, Version 4.01

What Is XSL (eXtensible Style Language)?

This section provides some basics about Extensible Stylesheet Language (XSL).

What is XSL?

XSL (eXtensible Style Language): A language that defines style instructions to transform the information contained in XML files into new formats.

Main features of XSL:

  • XSL is XML based.
  • The transforming component is called XSL Transformation (XSLT).
  • The formatting component is called XSL Formatting Objects (XSL-FO).
  • XSL supports all functionalities supported by CSS, and more.
  • XSL is easy to get started.
  • XSL files are hard to understand, like Perl. The processing rules heavily depend on a hidden, and dynamically changing, context.

'Hello world!' Example of XSLT

Here is the XSL file, hello.xsl, that defines how information in my hello.xml should be transformed:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="p">Hello world! 
    - From hello.xsl.</xsl:template>
</xsl:stylesheet>

Note that:

  • The root element is named as "xsl:stylesheet".
  • All the element names are prefixed with "xls:".
  • Prefix "xls:" is associated with the XML name space: "http://www.w3.org/1999/XSL/Transform". This is done by the attribute, "xmlns:xsl" in the root element.

In order to link hello.xsl to hello.xml, I have to modify it as hello_xsl.xml:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="hello.xsl"?>
<p>Hello world!</p>

Note that a new processing instruction "xml-stylesheet" is added to the XML file to tell the processing applications to look for style instructions in "hello.xsl".

The next question is then: "Do we have an application that can process this XML file based on the style instructions specified in the XSL file?"

The answer is yes. Microsoft Internet Explorer (IE) 6.0 is an excellent XML XSL processor. So if you run IE 6.0 and open hello_xsl.xml, you will see the following text in the IE window:

Hello world! - From hello.xsl.

Note that:

  • The element "p" in hello.xml was transformed into a new text string by IE.
  • IE first transformed the content in hello_xsl.xml, kept the result in memory, then displayed the result on the screen.

Table of Contents

 About This Book

 Ideas on Publishing Books using XML

 Overview of hyPub - A Simple XML Publishing Tool

 Writing Book Contents in XHTML Source Files

Transforming Book Source Files with XSL Technology

What Is XSL (eXtensible Style Language)?

 Introduction to XSL Templates?

 xalan - XSL Transformation Processing Engine

 How XSL Technology Is Used in hyPub?

 Designing Web Page Layouts with Tables

 Controlling Web Page Appearance with CSS

 Sharing HTML Codes with JavaScript Files

 Generating Web Pages with hyPub

 Formatting Printable Documents with XSL-FO

 Generating PDF Documents with hyPub

 Areas of Future Improvements

 References

 PDF Printing Version

Dr. Herong Yang, updated in 2007
What Is XSL (eXtensible Style Language)?