Datasheet
Williams c01.tex V3 - 07/31/2009 2:53pm Page 3
Chapter 1: First Steps with XSLT
<?xml version
=
"1.0" encoding
=
"UTF-8"?>
<?xml-stylesheet href
=
"browser.xsl" type
=
"text/xsl"?>
<reference>
...
</reference>
You may have used processing instructions in other XML applications; what appear to be attributes in
the instruction are in fact known as pseudo-attributes.The
href
pseudo-attribute locates the stylesheet
(
browser.xsl
). The file extension
.xsl
is a convention, which some applications may rely on for iden-
tification. The
type
pseudo-attribute defines the content type (text/xsl). In this case you use a relative
URI, for a stylesheet in the same directory as the source document. (In this book I use the more general
term URI, which is an identifier that may not imply a specific location, whereas the term URL implies a
location from which you can obtain a representation of a resource such as an HTML page.
The W3C recommendation for this processing instruction is separate from the XSLT specifications, and is
at
www.w3.org/TR/xml-stylesheet/
.
The semantics of pseudo-attributes is the same as that of the attributes used in
<link
rel
=
"stylesheet">
in HTML.
The content type expressed need not be XSLT, and this processing instruction is often used to specify
multiple CSS files to handle different types of media using the value
‘text/css’.
The content type
for XSLT 1.0 was never specified in the W3C recommendation. Microsoft invented the
‘text/xsl’
value for Internet Explorer, which seems to have stuck in practice, though browsers may also accept
other values, such as
‘text/xml’.
The XSLT 2.0 recommendation formally registers the media type
‘application/xslt
+
xml’.
Built-in Rules
We can now process the sample by writing a bare-bones transform. It is not very exciting, but it illustrates
the default behavior of a processor using a built-in template rule, specified in the XSLT specification.
XSLT defines built-in rules for processing templates, and the rule for document and element nodes
ensures that the root element and all of its children will be handled recursively, even if there are no
element-specific templates.
This book generally specifies XSLT version 2.0 for stylesheets. However, in the following Try It Out you’ll
create an XSLT 1.0 transform using a single root
<xsl:stylesheet>
element to demonstrate this built-in
behavior.
Try It Out A Root Element Stylesheet
To create the transform, follow these steps:
1. In the Oxygen IDE, mentioned in this book’s Introduction, create a new document by choosing
New Stylesheet (XSL) File.
2. In the dialog that appears, select 1.0 as the Stylesheet version.
3