The Element

The <stylesheet> Element</stylesheet>

The <xsl:stylesheet> Element

The <xsl:stylesheet> element (or <xsl:transform>, which is a synonym) is the outermost element of every stylesheet module.

The name <xsl:stylesheet> is a conventional name. The first part, xsl, is a prefix that identifies the namespace to which the element name belongs. Any prefix can be used so long as it is mapped, using a namespace declaration, to the URI http://www.w3.org/1999/XSL/Transform . There is also a mandatory version attribute. So the start tag of the <xsl:stylesheet> element will usually look like this.

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

The <xsl:stylesheet> element can also be written as <xsl:transform> if you prefer to think of XSLT as doing transformations rather than styling. The two names are completely interchangeable, but I usually use <xsl:stylesheet> for familiarity . Everything I say about the <xsl:stylesheet> element applies equally to <xsl:transform>

As a general principle, it's advisable to specify «version=" 2.0" » if the stylesheet module uses any facilities from XSLT 2.0 or XPath 2.0, and «version="1.0" » if it relies only on XSLT 1.0 and XPath 1.0 features. This isn't purely documentary ; as we'll see later (see page 123), XSLT processors have some subtle differences in behavior, depending on the setting of this attribute.

If you encounter a stylesheet that uses the namespace URI http://www.w3.org/TR/WD-xsl , then the stylesheet is written in a Microsoft dialect , based on an early working draft of the XSLT standard. This version was released with Internet Explorer 5, and although it has been obsolete for some years , you still come across it occasionally. There are many differences between the IE5 dialect (which I refer to as WD-xsl, but which Microsoft documentation often refers to simply as "XSL") and XSLT 1.0, and even more differences between WD-xsl and XSLT 2.0.

The other attributes that may appear on this element are described under <xsl:stylesheet> in Chapter 5, page 433. Specifically, they are as follows :

  • id, to identify the stylesheet if it appears as an embedded stylesheet within another document. Embedded stylesheets are described in the next section.

  • extension-element-prefixes, a list of namespace prefixes that denote elements used for vendor-defined or user -defined extensions to the XSLT language.

  • exclude-result-prefixes, a list of namespaces used in the stylesheet that should not be copied to the result tree unless they are actually needed. I'll explain how this works in the section Literal Result Elements on page 106.

  • xpath-default-namespace , a namespace URI, which is used as the default namespace for unprefixed element names used in path expressions within the stylesheet, and also for unprefixed type names. This attribute is handy when all the elements in your source document are in a particular namespace, because it saves you having to use a namespace prefix every time you refer to an element in this namespace. Without this attribute, element names with no prefix are assumed to refer to names in the null namespace ( neither the default namespace declared using «xmlns="uri" » in the stylesheet, nor the default namespace declared in the source document, has any effect on names used in path expressions).

  • default-validation , which takes one of the values «strict », «lax », «preserve », or «strip ». This attribute is used by a schema-aware processor to define the schema-based validation that is applied to elements created in a result tree. The value can be overridden on the instruction that creates a particular element. If the attribute is omitted, the value «strip » is assumed: this causes no schema-based validation to occur, and it also ensures that type annotations are not copied from the source tree to the result tree. You will find more details of how result trees are validated against a schema in Chapter 4.

These attributes affect only the stylesheet module in which this <xsl:stylesheet> element appears; they do not affect what happens in included or imported stylesheet modules.

The <xsl:stylesheet> 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. 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 <xsl:stylesheet> element. For example, if you want to declare «saxon » as an extension element prefix, the start tag of the <xsl:stylesheet> element might look like this.

  <xsl:stylesheet   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   xmlns:xs="http://www.w3.org/2001/XMLSchema"   xmlns:saxon="http://saxon.sf.net/"   version="1.0"   extension-element-prefixes="saxon"   >  

Namespace declarations on the <xsl:stylesheet> 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.




XSLT 2.0 Programmer's Reference
NetBeansв„ў IDE Field Guide: Developing Desktop, Web, Enterprise, and Mobile Applications (2nd Edition)
ISBN: 764569090
EAN: 2147483647
Year: 2003
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net