Bookmark and Share

XSLT - Syntax

This lesson will teach you the basics of syntax and the necessary parts that must be in every XSLT file. Most of this information is just code that you can copy and paste to get started in XSLT.

Advertise on Tizag.com

If you would like to follow along, we recommend that you create a blank text file and save it as class.xsl. We will be adding to this file throughout the tutorial.

XSLT - XML Declaration

This is more of a technicality, but you should include an XML declaration at the top of your XSLT documents. The attribute version defines what version of XML you are using.

XSLT Code (Work in Progress!):

<?xml version="1.0" ?>

XSLT - Stylesheet Root Element

Every XSLT file must have the root element xsl:stylesheet. This root element has two attributes that must be included:

  • version - the version of XSLT
  • xmlns:xsl - the XSLT namespace, which is a URI to w3.org

As you probably guessed, an XSLT file is a well-formed XML document.

XSLT Code (Work in Progress!):

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:stylesheet>

If you want to follow along on your own computer, copy and paste that text and save the file as class.xsl.

You do not need to know the intricacies of the xsl:stylesheet to use XSLT. What you do need to remember is to include both the XML declaration and the root element in your XSLT code!

XSLT - XSL: Namespace Prefix

As you probably noticed, the root element specifies the XSL namespace. This basically means you have to put a xsl: prefix before every XSL element. Although this may seem annoying, it is absolutely required, so you better get used to it! The standard form of an XSL element is:

  • xsl:element

XSLT - Syntax Overview

In this lesson, you learned about the required pieces for valid XSLT code. You also learned that every XSLT element has an xsl: prefix to specify its namespace.

The rest of XSLT is just learning the special elements and attributes that XSLT uses. The next few lessons will talk about the most important XSLT elements and their related attributes.

Bookmark and Share




Download Tizag.com's XML Book

If you would rather download the PDF of this tutorial, check out our XML eBook from the Tizag.com store.

Found Something Wrong in this Lesson?

Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!

Advertise Here

More Tutorials!
Microsoft Office Tutorials Artist Tutorials