xsl:stylesheet and xsl:transform
An XSLT stylesheet is an XML document. It can and generally
should have an XML declaration. It can have a document type
declaration, although most stylesheets do not. The root element of this document is either stylesheet
or
transform
; these are synonyms for each other, and you can use
either. They both have the same possible children and attributes. They
both mean the same thing to an XSLT processor.
The stylesheet
and transform
elements, like all other XSLT
elements, are in the http://www.w3.org/1999/XSL/Transform
namespace. This namespace is customarily mapped to the
xsl
prefix so that you write xsl:transform
or xsl:stylesheet
rather than simply transform
or stylesheet
.
Warning
This namespace URI must be exactly correct. If even so much as a single character is wrong, the stylesheet processor will output the stylesheet itself instead of either the input document or the transformed input document. There’s a reason for this (see Section 2.3 of the XSLT 1.0 specification, Literal Result Element as Stylesheet, if you really want to know), but the bottom line is that this weird behavior looks very much like a bug in the XSLT processor if you’re not expecting it. If you ever do see your stylesheet processor spitting your stylesheet back out at you, the problem is almost certainly an incorrect namespace URI.
In addition to the xmlns:xsl
attribute declaring this prefix mapping, the root
element must have a version
attribute with the value 1.0
. Thus, ...
Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.