XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (41 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
13.16Mb size Format: txt, pdf, ePub
ads

With the exception of
input-type-annotations
, these attributes affect only the stylesheet module in which this

element appears; they do not affect what happens in included or imported stylesheet modules.

The

element will often contain further namespace declarations. Many stylesheets are likely to reference the names of types defined in XML Schema, in which case the XML Schema namespace needs to be declared. If the result tree uses a namespace (perhaps XSL-FO or SVG), then that namespace too will often be declared. Also, if the
extension-element-prefixes
or
exclude-result-prefixes
attributes are used, then any namespace prefixes they mention must be declared by means of a namespace declaration on the

element. So, if you want to declare
saxon
as an extension element prefix, the start tag of the

element might look like this.

   xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”

   xmlns:xs=“http://www.w3.org/2001/XMLSchema”

   xmlns:fo=“http://www.w3.org/1999/XSL/Format”

   xmlns:saxon=“http://saxon.sf.net/”

   version=“2.0”

   extension-element-prefixes=“saxon”

   exclude-result-prefixes=“xs”

>

Namespace declarations on the

element, and indeed anywhere else in the stylesheet, apply only to the stylesheet module in which they appear. They are not inherited by included or imported modules.

The Processing Instruction

This processing instruction is not a part of the XSLT or XPath standard; rather it has a short W3 C Recommendation all to itself, which you can find at
http://www.w3.org/TR/xml-stylesheet
. XSLT mentions it, but only in an example, so there is no implication that an XSLT processor is required to support it. However, many processors do, at least in its most basic form.

The

processing instruction is used within a source XML document to identify the stylesheet that should be used to process it. There can be several

processing instructions present, defining different stylesheets to be used under different circumstances.

This way of controlling a transformation is particularly useful if you want to run the transformation on the client side (that is, in the browser). This is supported by most browsers, including Internet Explorer, Firefox, Safari, and Opera. It means you can simply send an XML file to the browser, with a processing instruction to identify the stylesheet to be used, and the browser will automatically invoke a transformation and then display the resulting HTML. No special script is needed to control the process, which means the solution is very portable. Unfortunately, at the time of writing, none of the major browsers includes support for client-side transformation using XSLT 2.0.

On the server side, which is where you are more likely to be using XSLT 2.0, it's less likely that you will want to control the transformation using this processing instruction. It's much more likely that you will want either to drive the process from the operating system command line or to use an API such as the Microsoft or Java APIs (described in Appendices D and E, respectively). These APIs give you much more control: they allow you to apply different stylesheets to the same documents on different occasions, to set parameters, and to compile a stylesheet once and then use it repeatedly.

So it's quite likely you can skip this section for now; but for completeness, I think it's still important to describe this mechanism.

The

processing instruction has an
href
attribute whose value is the URI of the stylesheet (that is, the principal stylesheet module), and a
type
attribute that indicates the language in which the stylesheet is written. This doesn't have to be an XSLT stylesheet; it could be a Cascading Style Sheet (CSS).

There's considerable confusion about what the correct value of the
type
attribute should be in the case of XSLT. Until recently there was no registered media type (often called MIME type) for XSLT stylesheets, so Microsoft invented one:
text/xsl
. This has never been made official, and the XSLT 2.0 Recommendation instead registers the name
application/xslt+xml
. However, the use of
text/xsl
is now so widespread that it is unlikely to go away.

Technically, XML processing instructions do not contain attributes; they contain a name (here
xml-stylesheet
) followed by character data. But in this case the character data is structured as a sequence of
name = “value”
pairs, like the attributes in an element start tag, and the xml-stylesheet recommendation refers to these pairs as pseudo-attributes.

Following is the full list of pseudo-attributes in the

processing instruction.

Attribute Name
Value
Meaning
href
(mandatory)
URI
The URI of the stylesheet. This may be an absolute or relative link to the XML document that contains the stylesheet, or it may contain a fragment identifier (for example
#styleB
) used to locate the stylesheet within a larger file. See the section
Embedded Stylesheets
on page 102.
type
(mandatory)
MIME type
Identifies the language in which the stylesheet is written; typically
application/xslt+xml
or
text/xsl
(see the discussion earlier).
title
(optional)
String
If there are several

processing instructions, each should be given a title to distinguish them. The user can then be allowed to choose which stylesheet is wanted. For example, there may be special stylesheets that produce large print or aural rendition.
media
(optional)
String
Description of the output medium, for example
print
,
projection
, or
aural
. The list of possible values is defined in the HTML 4.0 specification. This value can be used to select from the available stylesheets.
charset
(optional)
Character encoding
This attribute is not useful with XSLT stylesheets, since as XML documents they define their character encoding themselves.
alternate
(optional)

yes
” or “
no

If
no
is specified, this is the preferred stylesheet. If
yes
is specified, it is an alternative stylesheet to be selected at user option.
BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
13.16Mb size Format: txt, pdf, ePub
ads

Other books

Night Fall on Dark Mountain by Delilah Devlin
Shining Hero by Sara Banerji
Married By Christmas by Bailey, Scarlett
Jade by Olivia Rigal
The Blue Diamond by Joan Smith
Gabriel's Horn by Alex Archer
PW02 - Bidding on Death by Joyce Harmon