"Hello world!" Example of XSLT

This section provides a tutorial example on how to a first XSLT stylesheet, hello.xls, to transform the original XML document, hello.xml. The Internet Explorer (IE) can be used as XSLT transformation program to apply the stylesheet and generate the resulting document.

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

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
 <xsl:template match="p">Hello world! - From hello.xsl.</xsl:template>

Note that:

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. There are many commercial tools that supports XML XSL processing functionalities. But you also use some open source tools like Notepad++ and Atom as XML/XSL editors and processors.

Or you can write a simple program to as an XML XSL processor. XSLTransformer.java presented later in the book is a good example. If you run it on hello_xsl.xml, you will get the following output:

Hello world! - From hello.xsl.

Note that:

If you work with XML Stylesheet frequently, you need to have some good tools as XML XSL processors with command line interface or graphical user interface.

Here is a list of XML XSL processors I have used.

Table of Contents

 About This Book

 Introduction of XML (eXtensible Markup Language)

 XML File Syntax

 XML File Browsers

 XML-JSON Document Conversion

 DOM (Document Object Model) Programming Interface

 SAX (Simple API for XML) Programming Interface

 DTD (Document Type Definition) Introduction

 Syntaxes of DTD Statements

 Validating an XML Document against the Specified DTD Document Type

 XSD (XML Schema Definition) Introduction

 Syntaxes of XSD Statements

 Validating XML Documents Against Specified XML Schemas

XSL (Extensible Stylesheet Language) Introduction

 What Is XSL (Extensible Stylesheet Language)

"Hello world!" Example of XSLT

 Web Browser Errors on Local XSL File

 Java Implementation of XSLT

 XSLT (XSL Transformations) Introduction

 XPath (XML Path) Language

 XSLT Elements as Programming Statements

 Control and Generate XML Element in the Result

 PHP Extensions for XML Manipulation

 Processing XML with Python Scripts

 XML Notepad - XML Editor

 XML Tools Plugin for Notepad++

 XML Plugin Packages for Atom Editor

 XML 1.1 Changes and Parsing Examples

 Archived Tutorials


 Full Version in PDF/EPUB