Free since 2005 · No login required
AT

Academic Tutorials

Learn at your own pace

site-mobile-top-banner · 320x50

What Does XSL Look Like

Added 26 Jul 2008


 A simple XSL style sheet that generates HTML from XML.

 xmlns:xsl="http://www.w4.org/TR/WD-xsl">




A Document
















Don't worry if this looks a little confusing at first. There's a lot going on. We'll revisit this style sheet in the "Understanding XSL" section.

One thing that stands out in an XSL style sheet is the use of namespaces. (covered in two articles in this issue of XML.com), namespaces are what all the colon-delimited prefixes are about.

In XSL, there can be no reserved element names, so it's necessary to use some other mechanism to distinguish between elements that have XSL semantics and other elements. This is the problem that namespaces were designed to solve.

If you're not familiar with namespaces, here are some simple guidelines:

The prefix is significant when comparing element names; therefore xsl:template and template are different.

The prefix string is arbitrary. What's important is the association of a prefix string with a URI. That's the function of the "xmlns:" attribute on the stylesheet.

The attribute

xmlns:xsl="http:// www.w3.org/TR/WD-xsl"
associates the namespace prefix "xsl" with the URI that follows it:
("http://www.w3.org/TR/ WD-xsl").
If it were instead
xmlns:xyzzy="http://www.w3.org/ TR/WD-xsl"
then the prefix xyzzy: would replace every instance of xsl: in the example, and the style sheet would be exactly the same