1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
\r
4 <title>XSL Transformations (XSLT)</title>
\r
5 <link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-REC">
\r
6 <style type="text/css">p.element-syntax { border: solid thin }code { font-family: monospace }</style>
\r
10 <a href="http://www.w3.org/"><img src="http://www.w3.org/Icons/WWW/w3c_home" alt="W3C" height="48" width="72"></a>
\r
11 <h1>XSL Transformations (XSLT)<br>Version 1.0</h1>
\r
12 <h2>W3C Recommendation 16 November 1999</h2>
\r
14 <dt>This version:</dt>
\r
16 <a href="http://www.w3.org/TR/1999/REC-xslt-19991116">http://www.w3.org/TR/1999/REC-xslt-19991116</a>
\r
18 (available in <a href="http://www.w3.org/TR/1999/REC-xslt-19991116.xml">XML</a> or
\r
19 <a href="http://www.w3.org/TR/1999/REC-xslt-19991116.html">HTML</a>)
\r
22 <dt>Latest version:</dt>
\r
24 <a href="http://www.w3.org/TR/xslt">http://www.w3.org/TR/xslt</a>
\r
27 <dt>Previous versions:</dt>
\r
29 <a href="http://www.w3.org/TR/1999/PR-xslt-19991008">http://www.w3.org/TR/1999/PR-xslt-19991008</a>
\r
31 <a href="http://www.w3.org/1999/08/WD-xslt-19990813">http://www.w3.org/1999/08/WD-xslt-19990813</a>
\r
33 <a href="http://www.w3.org/1999/07/WD-xslt-19990709">http://www.w3.org/1999/07/WD-xslt-19990709</a>
\r
35 <a href="http://www.w3.org/TR/1999/WD-xslt-19990421">http://www.w3.org/TR/1999/WD-xslt-19990421</a>
\r
37 <a href="http://www.w3.org/TR/1998/WD-xsl-19981216">http://www.w3.org/TR/1998/WD-xsl-19981216</a>
\r
39 <a href="http://www.w3.org/TR/1998/WD-xsl-19980818">http://www.w3.org/TR/1998/WD-xsl-19980818</a>
\r
46 <a href="mailto:jjc@jclark.com"><jjc@jclark.com></a>
\r
50 <p class="copyright">
\r
51 <a href="http://www.w3.org/Consortium/Legal/ipr-notice.html#Copyright">
\r
52 Copyright</a> © 1999 <a href="http://www.w3.org">W3C</a><sup>®</sup>
\r
53 (<a href="http://www.lcs.mit.edu">MIT</a>,
\r
54 <a href="http://www.inria.fr/">INRIA</a>,
\r
55 <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C
\r
56 <a href="http://www.w3.org/Consortium/Legal/ipr-notice.html#Legal_Disclaimer">liability</a>,
\r
57 <a href="http://www.w3.org/Consortium/Legal/ipr-notice.html#W3C_Trademarks">trademark</a>,
\r
58 <a href="http://www.w3.org/Consortium/Legal/copyright-documents.html">document use</a> and
\r
59 <a href="http://www.w3.org/Consortium/Legal/copyright-software.html">software licensing</a> rules apply.
\r
61 <hr title="Separator for header">
\r
64 <a name="abstract">Abstract</a>
\r
67 <p>This specification defines the syntax and semantics of XSLT, which
\r
68 is a language for transforming XML documents into other XML
\r
71 <p>XSLT is designed for use as part of XSL, which is a stylesheet
\r
72 language for XML. In addition to XSLT, XSL includes an XML vocabulary
\r
73 for specifying formatting. XSL specifies the styling of an XML
\r
74 document by using XSLT to describe how the document is transformed
\r
75 into another XML document that uses the formatting vocabulary.</p>
\r
77 <p>XSLT is also designed to be used independently of XSL. However,
\r
78 XSLT is not intended as a completely general-purpose XML
\r
79 transformation language. Rather it is designed primarily for the
\r
80 kinds of transformations that are needed when XSLT is used as part of
\r
84 <a name="status">Status of this document</a>
\r
87 <p>This document has been reviewed by W3C Members and other interested
\r
88 parties and has been endorsed by the Director as a W3C <a href="http://www.w3.org/Consortium/Process/#RecsW3C">Recommendation</a>. It
\r
89 is a stable document and may be used as reference material or cited as
\r
90 a normative reference from other documents. W3C's role in making the
\r
91 Recommendation is to draw attention to the specification and to
\r
92 promote its widespread deployment. This enhances the functionality and
\r
93 interoperability of the Web.</p>
\r
95 <p>The list of known errors in this specification is available at
\r
96 <a href="http://www.w3.org/1999/11/REC-xslt-19991116-errata">http://www.w3.org/1999/11/REC-xslt-19991116-errata</a>.</p>
\r
98 <p>Comments on this specification may be sent to <a href="mailto:xsl-editors@w3.org">xsl-editors@w3.org</a>; <a href="http://lists.w3.org/Archives/Public/xsl-editors">archives</a>
\r
99 of the comments are available. Public discussion of XSL, including
\r
100 XSL Transformations, takes place on the <a href="http://www.mulberrytech.com/xsl/xsl-list/index.html">XSL-List</a>
\r
103 <p>The English version of this specification is the only normative
\r
104 version. However, for translations of this document, see <a href="http://www.w3.org/Style/XSL/translations.html">http://www.w3.org/Style/XSL/translations.html</a>.</p>
\r
106 <p>A list of current W3C Recommendations and other technical documents
\r
107 can be found at <a href="http://www.w3.org/TR">http://www.w3.org/TR</a>.</p>
\r
109 <p>This specification has been produced as part of the <a href="http://www.w3.org/Style/Activity">W3C Style activity</a>.</p>
\r
113 <a name="contents">Table of contents</a>
\r
114 </h2>1 <a href="#section-Introduction">Introduction</a>
\r
115 <br>2 <a href="#section-Stylesheet-Structure">Stylesheet Structure</a>
\r
116 <br> 2.1 <a href="#xslt-namespace">XSLT Namespace</a>
\r
117 <br> 2.2 <a href="#stylesheet-element">Stylesheet Element</a>
\r
118 <br> 2.3 <a href="#result-element-stylesheet">Literal Result Element as Stylesheet</a>
\r
119 <br> 2.4 <a href="#qname">Qualified Names</a>
\r
120 <br> 2.5 <a href="#forwards">Forwards-Compatible Processing</a>
\r
121 <br> 2.6 <a href="#section-Combining-Stylesheets">Combining Stylesheets</a>
\r
122 <br> 2.6.1 <a href="#include">Stylesheet Inclusion</a>
\r
123 <br> 2.6.2 <a href="#import">Stylesheet Import</a>
\r
124 <br> 2.7 <a href="#section-Embedding-Stylesheets">Embedding Stylesheets</a>
\r
125 <br>3 <a href="#data-model">Data Model</a>
\r
126 <br> 3.1 <a href="#root-node-children">Root Node Children</a>
\r
127 <br> 3.2 <a href="#base-uri">Base URI</a>
\r
128 <br> 3.3 <a href="#unparsed-entities">Unparsed Entities</a>
\r
129 <br> 3.4 <a href="#strip">Whitespace Stripping</a>
\r
130 <br>4 <a href="#section-Expressions">Expressions</a>
\r
131 <br>5 <a href="#rules">Template Rules</a>
\r
132 <br> 5.1 <a href="#section-Processing-Model">Processing Model</a>
\r
133 <br> 5.2 <a href="#patterns">Patterns</a>
\r
134 <br> 5.3 <a href="#section-Defining-Template-Rules">Defining Template Rules</a>
\r
135 <br> 5.4 <a href="#section-Applying-Template-Rules">Applying Template Rules</a>
\r
136 <br> 5.5 <a href="#conflict">Conflict Resolution for Template Rules</a>
\r
137 <br> 5.6 <a href="#apply-imports">Overriding Template Rules</a>
\r
138 <br> 5.7 <a href="#modes">Modes</a>
\r
139 <br> 5.8 <a href="#built-in-rule">Built-in Template Rules</a>
\r
140 <br>6 <a href="#named-templates">Named Templates</a>
\r
141 <br>7 <a href="#section-Creating-the-Result-Tree">Creating the Result Tree</a>
\r
142 <br> 7.1 <a href="#section-Creating-Elements-and-Attributes">Creating Elements and Attributes</a>
\r
143 <br> 7.1.1 <a href="#literal-result-element">Literal Result Elements</a>
\r
144 <br> 7.1.2 <a href="#section-Creating-Elements-with-xsl:element">Creating Elements with xsl:element</a>
\r
145 <br> 7.1.3 <a href="#creating-attributes">Creating Attributes with xsl:attribute</a>
\r
146 <br> 7.1.4 <a href="#attribute-sets">Named Attribute Sets</a>
\r
147 <br> 7.2 <a href="#section-Creating-Text">Creating Text</a>
\r
148 <br> 7.3 <a href="#section-Creating-Processing-Instructions">Creating Processing Instructions</a>
\r
149 <br> 7.4 <a href="#section-Creating-Comments">Creating Comments</a>
\r
150 <br> 7.5 <a href="#copying">Copying</a>
\r
151 <br> 7.6 <a href="#section-Computing-Generated-Text">Computing Generated Text</a>
\r
152 <br> 7.6.1 <a href="#value-of">Generating Text with xsl:value-of</a>
\r
153 <br> 7.6.2 <a href="#attribute-value-templates">Attribute Value Templates</a>
\r
154 <br> 7.7 <a href="#number">Numbering</a>
\r
155 <br> 7.7.1 <a href="#convert">Number to String Conversion Attributes</a>
\r
156 <br>8 <a href="#for-each">Repetition</a>
\r
157 <br>9 <a href="#section-Conditional-Processing">Conditional Processing</a>
\r
158 <br> 9.1 <a href="#section-Conditional-Processing-with-xsl:if">Conditional Processing with xsl:if</a>
\r
159 <br> 9.2 <a href="#section-Conditional-Processing-with-xsl:choose">Conditional Processing with xsl:choose</a>
\r
160 <br>10 <a href="#sorting">Sorting</a>
\r
161 <br>11 <a href="#variables">Variables and Parameters</a>
\r
162 <br> 11.1 <a href="#section-Result-Tree-Fragments">Result Tree Fragments</a>
\r
163 <br> 11.2 <a href="#variable-values">Values of Variables and Parameters</a>
\r
164 <br> 11.3 <a href="#copy-of">Using Values of Variables and Parameters with
\r
166 <br> 11.4 <a href="#top-level-variables">Top-level Variables and Parameters</a>
\r
167 <br> 11.5 <a href="#local-variables">Variables and Parameters within Templates</a>
\r
168 <br> 11.6 <a href="#section-Passing-Parameters-to-Templates">Passing Parameters to Templates</a>
\r
169 <br>12 <a href="#add-func">Additional Functions</a>
\r
170 <br> 12.1 <a href="#document">Multiple Source Documents</a>
\r
171 <br> 12.2 <a href="#key">Keys</a>
\r
172 <br> 12.3 <a href="#format-number">Number Formatting</a>
\r
173 <br> 12.4 <a href="#misc-func">Miscellaneous Additional Functions</a>
\r
174 <br>13 <a href="#message">Messages</a>
\r
175 <br>14 <a href="#extension">Extensions</a>
\r
176 <br> 14.1 <a href="#extension-element">Extension Elements</a>
\r
177 <br> 14.2 <a href="#section-Extension-Functions">Extension Functions</a>
\r
178 <br>15 <a href="#fallback">Fallback</a>
\r
179 <br>16 <a href="#output">Output</a>
\r
180 <br> 16.1 <a href="#section-XML-Output-Method">XML Output Method</a>
\r
181 <br> 16.2 <a href="#section-HTML-Output-Method">HTML Output Method</a>
\r
182 <br> 16.3 <a href="#section-Text-Output-Method">Text Output Method</a>
\r
183 <br> 16.4 <a href="#disable-output-escaping">Disabling Output Escaping</a>
\r
184 <br>17 <a href="#conformance">Conformance</a>
\r
185 <br>18 <a href="#notation">Notation</a>
\r
187 <h3>Appendices</h3>A <a href="#section-References">References</a>
\r
188 <br> A.1 <a href="#section-Normative-References">Normative References</a>
\r
189 <br> A.2 <a href="#section-Other-References">Other References</a>
\r
190 <br>B <a href="#element-syntax-summary">Element Syntax Summary</a>
\r
191 <br>C <a href="#dtd">DTD Fragment for XSLT Stylesheets</a> (Non-Normative)<br>D <a href="#section-Examples">Examples</a> (Non-Normative)<br> D.1 <a href="#section-Document-Example">Document Example</a>
\r
192 <br> D.2 <a href="#data-example">Data Example</a>
\r
193 <br>E <a href="#section-Acknowledgements">Acknowledgements</a> (Non-Normative)<br>F <a href="#section-Changes-from-Proposed-Recommendation">Changes from Proposed Recommendation</a> (Non-Normative)<br>G <a href="#section-Features-under-Consideration-for-Future-Versions-of-XSLT">Features under Consideration for Future Versions of XSLT</a> (Non-Normative)<br>
\r
197 <a name="section-Introduction"></a>1 Introduction</h2>
\r
199 <p>This specification defines the syntax and semantics of the XSLT
\r
200 language. A transformation in the XSLT language is expressed as a
\r
201 well-formed XML document <a href="#XML">[XML]</a> conforming to the
\r
202 Namespaces in XML Recommendation <a href="#XMLNAMES">[XML Names]</a>, which may
\r
203 include both elements that are defined by XSLT and elements that are
\r
204 not defined by XSLT. <a name="dt-xslt-namespace"></a>XSLT-defined elements are distinguished by belonging to a
\r
205 specific XML namespace (see <a href="#xslt-namespace">[<b>2.1 XSLT Namespace</b>]</a>), which is
\r
206 referred to in this specification as the <b>XSLT
\r
207 namespace</b>. Thus this specification is a definition of
\r
208 the syntax and semantics of the XSLT namespace.</p>
\r
210 <p>A transformation expressed in XSLT describes rules for transforming
\r
211 a source tree into a result tree. The transformation is achieved by
\r
212 associating patterns with templates. A pattern is matched against
\r
213 elements in the source tree. A template is instantiated to create
\r
214 part of the result tree. The result tree is separate from the source
\r
215 tree. The structure of the result tree can be completely different
\r
216 from the structure of the source tree. In constructing the result
\r
217 tree, elements from the source tree can be filtered and reordered, and
\r
218 arbitrary structure can be added.</p>
\r
220 <p>A transformation expressed in XSLT is called a stylesheet. This is
\r
221 because, in the case when XSLT is transforming into the XSL formatting
\r
222 vocabulary, the transformation functions as a stylesheet.</p>
\r
224 <p>This document does not specify how an XSLT stylesheet is associated
\r
225 with an XML document. It is recommended that XSL processors support
\r
226 the mechanism described in <a href="#XMLSTYLE">[XML Stylesheet]</a>. When this or any
\r
227 other mechanism yields a sequence of more than one XSLT stylesheet to
\r
228 be applied simultaneously to a XML document, then the effect
\r
229 should be the same as applying a single stylesheet that imports each
\r
230 member of the sequence in order (see <a href="#import">[<b>2.6.2 Stylesheet Import</b>]</a>).</p>
\r
232 <p>A stylesheet contains a set of template rules. A template rule has
\r
233 two parts: a pattern which is matched against nodes in the source tree
\r
234 and a template which can be instantiated to form part of the result
\r
235 tree. This allows a stylesheet to be applicable to a wide class of
\r
236 documents that have similar source tree structures.</p>
\r
238 <p>A template is instantiated for a particular source element
\r
239 to create part of the result tree. A template can contain elements
\r
240 that specify literal result element structure. A template can also
\r
241 contain elements from the XSLT namespace
\r
242 that are instructions for creating result tree
\r
243 fragments. When a template is instantiated, each instruction is
\r
244 executed and replaced by the result tree fragment that it creates.
\r
245 Instructions can select and process descendant source elements. Processing a
\r
246 descendant element creates a result tree fragment by finding the
\r
247 applicable template rule and instantiating its template. Note
\r
248 that elements are only processed when they have been selected by the
\r
249 execution of an instruction. The result tree is constructed by
\r
250 finding the template rule for the root node and instantiating
\r
253 <p>In the process of finding the applicable template rule, more
\r
254 than one template rule may have a pattern that matches a given
\r
255 element. However, only one template rule will be applied. The
\r
256 method for deciding which template rule to apply is described
\r
257 in <a href="#conflict">[<b>5.5 Conflict Resolution for Template Rules</b>]</a>.</p>
\r
259 <p>A single template by itself has considerable power: it can create
\r
260 structures of arbitrary complexity; it can pull string values out of
\r
261 arbitrary locations in the source tree; it can generate structures
\r
262 that are repeated according to the occurrence of elements in the
\r
263 source tree. For simple transformations where the structure of the
\r
264 result tree is independent of the structure of the source tree, a
\r
265 stylesheet can often consist of only a single template, which
\r
266 functions as a template for the complete result tree. Transformations
\r
267 on XML documents that represent data are often of this kind (see
\r
268 <a href="#data-example">[<b>D.2 Data Example</b>]</a>). XSLT allows a simplified syntax for
\r
269 such stylesheets (see <a href="#result-element-stylesheet">[<b>2.3 Literal Result Element as Stylesheet</b>]</a>).</p>
\r
271 <p>When a template is instantiated, it is always instantiated with
\r
272 respect to a <a name="dt-current-node"></a><b>current node</b> and a <a name="dt-current-node-list"></a><b>current node
\r
273 list</b>. The current node is always a member of the
\r
274 current node list. Many operations in XSLT are relative to the
\r
275 current node. Only a few instructions change the current node list or
\r
276 the current node (see <a href="#rules">[<b>5 Template Rules</b>]</a> and <a href="#for-each">[<b>8 Repetition</b>]</a>); during the instantiation of one of these
\r
277 instructions, the current node list changes to a new list of nodes and
\r
278 each member of this new list becomes the current node in turn; after
\r
279 the instantiation of the instruction is complete, the current node and
\r
280 current node list revert to what they were before the instruction was
\r
283 <p>XSLT makes use of the expression language defined by <a href="#XPATH">[XPath]</a> for selecting elements for processing, for conditional
\r
284 processing and for generating text.</p>
\r
286 <p>XSLT provides two "hooks" for extending the language,
\r
287 one hook for extending the set of instruction elements used in
\r
288 templates and one hook for extending the set of functions used in
\r
289 XPath expressions. These hooks are both based on XML namespaces.
\r
290 This version of XSLT does not define a mechanism for implementing the
\r
291 hooks. See <a href="#extension">[<b>14 Extensions</b>]</a>.</p>
\r
294 <b>NOTE: </b>The XSL WG intends to define such a mechanism in a future
\r
295 version of this specification or in a separate
\r
296 specification.</blockquote>
\r
298 <p>The element syntax summary notation used to describe the syntax of
\r
299 XSLT-defined elements is described in <a href="#notation">[<b>18 Notation</b>]</a>.</p>
\r
301 <p>The MIME media types <code>text/xml</code> and
\r
302 <code>application/xml</code> <a href="#RFC2376">[RFC2376]</a> should be used
\r
303 for XSLT stylesheets. It is possible that a media type will be
\r
304 registered specifically for XSLT stylesheets; if and when it is, that
\r
305 media type may also be used.</p>
\r
311 <a name="section-Stylesheet-Structure"></a>2 Stylesheet Structure</h2>
\r
315 <a name="xslt-namespace"></a>2.1 XSLT Namespace</h3>
\r
317 <p>The XSLT namespace has the URI <code>http://www.w3.org/1999/XSL/Transform</code>.</p>
\r
320 <b>NOTE: </b>The <code>1999</code> in the URI indicates the year in which
\r
321 the URI was allocated by the W3C. It does not indicate the version of
\r
322 XSLT being used, which is specified by attributes (see <a href="#stylesheet-element">[<b>2.2 Stylesheet Element</b>]</a> and <a href="#result-element-stylesheet">[<b>2.3 Literal Result Element as Stylesheet</b>]</a>).</blockquote>
\r
324 <p>XSLT processors must use the XML namespaces mechanism <a href="#XMLNAMES">[XML Names]</a> to recognize elements and attributes from this
\r
325 namespace. Elements from the XSLT namespace are recognized only in the
\r
326 stylesheet not in the source document. The complete list of
\r
327 XSLT-defined elements is specified in <a href="#element-syntax-summary">[<b>B Element Syntax Summary</b>]</a>. Vendors must not extend the XSLT
\r
328 namespace with additional elements or attributes. Instead, any
\r
329 extension must be in a separate namespace. Any namespace that is used
\r
330 for additional instruction elements must be identified by means of the
\r
331 extension element mechanism specified in <a href="#extension-element">[<b>14.1 Extension Elements</b>]</a>.</p>
\r
333 <p>This specification uses a prefix of <code>xsl:</code> for referring
\r
334 to elements in the XSLT namespace. However, XSLT stylesheets are free
\r
335 to use any prefix, provided that there is a namespace declaration that
\r
336 binds the prefix to the URI of the XSLT namespace.</p>
\r
338 <p>An element from the XSLT namespace may have any attribute not from
\r
339 the XSLT namespace, provided that the <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> of the
\r
340 attribute has a non-null namespace URI. The presence of such
\r
341 attributes must not change the behavior of XSLT elements and functions
\r
342 defined in this document. Thus, an XSLT processor is always free to
\r
343 ignore such attributes, and must ignore such attributes without giving
\r
344 an error if it does not recognize the namespace URI. Such attributes
\r
345 can provide, for example, unique identifiers, optimization hints, or
\r
348 <p>It is an error for an element from the XSLT namespace to have
\r
349 attributes with expanded-names that have null namespace URIs
\r
350 (i.e. attributes with unprefixed names) other than attributes defined
\r
351 for the element in this document.</p>
\r
354 <b>NOTE: </b>The conventions used for the names of XSLT elements,
\r
355 attributes and functions are that names are all lower-case, use
\r
356 hyphens to separate words, and use abbreviations only if they already
\r
357 appear in the syntax of a related language such as XML or
\r
365 <a name="stylesheet-element"></a>2.2 Stylesheet Element</h3>
\r
367 <p class="element-syntax">
\r
368 <a name="element-stylesheet"></a><code><xsl:stylesheet<br> id = <var>id</var>
\r
369 <br> extension-element-prefixes = <var>tokens</var>
\r
370 <br> exclude-result-prefixes = <var>tokens</var>
\r
371 <br> <b>version</b> = <var>number</var>><br> <!-- Content: (<a href="#element-import">xsl:import</a>*, <var>top-level-elements</var>) --><br></xsl:stylesheet></code>
\r
374 <p class="element-syntax">
\r
375 <a name="element-transform"></a><code><xsl:transform<br> id = <var>id</var>
\r
376 <br> extension-element-prefixes = <var>tokens</var>
\r
377 <br> exclude-result-prefixes = <var>tokens</var>
\r
378 <br> <b>version</b> = <var>number</var>><br> <!-- Content: (<a href="#element-import">xsl:import</a>*, <var>top-level-elements</var>) --><br></xsl:transform></code>
\r
381 <p>A stylesheet is represented by an <code>xsl:stylesheet</code>
\r
382 element in an XML document. <code>xsl:transform</code> is allowed as
\r
383 a synonym for <code>xsl:stylesheet</code>.</p>
\r
385 <p>An <code>xsl:stylesheet</code> element must have a
\r
386 <code>version</code> attribute, indicating the version of XSLT that
\r
387 the stylesheet requires. For this version of XSLT, the value should
\r
388 be <code>1.0</code>. When the value is not equal to <code>1.0</code>,
\r
389 forwards-compatible processing mode is enabled (see <a href="#forwards">[<b>2.5 Forwards-Compatible Processing</b>]</a>).</p>
\r
391 <p>The <code>xsl:stylesheet</code> element may contain the following types
\r
396 <code>xsl:import</code>
\r
401 <code>xsl:include</code>
\r
406 <code>xsl:strip-space</code>
\r
411 <code>xsl:preserve-space</code>
\r
416 <code>xsl:output</code>
\r
421 <code>xsl:key</code>
\r
426 <code>xsl:decimal-format</code>
\r
431 <code>xsl:namespace-alias</code>
\r
436 <code>xsl:attribute-set</code>
\r
441 <code>xsl:variable</code>
\r
446 <code>xsl:param</code>
\r
451 <code>xsl:template</code>
\r
457 <a name="dt-top-level"></a>An element occurring as
\r
458 a child of an <code>xsl:stylesheet</code> element is called a
\r
459 <b>top-level</b> element.</p>
\r
461 <p>This example shows the structure of a stylesheet. Ellipses
\r
462 (<code>...</code>) indicate where attribute values or content have
\r
463 been omitted. Although this example shows one of each type of allowed
\r
464 element, stylesheets may contain zero or more of each of these
\r
467 <pre><xsl:stylesheet version="1.0"
\r
468 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
\r
469 <xsl:import href="..."/>
\r
471 <xsl:include href="..."/>
\r
473 <xsl:strip-space elements="..."/>
\r
475 <xsl:preserve-space elements="..."/>
\r
477 <xsl:output method="..."/>
\r
479 <xsl:key name="..." match="..." use="..."/>
\r
481 <xsl:decimal-format name="..."/>
\r
483 <xsl:namespace-alias stylesheet-prefix="..." result-prefix="..."/>
\r
485 <xsl:attribute-set name="...">
\r
487 </xsl:attribute-set>
\r
489 <xsl:variable name="...">...</xsl:variable>
\r
491 <xsl:param name="...">...</xsl:param>
\r
493 <xsl:template match="...">
\r
495 </xsl:template>
\r
497 <xsl:template name="...">
\r
499 </xsl:template>
\r
501 </xsl:stylesheet></pre>
\r
503 <p>The order in which the children of the <code>xsl:stylesheet</code>
\r
504 element occur is not significant except for <code>xsl:import</code>
\r
505 elements and for error recovery. Users are free to order the elements
\r
506 as they prefer, and stylesheet creation tools need not provide control
\r
507 over the order in which the elements occur.</p>
\r
509 <p>In addition, the <code>xsl:stylesheet</code> element may contain
\r
510 any element not from the XSLT namespace, provided that the
\r
511 expanded-name of the element has a non-null namespace URI. The presence of
\r
512 such top-level elements must not change the behavior of XSLT elements
\r
513 and functions defined in this document; for example, it would not be
\r
514 permitted for such a top-level element to specify that
\r
515 <code>xsl:apply-templates</code> was to use different rules to resolve
\r
516 conflicts. Thus, an XSLT processor is always free to ignore such
\r
517 top-level elements, and must ignore a top-level element without giving
\r
518 an error if it does not recognize the namespace URI. Such elements can
\r
519 provide, for example,</p>
\r
524 <p>information used by extension elements or extension functions
\r
525 (see <a href="#extension">[<b>14 Extensions</b>]</a>),</p>
\r
529 <p>information about what to do with the result tree,</p>
\r
533 <p>information about how to obtain the source tree,</p>
\r
537 <p>metadata about the stylesheet,</p>
\r
541 <p>structured documentation for the stylesheet.</p>
\r
550 <a name="result-element-stylesheet"></a>2.3 Literal Result Element as Stylesheet</h3>
\r
552 <p>A simplified syntax is allowed for stylesheets that consist of only
\r
553 a single template for the root node. The stylesheet may consist of
\r
554 just a literal result element (see <a href="#literal-result-element">[<b>7.1.1 Literal Result Elements</b>]</a>). Such a stylesheet is equivalent to a
\r
555 stylesheet with an <code>xsl:stylesheet</code> element containing a
\r
556 template rule containing the literal result element; the template rule
\r
557 has a match pattern of <code>/</code>. For example</p>
\r
559 <pre><html xsl:version="1.0"
\r
560 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
\r
561 xmlns="http://www.w3.org/TR/xhtml1/strict">
\r
563 <title>Expense Report Summary</title>
\r
566 <p>Total Amount: <xsl:value-of select="expense-report/total"/></p>
\r
568 </html></pre>
\r
570 <p>has the same meaning as</p>
\r
572 <pre><xsl:stylesheet version="1.0"
\r
573 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
\r
574 xmlns="http://www.w3.org/TR/xhtml1/strict">
\r
575 <xsl:template match="/">
\r
578 <title>Expense Report Summary</title>
\r
581 <p>Total Amount: <xsl:value-of select="expense-report/total"/></p>
\r
584 </xsl:template>
\r
585 </xsl:stylesheet></pre>
\r
587 <p>A literal result element that is the document element of a
\r
588 stylesheet must have an <code>xsl:version</code> attribute, which
\r
589 indicates the version of XSLT that the stylesheet requires. For this
\r
590 version of XSLT, the value should be <code>1.0</code>; the value must
\r
591 be a <a href="http://www.w3.org/TR/xpath#NT-Number">Number</a>. Other literal result
\r
592 elements may also have an <code>xsl:version</code> attribute. When the
\r
593 <code>xsl:version</code> attribute is not equal to <code>1.0</code>,
\r
594 forwards-compatible processing mode is enabled (see <a href="#forwards">[<b>2.5 Forwards-Compatible Processing</b>]</a>).</p>
\r
596 <p>The allowed content of a literal result element when used as a
\r
597 stylesheet is no different from when it occurs within a
\r
598 stylesheet. Thus, a literal result element used as a stylesheet cannot
\r
599 contain <a href="#dt-top-level">top-level</a> elements.</p>
\r
601 <p>In some situations, the only way that a system can recognize that an
\r
602 XML document needs to be processed by an XSLT processor as an XSLT
\r
603 stylesheet is by examining the XML document itself. Using the
\r
604 simplified syntax makes this harder.</p>
\r
607 <b>NOTE: </b>For example, another XML language (AXL) might also use an
\r
608 <code>axl:version</code> on the document element to indicate that an
\r
609 XML document was an AXL document that required processing by an AXL
\r
610 processor; if a document had both an <code>axl:version</code>
\r
611 attribute and an <code>xsl:version</code> attribute, it would be
\r
612 unclear whether the document should be processed by an XSLT processor
\r
613 or an AXL processor.</blockquote>
\r
615 <p>Therefore, the simplified syntax should not be used for XSLT
\r
616 stylesheets that may be used in such a situation. This situation can,
\r
617 for example, arise when an XSLT stylesheet is transmitted as a message
\r
618 with a MIME media type of <code>text/xml</code> or
\r
619 <code>application/xml</code> to a recipient that will use the MIME
\r
620 media type to determine how the message is processed.</p>
\r
626 <a name="qname"></a>2.4 Qualified Names</h3>
\r
628 <p>The name of an internal XSLT object, specifically a named template
\r
629 (see <a href="#named-templates">[<b>6 Named Templates</b>]</a>), a mode (see <a href="#modes">[<b>5.7 Modes</b>]</a>), an attribute set (see <a href="#attribute-sets">[<b>7.1.4 Named Attribute Sets</b>]</a>), a key (see <a href="#key">[<b>12.2 Keys</b>]</a>), a
\r
630 decimal-format (see <a href="#format-number">[<b>12.3 Number Formatting</b>]</a>), a variable or a
\r
631 parameter (see <a href="#variables">[<b>11 Variables and Parameters</b>]</a>) is specified as a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>. If it has a prefix, then the
\r
632 prefix is expanded into a URI reference using the namespace
\r
633 declarations in effect on the attribute in which the name occurs. The
\r
634 <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a>
\r
635 consisting of the local part of the name and the possibly null URI
\r
636 reference is used as the name of the object. The default namespace is
\r
637 <i>not</i> used for unprefixed names.</p>
\r
643 <a name="forwards"></a>2.5 Forwards-Compatible Processing</h3>
\r
645 <p>An element enables forwards-compatible mode for itself, its
\r
646 attributes, its descendants and their attributes if either it is an
\r
647 <code>xsl:stylesheet</code> element whose <code>version</code>
\r
648 attribute is not equal to <code>1.0</code>, or it is a literal result
\r
649 element that has an <code>xsl:version</code> attribute whose value is
\r
650 not equal to <code>1.0</code>, or it is a literal result element that
\r
651 does not have an <code>xsl:version</code> attribute and that is the
\r
652 document element of a stylesheet using the simplified syntax (see
\r
653 <a href="#result-element-stylesheet">[<b>2.3 Literal Result Element as Stylesheet</b>]</a>). A literal result element
\r
654 that has an <code>xsl:version</code> attribute whose value is equal to
\r
655 <code>1.0</code> disables forwards-compatible mode for itself, its
\r
656 attributes, its descendants and their attributes.</p>
\r
658 <p>If an element is processed in forwards-compatible mode, then:</p>
\r
663 <p>if it is a <a href="#dt-top-level">top-level</a>
\r
664 element and XSLT 1.0 does not allow such elements as top-level
\r
665 elements, then the element must be ignored along with its
\r
670 <p>if it is an element in a template and XSLT 1.0 does not allow
\r
671 such elements to occur in templates, then if the element is not
\r
672 instantiated, an error must not be signaled, and if the element is
\r
673 instantiated, the XSLT must perform fallback for the element as
\r
674 specified in <a href="#fallback">[<b>15 Fallback</b>]</a>;</p>
\r
678 <p>if the element has an attribute that XSLT 1.0 does not allow
\r
679 the element to have or if the element has an optional attribute with a
\r
680 value that the XSLT 1.0 does not allow the attribute to have, then the
\r
681 attribute must be ignored.</p>
\r
686 <p>Thus, any XSLT 1.0 processor must be able to process the following
\r
687 stylesheet without error, although the stylesheet includes elements
\r
688 from the XSLT namespace that are not defined in this
\r
691 <pre><xsl:stylesheet version="1.1"
\r
692 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
\r
693 <xsl:template match="/">
\r
695 <xsl:when test="system-property('xsl:version') >= 1.1">
\r
696 <xsl:exciting-new-1.1-feature/>
\r
698 <xsl:otherwise>
\r
701 <title>XSLT 1.1 required</title>
\r
704 <p>Sorry, this stylesheet requires XSLT 1.1.</p>
\r
707 </xsl:otherwise>
\r
708 </xsl:choose>
\r
709 </xsl:template>
\r
710 </xsl:stylesheet></pre>
\r
713 <b>NOTE: </b>If a stylesheet depends crucially on a top-level element
\r
714 introduced by a version of XSL after 1.0, then the stylesheet can use
\r
715 an <code>xsl:message</code> element with <code>terminate="yes"</code>
\r
716 (see <a href="#message">[<b>13 Messages</b>]</a>) to ensure that XSLT processors
\r
717 implementing earlier versions of XSL will not silently ignore the
\r
718 top-level element. For example,
\r
720 <pre><xsl:stylesheet version="1.5"
\r
721 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
\r
723 <xsl:important-new-1.1-declaration/>
\r
725 <xsl:template match="/">
\r
727 <xsl:when test="system-property('xsl:version') &lt; 1.1">
\r
728 <xsl:message terminate="yes">
\r
729 <xsl:text>Sorry, this stylesheet requires XSLT 1.1.</xsl:text>
\r
730 </xsl:message>
\r
732 <xsl:otherwise>
\r
734 </xsl:otherwise>
\r
735 </xsl:choose>
\r
736 </xsl:template>
\r
738 </xsl:stylesheet></pre>
\r
741 <p>If an <a href="#dt-expression">expression</a> occurs in
\r
742 an attribute that is processed in forwards-compatible mode, then an
\r
743 XSLT processor must recover from errors in the expression as
\r
749 <p>if the expression does not match the syntax allowed by the
\r
750 XPath grammar, then an error must not be signaled unless the
\r
751 expression is actually evaluated;</p>
\r
755 <p>if the expression calls a function with an unprefixed name
\r
756 that is not part of the XSLT library, then an error must not be
\r
757 signaled unless the function is actually called;</p>
\r
761 <p>if the expression calls a function with a number of arguments
\r
762 that XSLT does not allow or with arguments of types that XSLT does not
\r
763 allow, then an error must not be signaled unless the function is
\r
764 actually called.</p>
\r
774 <a name="section-Combining-Stylesheets"></a>2.6 Combining Stylesheets</h3>
\r
776 <p>XSLT provides two mechanisms to combine stylesheets:</p>
\r
780 <li>an inclusion mechanism that allows stylesheets to be combined
\r
781 without changing the semantics of the stylesheets being combined,
\r
784 <li>an import mechanism that allows stylesheets to override each
\r
791 <a name="include"></a>2.6.1 Stylesheet Inclusion</h4>
\r
793 <p class="element-syntax">
\r
794 <a name="element-include"></a><code><!-- Category: top-level-element --><br><xsl:include<br> <b>href</b> = <var>uri-reference</var> /></code>
\r
797 <p>An XSLT stylesheet may include another XSLT stylesheet using an
\r
798 <code>xsl:include</code> element. The <code>xsl:include</code> element
\r
799 has an <code>href</code> attribute whose value is a URI reference
\r
800 identifying the stylesheet to be included. A relative URI is resolved
\r
801 relative to the base URI of the <code>xsl:include</code> element (see
\r
802 <a href="#base-uri">[<b>3.2 Base URI</b>]</a>).</p>
\r
804 <p>The <code>xsl:include</code> element is only allowed as a <a href="#dt-top-level">top-level</a> element.</p>
\r
806 <p>The inclusion works at the XML tree level. The resource located by
\r
807 the <code>href</code> attribute value is parsed as an XML document,
\r
808 and the children of the <code>xsl:stylesheet</code> element in this
\r
809 document replace the <code>xsl:include</code> element in the including
\r
810 document. The fact that template rules or definitions are included
\r
811 does not affect the way they are processed.</p>
\r
813 <p>The included stylesheet may use the simplified syntax described in
\r
814 <a href="#result-element-stylesheet">[<b>2.3 Literal Result Element as Stylesheet</b>]</a>. The included stylesheet
\r
815 is treated the same as the equivalent <code>xsl:stylesheet</code>
\r
818 <p>It is an error if a stylesheet directly or indirectly includes
\r
822 <b>NOTE: </b>Including a stylesheet multiple times can cause errors
\r
823 because of duplicate definitions. Such multiple inclusions are less
\r
824 obvious when they are indirect. For example, if stylesheet
\r
825 <var>B</var> includes stylesheet <var>A</var>, stylesheet <var>C</var>
\r
826 includes stylesheet <var>A</var>, and stylesheet <var>D</var> includes
\r
827 both stylesheet <var>B</var> and stylesheet <var>C</var>, then
\r
828 <var>A</var> will be included indirectly by <var>D</var> twice. If
\r
829 all of <var>B</var>, <var>C</var> and <var>D</var> are used as
\r
830 independent stylesheets, then the error can be avoided by separating
\r
831 everything in <var>B</var> other than the inclusion of <var>A</var>
\r
832 into a separate stylesheet <var>B'</var> and changing <var>B</var> to
\r
833 contain just inclusions of <var>B'</var> and <var>A</var>, similarly
\r
834 for <var>C</var>, and then changing <var>D</var> to include
\r
835 <var>A</var>, <var>B'</var>, <var>C'</var>.</blockquote>
\r
841 <a name="import"></a>2.6.2 Stylesheet Import</h4>
\r
843 <p class="element-syntax">
\r
844 <a name="element-import"></a><code><xsl:import<br> <b>href</b> = <var>uri-reference</var> /></code>
\r
847 <p>An XSLT stylesheet may import another XSLT stylesheet using an
\r
848 <code>xsl:import</code> element. Importing a stylesheet is the same
\r
849 as including it (see <a href="#include">[<b>2.6.1 Stylesheet Inclusion</b>]</a>) except that definitions
\r
850 and template rules in the importing stylesheet take precedence over
\r
851 template rules and definitions in the imported stylesheet; this is
\r
852 described in more detail below. The <code>xsl:import</code> element
\r
853 has an <code>href</code> attribute whose value is a URI reference
\r
854 identifying the stylesheet to be imported. A relative URI is resolved
\r
855 relative to the base URI of the <code>xsl:import</code> element (see
\r
856 <a href="#base-uri">[<b>3.2 Base URI</b>]</a>).</p>
\r
858 <p>The <code>xsl:import</code> element is only allowed as a <a href="#dt-top-level">top-level</a> element. The
\r
859 <code>xsl:import</code> element children must precede all other
\r
860 element children of an <code>xsl:stylesheet</code> element, including
\r
861 any <code>xsl:include</code> element children. When
\r
862 <code>xsl:include</code> is used to include a stylesheet, any
\r
863 <code>xsl:import</code> elements in the included document are moved up
\r
864 in the including document to after any existing
\r
865 <code>xsl:import</code> elements in the including document.</p>
\r
867 <p>For example,</p>
\r
869 <pre><xsl:stylesheet version="1.0"
\r
870 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
\r
871 <xsl:import href="article.xsl"/>
\r
872 <xsl:import href="bigfont.xsl"/>
\r
873 <xsl:attribute-set name="note-style">
\r
874 <xsl:attribute name="font-style">italic</xsl:attribute>
\r
875 </xsl:attribute-set>
\r
876 </xsl:stylesheet></pre>
\r
879 <a name="dt-import-tree"></a>The
\r
880 <code>xsl:stylesheet</code> elements encountered during processing of
\r
881 a stylesheet that contains <code>xsl:import</code> elements are
\r
882 treated as forming an <b>import tree</b>. In the import tree,
\r
883 each <code>xsl:stylesheet</code> element has one import child for each
\r
884 <code>xsl:import</code> element that it contains. Any
\r
885 <code>xsl:include</code> elements are resolved before constructing the
\r
886 import tree. <a name="dt-import-precedence"></a>An <code>xsl:stylesheet</code> element in the import tree
\r
887 is defined to have lower <b>import precedence</b> than another
\r
888 <code>xsl:stylesheet</code> element in the import tree if it would be
\r
889 visited before that <code>xsl:stylesheet</code> element in a
\r
890 post-order traversal of the import tree (i.e. a traversal of the
\r
891 import tree in which an <code>xsl:stylesheet</code> element is visited
\r
892 after its import children). Each definition and template
\r
893 rule has import precedence determined by the
\r
894 <code>xsl:stylesheet</code> element that contains it.</p>
\r
896 <p>For example, suppose</p>
\r
901 <p>stylesheet <var>A</var> imports stylesheets <var>B</var>
\r
902 and <var>C</var> in that order;</p>
\r
906 <p>stylesheet <var>B</var> imports stylesheet
\r
911 <p>stylesheet <var>C</var> imports stylesheet
\r
917 <p>Then the order of import precedence (lowest first) is
\r
918 <var>D</var>, <var>B</var>, <var>E</var>, <var>C</var>,
\r
922 <b>NOTE: </b>Since <code>xsl:import</code> elements are required to occur
\r
923 before any definitions or template rules, an implementation that
\r
924 processes imported stylesheets at the point at which it encounters the
\r
925 <code>xsl:import</code> element will encounter definitions and
\r
926 template rules in increasing order of import precedence.</blockquote>
\r
928 <p>In general, a definition or template rule with higher import
\r
929 precedence takes precedence over a definition or template rule with
\r
930 lower import precedence. This is defined in detail for each kind of
\r
931 definition and for template rules.</p>
\r
933 <p>It is an error if a stylesheet directly or indirectly imports
\r
934 itself. Apart from this, the case where a stylesheet with a particular
\r
935 URI is imported in multiple places is not treated specially. The
\r
936 <a href="#dt-import-tree">import tree</a> will have a
\r
937 separate <code>xsl:stylesheet</code> for each place that it is
\r
941 <b>NOTE: </b>If <code>xsl:apply-imports</code> is used (see <a href="#apply-imports">[<b>5.6 Overriding Template Rules</b>]</a>), the behavior may be different from the
\r
942 behavior if the stylesheet had been imported only at the place with
\r
943 the highest <a href="#dt-import-precedence">import
\r
944 precedence</a>.</blockquote>
\r
952 <a name="section-Embedding-Stylesheets"></a>2.7 Embedding Stylesheets</h3>
\r
954 <p>Normally an XSLT stylesheet is a complete XML document with the
\r
955 <code>xsl:stylesheet</code> element as the document element. However,
\r
956 an XSLT stylesheet may also be embedded in another resource. Two forms
\r
957 of embedding are possible:</p>
\r
961 <li>the XSLT stylesheet may be textually embedded in a non-XML
\r
964 <li>the <code>xsl:stylesheet</code> element may occur in an XML
\r
965 document other than as the document element.</li>
\r
969 <p>To facilitate the second form of embedding, the
\r
970 <code>xsl:stylesheet</code> element is allowed to have an ID attribute
\r
971 that specifies a unique identifier.</p>
\r
974 <b>NOTE: </b>In order for such an attribute to be used with the XPath
\r
975 <b><a href="http://www.w3.org/TR/xpath#function-id">id</a></b> function, it must actually be declared in
\r
976 the DTD as being an ID.</blockquote>
\r
978 <p>The following example shows how the <code>xml-stylesheet</code>
\r
979 processing instruction <a href="#XMLSTYLE">[XML Stylesheet]</a> can be used to allow a
\r
980 document to contain its own stylesheet. The URI reference uses a
\r
981 relative URI with a fragment identifier to locate the
\r
982 <code>xsl:stylesheet</code> element:</p>
\r
984 <pre><?xml-stylesheet type="text/xml" href="#style1"?>
\r
985 <!DOCTYPE doc SYSTEM "doc.dtd">
\r
988 <xsl:stylesheet id="style1"
\r
990 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
\r
991 xmlns:fo="http://www.w3.org/1999/XSL/Format">
\r
992 <xsl:import href="doc.xsl"/>
\r
993 <xsl:template match="id('foo')">
\r
994 <fo:block font-weight="bold"><xsl:apply-templates/></fo:block>
\r
995 </xsl:template>
\r
996 <xsl:template match="xsl:stylesheet">
\r
997 <!-- ignore -->
\r
998 </xsl:template>
\r
999 </xsl:stylesheet>
\r
1002 <para id="foo">
\r
1010 <b>NOTE: </b>A stylesheet that is embedded in the document to which it is
\r
1011 to be applied or that may be included or imported into an stylesheet
\r
1012 that is so embedded typically needs to contain a template rule that
\r
1013 specifies that <code>xsl:stylesheet</code> elements are to be
\r
1014 ignored.</blockquote>
\r
1022 <a name="data-model"></a>3 Data Model</h2>
\r
1024 <p>The data model used by XSLT is the same as that used by <a href="http://www.w3.org/TR/xpath#data-model">XPath</a> with the additions
\r
1025 described in this section. XSLT operates on source, result and
\r
1026 stylesheet documents using the same data model. Any two XML documents
\r
1027 that have the same tree will be treated the same by XSLT.</p>
\r
1029 <p>Processing instructions and comments in the stylesheet are ignored:
\r
1030 the stylesheet is treated as if neither processing instruction nodes
\r
1031 nor comment nodes were included in the tree that represents the
\r
1036 <a name="root-node-children"></a>3.1 Root Node Children</h3>
\r
1038 <p>The normal restrictions on the children of the root node are
\r
1039 relaxed for the result tree. The result tree may have any sequence of
\r
1040 nodes as children that would be possible for an element node. In
\r
1041 particular, it may have text node children, and any number of element
\r
1042 node children. When written out using the XML output method (see
\r
1043 <a href="#output">[<b>16 Output</b>]</a>), it is possible that a result tree will not
\r
1044 be a well-formed XML document; however, it will always be a
\r
1045 well-formed external general parsed entity.</p>
\r
1047 <p>When the source tree is created by parsing a well-formed XML
\r
1048 document, the root node of the source tree will automatically satisfy
\r
1049 the normal restrictions of having no text node children and exactly
\r
1050 one element child. When the source tree is created in some other way,
\r
1051 for example by using the DOM, the usual restrictions are relaxed for
\r
1052 the source tree as for the result tree.</p>
\r
1058 <a name="base-uri"></a>3.2 Base URI</h3>
\r
1060 <p>Every node also has an associated URI called its base URI, which is
\r
1061 used for resolving attribute values that represent relative URIs into
\r
1062 absolute URIs. If an element or processing instruction occurs in an
\r
1063 external entity, the base URI of that element or processing
\r
1064 instruction is the URI of the external entity; otherwise, the base URI
\r
1065 is the base URI of the document. The base URI of the document node is
\r
1066 the URI of the document entity. The base URI for a text node, a
\r
1067 comment node, an attribute node or a namespace node is the base URI of
\r
1068 the parent of the node.</p>
\r
1074 <a name="unparsed-entities"></a>3.3 Unparsed Entities</h3>
\r
1076 <p>The root node has a mapping that gives the URI for each unparsed
\r
1077 entity declared in the document's DTD. The URI is generated from the
\r
1078 system identifier and public identifier specified in the entity
\r
1079 declaration. The XSLT processor may use the public identifier to
\r
1080 generate a URI for the entity instead of the URI specified in the
\r
1081 system identifier. If the XSLT processor does not use the public
\r
1082 identifier to generate the URI, it must use the system identifier; if
\r
1083 the system identifier is a relative URI, it must be resolved into an
\r
1084 absolute URI using the URI of the resource containing the entity
\r
1085 declaration as the base URI <a href="#RFC2396">[RFC2396]</a>.</p>
\r
1091 <a name="strip"></a>3.4 Whitespace Stripping</h3>
\r
1093 <p>After the tree for a source document or stylesheet document has
\r
1094 been constructed, but before it is otherwise processed by XSLT,
\r
1095 some text nodes are stripped. A text node is never stripped
\r
1096 unless it contains only whitespace characters. Stripping the text
\r
1097 node removes the text node from the tree. The stripping process takes
\r
1098 as input a set of element names for which whitespace must be
\r
1099 preserved. The stripping process is applied to both stylesheets and
\r
1100 source documents, but the set of whitespace-preserving element names
\r
1101 is determined differently for stylesheets and for source
\r
1104 <p>A text node is preserved if any of the following apply:</p>
\r
1109 <p>The element name of the parent of the text node is in the set
\r
1110 of whitespace-preserving element names.</p>
\r
1114 <p>The text node contains at least one non-whitespace character.
\r
1115 As in XML, a whitespace character is #x20, #x9, #xD or #xA.</p>
\r
1119 <p>An ancestor element of the text node has an
\r
1120 <code>xml:space</code> attribute with a value of
\r
1121 <code>preserve</code>, and no closer ancestor element has
\r
1122 <code>xml:space</code> with a value of
\r
1123 <code>default</code>.</p>
\r
1128 <p>Otherwise, the text node is stripped.</p>
\r
1130 <p>The <code>xml:space</code> attributes are not stripped from the
\r
1134 <b>NOTE: </b>This implies that if an <code>xml:space</code> attribute is
\r
1135 specified on a literal result element, it will be included in the
\r
1136 result.</blockquote>
\r
1138 <p>For stylesheets, the set of whitespace-preserving element names
\r
1139 consists of just <code>xsl:text</code>.</p>
\r
1141 <p class="element-syntax">
\r
1142 <a name="element-strip-space"></a><code><!-- Category: top-level-element --><br><xsl:strip-space<br> <b>elements</b> = <var>tokens</var> /></code>
\r
1145 <p class="element-syntax">
\r
1146 <a name="element-preserve-space"></a><code><!-- Category: top-level-element --><br><xsl:preserve-space<br> <b>elements</b> = <var>tokens</var> /></code>
\r
1149 <p>For source documents, the set of whitespace-preserving element
\r
1150 names is specified by <code>xsl:strip-space</code> and
\r
1151 <code>xsl:preserve-space</code> <a href="#dt-top-level">top-level</a> elements. These elements each
\r
1152 have an <code>elements</code> attribute whose value is a
\r
1153 whitespace-separated list of <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a>s. Initially, the
\r
1154 set of whitespace-preserving element names contains all element names.
\r
1155 If an element name matches a <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a> in an
\r
1156 <code>xsl:strip-space</code> element, then it is removed from the set
\r
1157 of whitespace-preserving element names. If an element name matches a
\r
1158 <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a> in an
\r
1159 <code>xsl:preserve-space</code> element, then it is added to the set
\r
1160 of whitespace-preserving element names. An element matches a <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a> if and only if the
\r
1161 <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a> would be true
\r
1162 for the element as an <a href="http://www.w3.org/TR/xpath#node-tests">XPath node
\r
1163 test</a>. Conflicts between matches to
\r
1164 <code>xsl:strip-space</code> and <code>xsl:preserve-space</code>
\r
1165 elements are resolved the same way as conflicts between template rules
\r
1166 (see <a href="#conflict">[<b>5.5 Conflict Resolution for Template Rules</b>]</a>). Thus, the applicable match for a
\r
1167 particular element name is determined as follows:</p>
\r
1172 <p>First, any match with lower <a href="#dt-import-precedence">import precedence</a> than another
\r
1173 match is ignored.</p>
\r
1177 <p>Next, any match with a <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a> that has a lower
\r
1178 <a href="#dt-default-priority">default priority</a> than the
\r
1179 <a href="#dt-default-priority">default priority</a> of the
\r
1180 <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a> of another
\r
1181 match is ignored.</p>
\r
1186 <p>It is an error if this leaves more than one match. An XSLT
\r
1187 processor may signal the error; if it does not signal the error, it
\r
1188 must recover by choosing, from amongst the matches that are left, the
\r
1189 one that occurs last in the stylesheet.</p>
\r
1197 <a name="section-Expressions"></a>4 Expressions</h2>
\r
1199 <p>XSLT uses the expression language defined by XPath <a href="#XPATH">[XPath]</a>. Expressions are used in XSLT for a variety of purposes
\r
1203 <li>selecting nodes for processing;</li>
\r
1204 <li>specifying conditions for different ways of processing a node;</li>
\r
1205 <li>generating text to be inserted in the result tree.</li>
\r
1209 <a name="dt-expression"></a>An
\r
1210 <b>expression</b> must match the XPath production <a href="http://www.w3.org/TR/xpath#NT-Expr">Expr</a>.</p>
\r
1212 <p>Expressions occur as the value of certain attributes on
\r
1213 XSLT-defined elements and within curly braces in <a href="#dt-attribute-value-template">attribute value
\r
1214 template</a>s.</p>
\r
1216 <p>In XSLT, an outermost expression (i.e. an expression that is not
\r
1217 part of another expression) gets its context as follows:</p>
\r
1222 <p>the context node comes from the <a href="#dt-current-node">current node</a>
\r
1227 <p>the context position comes from the position of the <a href="#dt-current-node">current node</a> in the <a href="#dt-current-node-list">current node list</a>; the first
\r
1232 <p>the context size comes from the size of the <a href="#dt-current-node-list">current node list</a>
\r
1237 <p>the variable bindings are the bindings in scope on the
\r
1238 element which has the attribute in which the expression occurs (see
\r
1239 <a href="#variables">[<b>11 Variables and Parameters</b>]</a>)</p>
\r
1243 <p>the set of namespace declarations are those in scope on the
\r
1244 element which has the attribute in which the expression occurs;
\r
1245 this includes the implicit declaration of the prefix <code>xml</code>
\r
1246 required by the the XML Namespaces Recommendation <a href="#XMLNAMES">[XML Names]</a>;
\r
1248 namespace (as declared by <code>xmlns</code>) is not part of this
\r
1253 <p>the function library consists of the core function library
\r
1254 together with the additional functions defined in <a href="#add-func">[<b>12 Additional Functions</b>]</a> and extension functions as described in <a href="#extension">[<b>14 Extensions</b>]</a>; it is an error for an expression to include a call
\r
1255 to any other function</p>
\r
1264 <a name="rules"></a>5 Template Rules</h2>
\r
1268 <a name="section-Processing-Model"></a>5.1 Processing Model</h3>
\r
1270 <p>A list of source nodes is processed to create a result tree
\r
1271 fragment. The result tree is constructed by processing a list
\r
1272 containing just the root node. A list of source nodes is processed by
\r
1273 appending the result tree structure created by processing each of the
\r
1274 members of the list in order. A node is processed by finding all the
\r
1275 template rules with patterns that match the node, and choosing the
\r
1276 best amongst them; the chosen rule's template is then instantiated
\r
1277 with the node as the <a href="#dt-current-node">current
\r
1278 node</a> and with the list of source nodes as the <a href="#dt-current-node-list">current node list</a>. A template
\r
1279 typically contains instructions that select an additional list of
\r
1280 source nodes for processing. The process of matching, instantiation
\r
1281 and selection is continued recursively until no new source nodes are
\r
1282 selected for processing.</p>
\r
1284 <p>Implementations are free to process the source document in any way
\r
1285 that produces the same result as if it were processed using this
\r
1286 processing model.</p>
\r
1292 <a name="patterns"></a>5.2 Patterns</h3>
\r
1295 <a name="dt-pattern"></a>Template rules identify the
\r
1296 nodes to which they apply by using a <b>pattern</b>. As well as
\r
1297 being used in template rules, patterns are used for numbering (see
\r
1298 <a href="#number">[<b>7.7 Numbering</b>]</a>) and for declaring keys (see <a href="#key">[<b>12.2 Keys</b>]</a>). A pattern specifies a set of conditions on a node. A
\r
1299 node that satisfies the conditions matches the pattern; a node that
\r
1300 does not satisfy the conditions does not match the pattern. The
\r
1301 syntax for patterns is a subset of the syntax for expressions. In
\r
1302 particular, location paths that meet certain restrictions can be used
\r
1303 as patterns. An expression that is also a pattern always evaluates to
\r
1304 an object of type node-set. A node matches a pattern if the node is a
\r
1305 member of the result of evaluating the pattern as an expression with
\r
1306 respect to some possible context; the possible contexts are those
\r
1307 whose context node is the node being matched or one of its
\r
1310 <p>Here are some examples of patterns:</p>
\r
1316 <code>para</code> matches any <code>para</code> element</p>
\r
1321 <code>*</code> matches any element</p>
\r
1326 <code>chapter|appendix</code> matches any
\r
1327 <code>chapter</code> element and any <code>appendix</code>
\r
1333 <code>olist/item</code> matches any <code>item</code> element with
\r
1334 an <code>olist</code> parent</p>
\r
1339 <code>appendix//para</code> matches any <code>para</code> element with
\r
1340 an <code>appendix</code> ancestor element</p>
\r
1345 <code>/</code> matches the root node</p>
\r
1350 <code>text()</code> matches any text node</p>
\r
1355 <code>processing-instruction()</code> matches any processing
\r
1361 <code>node()</code> matches any node other than an attribute
\r
1362 node and the root node</p>
\r
1367 <code>id("W11")</code> matches the element with unique ID
\r
1374 <code>para[1]</code> matches any <code>para</code> element
\r
1375 that is the first <code>para</code> child element of its
\r
1381 <code>*[position()=1 and self::para]</code> matches any
\r
1382 <code>para</code> element that is the first child element of its
\r
1388 <code>para[last()=1]</code> matches any <code>para</code>
\r
1389 element that is the only <code>para</code> child element of its
\r
1395 <code>items/item[position()>1]</code> matches any
\r
1396 <code>item</code> element that has a <code>items</code> parent and
\r
1397 that is not the first <code>item</code> child of its parent</p>
\r
1402 <code>item[position() mod 2 = 1]</code> would be true for any
\r
1403 <code>item</code> element that is an odd-numbered <code>item</code>
\r
1404 child of its parent.</p>
\r
1409 <code>div[@class="appendix"]//p</code> matches any
\r
1410 <code>p</code> element with a <code>div</code> ancestor element that
\r
1411 has a <code>class</code> attribute with value
\r
1412 <code>appendix</code>
\r
1418 <code>@class</code> matches any <code>class</code> attribute
\r
1419 (<i>not</i> any element that has a <code>class</code>
\r
1425 <code>@*</code> matches any attribute</p>
\r
1430 <p>A pattern must match the grammar for <a href="#NT-Pattern">Pattern</a>. A <a href="#NT-Pattern">Pattern</a> is
\r
1431 a set of location path patterns separated by <code>|</code>. A
\r
1432 location path pattern is a location path whose steps all use only the
\r
1433 <code>child</code> or <code>attribute</code> axes. Although patterns
\r
1434 must not use the <code>descendant-or-self</code> axis, patterns may
\r
1435 use the <code>//</code> operator as well as the <code>/</code>
\r
1436 operator. Location path patterns can also start with an
\r
1437 <b><a href="http://www.w3.org/TR/xpath#function-id">id</a></b> or <b><a href="#function-key">key</a></b> function call
\r
1438 with a literal argument. Predicates in a pattern can use arbitrary
\r
1439 expressions just like predicates in a location path.</p>
\r
1442 <table class="scrap">
\r
1444 <tr valign="baseline">
\r
1445 <td><a name="NT-Pattern"></a>[1] </td><td>Pattern</td><td> ::= </td><td><a href="#NT-LocationPathPattern">LocationPathPattern</a></td><td></td>
\r
1447 <tr valign="baseline">
\r
1448 <td></td><td></td><td></td><td>| <a href="#NT-Pattern">Pattern</a> '|' <a href="#NT-LocationPathPattern">LocationPathPattern</a></td><td></td>
\r
1450 <tr valign="baseline">
\r
1451 <td><a name="NT-LocationPathPattern"></a>[2] </td><td>LocationPathPattern</td><td> ::= </td><td>'/' <a href="#NT-RelativePathPattern">RelativePathPattern</a>?</td><td></td>
\r
1453 <tr valign="baseline">
\r
1454 <td></td><td></td><td></td><td>| <a href="#NT-IdKeyPattern">IdKeyPattern</a> (('/' | '//') <a href="#NT-RelativePathPattern">RelativePathPattern</a>)?</td><td></td>
\r
1456 <tr valign="baseline">
\r
1457 <td></td><td></td><td></td><td>| '//'? <a href="#NT-RelativePathPattern">RelativePathPattern</a></td><td></td>
\r
1459 <tr valign="baseline">
\r
1460 <td><a name="NT-IdKeyPattern"></a>[3] </td><td>IdKeyPattern</td><td> ::= </td><td>'id' '(' <a href="http://www.w3.org/TR/xpath#NT-Literal">Literal</a> ')'</td><td></td>
\r
1462 <tr valign="baseline">
\r
1463 <td></td><td></td><td></td><td>| 'key' '(' <a href="http://www.w3.org/TR/xpath#NT-Literal">Literal</a> ',' <a href="http://www.w3.org/TR/xpath#NT-Literal">Literal</a> ')'</td><td></td>
\r
1465 <tr valign="baseline">
\r
1466 <td><a name="NT-RelativePathPattern"></a>[4] </td><td>RelativePathPattern</td><td> ::= </td><td><a href="#NT-StepPattern">StepPattern</a></td><td></td>
\r
1468 <tr valign="baseline">
\r
1469 <td></td><td></td><td></td><td>| <a href="#NT-RelativePathPattern">RelativePathPattern</a> '/' <a href="#NT-StepPattern">StepPattern</a></td><td></td>
\r
1471 <tr valign="baseline">
\r
1472 <td></td><td></td><td></td><td>| <a href="#NT-RelativePathPattern">RelativePathPattern</a> '//' <a href="#NT-StepPattern">StepPattern</a></td><td></td>
\r
1474 <tr valign="baseline">
\r
1475 <td><a name="NT-StepPattern"></a>[5] </td><td>StepPattern</td><td> ::= </td><td>
\r
1476 <a href="#NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</a>
\r
1477 <a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a>
\r
1478 <a href="http://www.w3.org/TR/xpath#NT-Predicate">Predicate</a>*
\r
1481 <tr valign="baseline">
\r
1482 <td><a name="NT-ChildOrAttributeAxisSpecifier"></a>[6] </td><td>ChildOrAttributeAxisSpecifier</td><td> ::= </td><td><a href="http://www.w3.org/TR/xpath#NT-AbbreviatedAxisSpecifier">AbbreviatedAxisSpecifier</a></td><td></td>
\r
1484 <tr valign="baseline">
\r
1485 <td></td><td></td><td></td><td>| ('child' | 'attribute') '::'</td><td></td>
\r
1490 <p>A pattern is defined to match a node if and only if there is
\r
1491 possible context such that when the pattern is evaluated as an
\r
1492 expression with that context, the node is a member of the resulting
\r
1493 node-set. When a node is being matched, the possible contexts have a
\r
1494 context node that is the node being matched or any ancestor of that
\r
1495 node, and a context node list containing just the context node.</p>
\r
1497 <p>For example, <code>p</code> matches any <code>p</code> element,
\r
1498 because for any <code>p</code> if the expression <code>p</code> is
\r
1499 evaluated with the parent of the <code>p</code> element as context the
\r
1500 resulting node-set will contain that <code>p</code> element as one of
\r
1504 <b>NOTE: </b>This matches even a <code>p</code> element that is the
\r
1505 document element, since the document root is the parent of the
\r
1506 document element.</blockquote>
\r
1508 <p>Although the semantics of patterns are specified indirectly in
\r
1509 terms of expression evaluation, it is easy to understand the meaning
\r
1510 of a pattern directly without thinking in terms of expression
\r
1511 evaluation. In a pattern, <code>|</code> indicates alternatives; a
\r
1512 pattern with one or more <code>|</code> separated alternatives matches
\r
1513 if any one of the alternative matches. A pattern that consists of a
\r
1514 sequence of <a href="#NT-StepPattern">StepPattern</a>s separated by
\r
1515 <code>/</code> or <code>//</code> is matched from right to left. The
\r
1516 pattern only matches if the rightmost <a href="#NT-StepPattern">StepPattern</a> matches and a suitable element
\r
1517 matches the rest of the pattern; if the separator is <code>/</code>
\r
1518 then only the parent is a suitable element; if the separator is
\r
1519 <code>//</code>, then any ancestor is a suitable element. A <a href="#NT-StepPattern">StepPattern</a> that uses the child axis matches
\r
1520 if the <a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a> is true for the
\r
1521 node and the node is not an attribute node. A <a href="#NT-StepPattern">StepPattern</a> that uses the attribute axis
\r
1522 matches if the <a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a> is true
\r
1523 for the node and the node is an attribute node. When <code>[]</code>
\r
1524 is present, then the first <a href="http://www.w3.org/TR/xpath#NT-PredicateExpr">PredicateExpr</a> in a <a href="#NT-StepPattern">StepPattern</a> is evaluated with the node being
\r
1525 matched as the context node and the siblings of the context node that
\r
1526 match the <a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a> as the
\r
1527 context node list, unless the node being matched is an attribute node,
\r
1528 in which case the context node list is all the attributes that have
\r
1529 the same parent as the attribute being matched and that match the <a href="http://www.w3.org/TR/xpath#NT-NameTest">NameTest</a>.</p>
\r
1531 <p>For example</p>
\r
1533 <pre>appendix//ulist/item[position()=1]</pre>
\r
1535 <p>matches a node if and only if all of the following are true:</p>
\r
1540 <p>the <a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a> <code>item</code> is
\r
1541 true for the node and the node is not an attribute; in other words the
\r
1542 node is an <code>item</code> element</p>
\r
1546 <p>evaluating the <a href="http://www.w3.org/TR/xpath#NT-PredicateExpr">PredicateExpr</a>
\r
1547 <code>position()=1</code> with the node as context node and the
\r
1548 siblings of the node that are <code>item</code> elements as the
\r
1549 context node list yields true</p>
\r
1553 <p>the node has a parent that matches
\r
1554 <code>appendix//ulist</code>; this will be true if the parent is a
\r
1555 <code>ulist</code> element that has an <code>appendix</code> ancestor
\r
1565 <a name="section-Defining-Template-Rules"></a>5.3 Defining Template Rules</h3>
\r
1567 <p class="element-syntax">
\r
1568 <a name="element-template"></a><code><!-- Category: top-level-element --><br><xsl:template<br> match = <var>pattern</var>
\r
1569 <br> name = <var>qname</var>
\r
1570 <br> priority = <var>number</var>
\r
1571 <br> mode = <var>qname</var>><br> <!-- Content: (<a href="#element-param">xsl:param</a>*, <var>template</var>) --><br></xsl:template></code>
\r
1574 <p>A template rule is specified with the <code>xsl:template</code>
\r
1575 element. The <code>match</code> attribute is a <a href="#NT-Pattern">Pattern</a> that identifies the source node or nodes
\r
1576 to which the rule applies. The <code>match</code> attribute is
\r
1577 required unless the <code>xsl:template</code> element has a
\r
1578 <code>name</code> attribute (see <a href="#named-templates">[<b>6 Named Templates</b>]</a>).
\r
1579 It is an error for the value of the <code>match</code> attribute to
\r
1580 contain a <a href="http://www.w3.org/TR/xpath#NT-VariableReference">VariableReference</a>. The
\r
1581 content of the <code>xsl:template</code> element is the template that
\r
1582 is instantiated when the template rule is applied.</p>
\r
1584 <p>For example, an XML document might contain:</p>
\r
1586 <pre>This is an <emph>important</emph> point.</pre>
\r
1588 <p>The following template rule matches <code>emph</code> elements and
\r
1589 produces a <code>fo:inline-sequence</code> formatting object with a
\r
1590 <code>font-weight</code> property of <code>bold</code>.</p>
\r
1592 <pre><xsl:template match="emph">
\r
1593 <fo:inline-sequence font-weight="bold">
\r
1594 <xsl:apply-templates/>
\r
1595 </fo:inline-sequence>
\r
1596 </xsl:template>
\r
1600 <b>NOTE: </b>Examples in this document use the <code>fo:</code> prefix for
\r
1601 the namespace <code>http://www.w3.org/1999/XSL/Format</code>, which is
\r
1602 the namespace of the formatting objects defined in <a href="#XSL">[XSL]</a>.</blockquote>
\r
1604 <p>As described next, the <code>xsl:apply-templates</code> element
\r
1605 recursively processes the children of the source element.</p>
\r
1611 <a name="section-Applying-Template-Rules"></a>5.4 Applying Template Rules</h3>
\r
1613 <p class="element-syntax">
\r
1614 <a name="element-apply-templates"></a><code><!-- Category: instruction --><br><xsl:apply-templates<br> select = <var>node-set-expression</var>
\r
1615 <br> mode = <var>qname</var>><br> <!-- Content: (<a href="#element-sort">xsl:sort</a> | <a href="#element-with-param">xsl:with-param</a>)* --><br></xsl:apply-templates></code>
\r
1618 <p>This example creates a block for a <code>chapter</code> element and
\r
1619 then processes its immediate children.</p>
\r
1621 <pre><xsl:template match="chapter">
\r
1623 <xsl:apply-templates/>
\r
1625 </xsl:template></pre>
\r
1627 <p>In the absence of a <code>select</code> attribute, the
\r
1628 <code>xsl:apply-templates</code> instruction processes all of the
\r
1629 children of the current node, including text nodes. However, text
\r
1630 nodes that have been stripped as specified in <a href="#strip">[<b>3.4 Whitespace Stripping</b>]</a>
\r
1631 will not be processed. If stripping of whitespace nodes has not been
\r
1632 enabled for an element, then all whitespace in the content of the
\r
1633 element will be processed as text, and thus whitespace
\r
1634 between child elements will count in determining the position of a
\r
1635 child element as returned by the <b><a href="http://www.w3.org/TR/xpath#function-position">position</a></b>
\r
1638 <p>A <code>select</code> attribute can be used to process nodes
\r
1639 selected by an expression instead of processing all children. The
\r
1640 value of the <code>select</code> attribute is an <a href="#dt-expression">expression</a>. The expression must
\r
1641 evaluate to a node-set. The selected set of nodes is processed in
\r
1642 document order, unless a sorting specification is present (see
\r
1643 <a href="#sorting">[<b>10 Sorting</b>]</a>). The following example processes all of the
\r
1644 <code>author</code> children of the <code>author-group</code>:</p>
\r
1646 <pre><xsl:template match="author-group">
\r
1647 <fo:inline-sequence>
\r
1648 <xsl:apply-templates select="author"/>
\r
1649 </fo:inline-sequence>
\r
1650 </xsl:template></pre>
\r
1652 <p>The following example processes all of the <code>given-name</code>s
\r
1653 of the <code>author</code>s that are children of
\r
1654 <code>author-group</code>:</p>
\r
1656 <pre><xsl:template match="author-group">
\r
1657 <fo:inline-sequence>
\r
1658 <xsl:apply-templates select="author/given-name"/>
\r
1659 </fo:inline-sequence>
\r
1660 </xsl:template></pre>
\r
1662 <p>This example processes all of the <code>heading</code> descendant
\r
1663 elements of the <code>book</code> element.</p>
\r
1665 <pre><xsl:template match="book">
\r
1667 <xsl:apply-templates select=".//heading"/>
\r
1669 </xsl:template></pre>
\r
1671 <p>It is also possible to process elements that are not descendants of
\r
1672 the current node. This example assumes that a <code>department</code>
\r
1673 element has <code>group</code> children and <code>employee</code>
\r
1674 descendants. It finds an employee's department and then processes
\r
1675 the <code>group</code> children of the <code>department</code>.</p>
\r
1677 <pre><xsl:template match="employee">
\r
1679 Employee <xsl:apply-templates select="name"/> belongs to group
\r
1680 <xsl:apply-templates select="ancestor::department/group"/>
\r
1682 </xsl:template></pre>
\r
1684 <p>Multiple <code>xsl:apply-templates</code> elements can be used within a
\r
1685 single template to do simple reordering. The following example
\r
1686 creates two HTML tables. The first table is filled with domestic sales
\r
1687 while the second table is filled with foreign sales.</p>
\r
1689 <pre><xsl:template match="product">
\r
1691 <xsl:apply-templates select="sales/domestic"/>
\r
1694 <xsl:apply-templates select="sales/foreign"/>
\r
1696 </xsl:template></pre>
\r
1701 It is possible for there to be two matching descendants where one
\r
1702 is a descendant of the other. This case is not treated specially:
\r
1703 both descendants will be processed as usual. For example, given a
\r
1706 <pre><doc><div><div></div></div></doc></pre>
\r
1710 <pre><xsl:template match="doc">
\r
1711 <xsl:apply-templates select=".//div"/>
\r
1712 </xsl:template></pre>
\r
1714 will process both the outer <code>div</code> and inner <code>div</code>
\r
1720 <b>NOTE: </b>Typically, <code>xsl:apply-templates</code> is used to
\r
1721 process only nodes that are descendants of the current node. Such use
\r
1722 of <code>xsl:apply-templates</code> cannot result in non-terminating
\r
1723 processing loops. However, when <code>xsl:apply-templates</code> is
\r
1724 used to process elements that are not descendants of the current node,
\r
1725 the possibility arises of non-terminating loops. For example,
\r
1727 <pre style="color: red"><xsl:template match="foo">
\r
1728 <xsl:apply-templates select="."/>
\r
1729 </xsl:template></pre>
\r
1731 Implementations may be able to detect such loops in some cases, but
\r
1732 the possibility exists that a stylesheet may enter a non-terminating
\r
1733 loop that an implementation is unable to detect. This may present a
\r
1734 denial of service security risk.</blockquote>
\r
1740 <a name="conflict"></a>5.5 Conflict Resolution for Template Rules</h3>
\r
1742 <p>It is possible for a source node to match more than one template
\r
1743 rule. The template rule to be used is determined as follows:</p>
\r
1748 <p>First, all matching template rules that have lower <a href="#dt-import-precedence">import precedence</a> than the
\r
1749 matching template rule or rules with the highest import precedence are
\r
1750 eliminated from consideration.</p>
\r
1754 <p>Next, all matching template rules that have lower priority
\r
1755 than the matching template rule or rules with the highest priority are
\r
1756 eliminated from consideration. The priority of a template rule is
\r
1757 specified by the <code>priority</code> attribute on the template rule.
\r
1758 The value of this must be a real number (positive or negative),
\r
1759 matching the production <a href="http://www.w3.org/TR/xpath#NT-Number">Number</a>
\r
1760 with an optional leading minus sign (<code>-</code>). <a name="dt-default-priority"></a>The <b>default
\r
1761 priority</b> is computed as follows:</p>
\r
1766 <p>If the pattern contains multiple alternatives separated by
\r
1767 <code>|</code>, then it is treated equivalently to a set of template
\r
1768 rules, one for each alternative.</p>
\r
1772 <p>If the pattern has the form of a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> preceded by a <a href="#NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</a>
\r
1774 <code>processing-instruction(</code><a href="http://www.w3.org/TR/xpath#NT-Literal">Literal</a><code>)</code> preceded by a <a href="#NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</a>,
\r
1775 then the priority is 0.</p>
\r
1779 <p>If the pattern has the form <a href="http://www.w3.org/TR/REC-xml-names#NT-NCName">NCName</a><code>:*</code> preceded by a
\r
1780 <a href="#NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</a>,
\r
1781 then the priority is -0.25.</p>
\r
1785 <p>Otherwise, if the pattern consists of just a <a href="http://www.w3.org/TR/xpath#NT-NodeTest">NodeTest</a> preceded by a <a href="#NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</a>,
\r
1786 then the priority is -0.5.</p>
\r
1790 <p>Otherwise, the priority is 0.5.</p>
\r
1795 <p>Thus, the most common kind of pattern (a pattern that tests for a
\r
1796 node with a particular type and a particular expanded-name) has
\r
1797 priority 0. The next less specific kind of pattern (a pattern that
\r
1798 tests for a node with a particular type and an expanded-name with a
\r
1799 particular namespace URI) has priority -0.25. Patterns less specific
\r
1800 than this (patterns that just tests for nodes with particular types)
\r
1801 have priority -0.5. Patterns more specific than the most common kind
\r
1802 of pattern have priority 0.5.</p>
\r
1808 <p>It is an error if this leaves more than one matching template
\r
1809 rule. An XSLT processor may signal the error; if it does not signal
\r
1810 the error, it must recover by choosing, from amongst the matching
\r
1811 template rules that are left, the one that occurs last in the
\r
1818 <a name="apply-imports"></a>5.6 Overriding Template Rules</h3>
\r
1820 <p class="element-syntax">
\r
1821 <a name="element-apply-imports"></a><code><!-- Category: instruction --><br><xsl:apply-imports /></code>
\r
1824 <p>A template rule that is being used to override a template rule in
\r
1825 an imported stylesheet (see <a href="#conflict">[<b>5.5 Conflict Resolution for Template Rules</b>]</a>) can use the
\r
1826 <code>xsl:apply-imports</code> element to invoke the overridden
\r
1827 template rule.</p>
\r
1830 <a name="dt-current-template-rule"></a>At any point in the processing of a stylesheet, there is a
\r
1831 <b>current template rule</b>. Whenever a template rule is
\r
1832 chosen by matching a pattern, the template rule becomes the current
\r
1833 template rule for the instantiation of the rule's template. When an
\r
1834 <code>xsl:for-each</code> element is instantiated, the current
\r
1835 template rule becomes null for the instantiation of the content of the
\r
1836 <code>xsl:for-each</code> element.</p>
\r
1839 <code>xsl:apply-imports</code> processes the current node using
\r
1840 only template rules that were imported into the stylesheet element
\r
1841 containing the current template rule; the node is processed in the
\r
1842 current template rule's mode. It is an error if
\r
1843 <code>xsl:apply-imports</code> is instantiated when the current
\r
1844 template rule is null.</p>
\r
1846 <p>For example, suppose the stylesheet <code>doc.xsl</code> contains a
\r
1847 template rule for <code>example</code> elements:</p>
\r
1849 <pre><xsl:template match="example">
\r
1850 <pre><xsl:apply-templates/></pre>
\r
1851 </xsl:template></pre>
\r
1853 <p>Another stylesheet could import <code>doc.xsl</code> and modify the
\r
1854 treatment of <code>example</code> elements as follows:</p>
\r
1856 <pre><xsl:import href="doc.xsl"/>
\r
1858 <xsl:template match="example">
\r
1859 <div style="border: solid red">
\r
1860 <xsl:apply-imports/>
\r
1862 </xsl:template></pre>
\r
1864 <p>The combined effect would be to transform an <code>example</code>
\r
1865 into an element of the form:</p>
\r
1867 <pre><div style="border: solid red"><pre>...</pre></div></pre>
\r
1873 <a name="modes"></a>5.7 Modes</h3>
\r
1875 <p>Modes allow an element to be processed multiple times, each time
\r
1876 producing a different result.</p>
\r
1878 <p>Both <code>xsl:template</code> and <code>xsl:apply-templates</code>
\r
1879 have an optional <code>mode</code> attribute. The value of the
\r
1880 <code>mode</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>, which is expanded as described
\r
1881 in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>. If <code>xsl:template</code> does not have
\r
1882 a <code>match</code> attribute, it must not have a <code>mode</code>
\r
1883 attribute. If an <code>xsl:apply-templates</code> element has a
\r
1884 <code>mode</code> attribute, then it applies only to those template
\r
1885 rules from <code>xsl:template</code> elements that have a
\r
1886 <code>mode</code> attribute with the same value; if an
\r
1887 <code>xsl:apply-templates</code> element does not have a
\r
1888 <code>mode</code> attribute, then it applies only to those template
\r
1889 rules from <code>xsl:template</code> elements that do not have a
\r
1890 <code>mode</code> attribute.</p>
\r
1896 <a name="built-in-rule"></a>5.8 Built-in Template Rules</h3>
\r
1898 <p>There is a built-in template rule to allow recursive processing to
\r
1899 continue in the absence of a successful pattern match by an explicit
\r
1900 template rule in the stylesheet. This template rule applies to both
\r
1901 element nodes and the root node. The following shows the equivalent
\r
1902 of the built-in template rule:</p>
\r
1904 <pre><xsl:template match="*|/">
\r
1905 <xsl:apply-templates/>
\r
1906 </xsl:template></pre>
\r
1908 <p>There is also a built-in template rule for each mode, which allows
\r
1909 recursive processing to continue in the same mode in the absence of a
\r
1910 successful pattern match by an explicit template rule in the
\r
1911 stylesheet. This template rule applies to both element nodes and the
\r
1912 root node. The following shows the equivalent of the built-in
\r
1913 template rule for mode <code><var>m</var></code>.</p>
\r
1915 <pre><xsl:template match="*|/" mode="<var>m</var>">
\r
1916 <xsl:apply-templates mode="<var>m</var>"/>
\r
1917 </xsl:template></pre>
\r
1919 <p>There is also a built-in template rule for text and attribute nodes
\r
1920 that copies text through:</p>
\r
1922 <pre><xsl:template match="text()|@*">
\r
1923 <xsl:value-of select="."/>
\r
1924 </xsl:template></pre>
\r
1926 <p>The built-in template rule for processing instructions and comments
\r
1927 is to do nothing.</p>
\r
1929 <pre><xsl:template match="processing-instruction()|comment()"/></pre>
\r
1931 <p>The built-in template rule for namespace nodes is also to do
\r
1932 nothing. There is no pattern that can match a namespace node; so, the
\r
1933 built-in template rule is the only template rule that is applied for
\r
1934 namespace nodes.</p>
\r
1936 <p>The built-in template rules are treated as if they were imported
\r
1937 implicitly before the stylesheet and so have lower <a href="#dt-import-precedence">import precedence</a> than all other
\r
1938 template rules. Thus, the author can override a built-in template
\r
1939 rule by including an explicit template rule.</p>
\r
1948 <a name="named-templates"></a>6 Named Templates</h2>
\r
1950 <p class="element-syntax">
\r
1951 <a name="element-call-template"></a><code><!-- Category: instruction --><br><xsl:call-template<br> <b>name</b> = <var>qname</var>><br> <!-- Content: <a href="#element-with-param">xsl:with-param</a>* --><br></xsl:call-template></code>
\r
1954 <p>Templates can be invoked by name. An <code>xsl:template</code>
\r
1955 element with a <code>name</code> attribute specifies a named template.
\r
1956 The value of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>, which is expanded as described
\r
1957 in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>. If an <code>xsl:template</code> element has
\r
1958 a <code>name</code> attribute, it may, but need not, also have a
\r
1959 <code>match</code> attribute. An <code>xsl:call-template</code>
\r
1960 element invokes a template by name; it has a required
\r
1961 <code>name</code> attribute that identifies the template to be
\r
1962 invoked. Unlike <code>xsl:apply-templates</code>,
\r
1963 <code>xsl:call-template</code> does not change the current node or the
\r
1964 current node list.</p>
\r
1966 <p>The <code>match</code>, <code>mode</code> and <code>priority</code> attributes on an
\r
1967 <code>xsl:template</code> element do not affect whether the template
\r
1968 is invoked by an <code>xsl:call-template</code> element. Similarly,
\r
1969 the <code>name</code> attribute on an <code>xsl:template</code>
\r
1970 element does not affect whether the template is invoked by an
\r
1971 <code>xsl:apply-templates</code> element.</p>
\r
1973 <p>It is an error if a stylesheet contains more than one template with
\r
1974 the same name and same <a href="#dt-import-precedence">import
\r
1975 precedence</a>.</p>
\r
1982 <a name="section-Creating-the-Result-Tree"></a>7 Creating the Result Tree</h2>
\r
1984 <p>This section describes instructions that directly create nodes in
\r
1985 the result tree.</p>
\r
1989 <a name="section-Creating-Elements-and-Attributes"></a>7.1 Creating Elements and Attributes</h3>
\r
1993 <a name="literal-result-element"></a>7.1.1 Literal Result Elements</h4>
\r
1995 <p>In a template, an element in the stylesheet that does not belong to
\r
1996 the XSLT namespace and that is not an extension element (see <a href="#extension-element">[<b>14.1 Extension Elements</b>]</a>) is instantiated to create an element node
\r
1997 with the same <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a>. The content
\r
1998 of the element is a template, which is instantiated to give the
\r
1999 content of the created element node. The created element node will
\r
2000 have the attribute nodes that were present on the element node in the
\r
2001 stylesheet tree, other than attributes with names in the XSLT
\r
2004 <p>The created element node will also have a copy of the namespace
\r
2005 nodes that were present on the element node in the stylesheet tree
\r
2006 with the exception of any namespace node whose string-value is the
\r
2007 XSLT namespace URI (<code>http://www.w3.org/1999/XSL/Transform</code>), a
\r
2008 namespace URI declared as an extension namespace (see <a href="#extension-element">[<b>14.1 Extension Elements</b>]</a>), or a namespace URI designated as an
\r
2009 excluded namespace. A namespace URI is designated as an excluded
\r
2010 namespace by using an <code>exclude-result-prefixes</code> attribute
\r
2011 on an <code>xsl:stylesheet</code> element or an
\r
2012 <code>xsl:exclude-result-prefixes</code> attribute on a literal result
\r
2013 element. The value of both these attributes is a whitespace-separated
\r
2014 list of namespace prefixes. The namespace bound to each of the
\r
2015 prefixes is designated as an excluded namespace. It is an error if
\r
2016 there is no namespace bound to the prefix on the element bearing the
\r
2017 <code>exclude-result-prefixes</code> or
\r
2018 <code>xsl:exclude-result-prefixes</code> attribute. The default
\r
2019 namespace (as declared by <code>xmlns</code>) may be designated as an
\r
2020 excluded namespace by including <code>#default</code> in the list of
\r
2021 namespace prefixes. The designation of a namespace as an excluded
\r
2022 namespace is effective within the subtree of the stylesheet rooted at
\r
2023 the element bearing the <code>exclude-result-prefixes</code> or
\r
2024 <code>xsl:exclude-result-prefixes</code> attribute;
\r
2025 a subtree rooted at an <code>xsl:stylesheet</code> element
\r
2026 does not include any stylesheets imported or included by children
\r
2027 of that <code>xsl:stylesheet</code> element.</p>
\r
2030 <b>NOTE: </b>When a stylesheet uses a namespace declaration only for the
\r
2031 purposes of addressing the source tree, specifying the prefix in the
\r
2032 <code>exclude-result-prefixes</code> attribute will avoid superfluous
\r
2033 namespace declarations in the result tree.</blockquote>
\r
2035 <p>The value of an attribute of a literal result element is
\r
2036 interpreted as an <a href="#dt-attribute-value-template">attribute
\r
2037 value template</a>: it can contain expressions contained
\r
2038 in curly braces (<code>{}</code>).</p>
\r
2041 <a name="dt-literal-namespace-uri"></a>A namespace URI in the stylesheet tree that is being used to
\r
2042 specify a namespace URI in the result tree is called a <b>literal
\r
2043 namespace URI</b>. This applies to:</p>
\r
2048 <p>the namespace URI in the expanded-name of a literal
\r
2049 result element in the stylesheet</p>
\r
2053 <p>the namespace URI in the expanded-name of an attribute
\r
2054 specified on a literal result element in the stylesheet</p>
\r
2058 <p>the string-value of a namespace node on a literal result
\r
2059 element in the stylesheet</p>
\r
2064 <p class="element-syntax">
\r
2065 <a name="element-namespace-alias"></a><code><!-- Category: top-level-element --><br><xsl:namespace-alias<br> <b>stylesheet-prefix</b> = <var>prefix</var> | "#default"<br> <b>result-prefix</b> = <var>prefix</var> | "#default" /></code>
\r
2069 <a name="dt-alias"></a>A stylesheet can use the
\r
2070 <code>xsl:namespace-alias</code> element to declare that one namespace
\r
2071 URI is an <b>alias</b> for another namespace URI. When
\r
2072 a <a href="#dt-literal-namespace-uri">literal namespace
\r
2073 URI</a> has been declared to be an alias for another namespace
\r
2074 URI, then the namespace URI in the result tree will be the namespace
\r
2075 URI that the literal namespace URI is an alias for, instead of the
\r
2076 literal namespace URI itself. The <code>xsl:namespace-alias</code>
\r
2077 element declares that the namespace URI bound to the prefix specified
\r
2078 by the <code>stylesheet-prefix</code> attribute is an alias for the
\r
2079 namespace URI bound to the prefix specified by the
\r
2080 <code>result-prefix</code> attribute. Thus, the
\r
2081 <code>stylesheet-prefix</code> attribute specifies the namespace URI
\r
2082 that will appear in the stylesheet, and the
\r
2083 <code>result-prefix</code> attribute specifies the corresponding
\r
2084 namespace URI that will appear in the result tree. The default
\r
2085 namespace (as declared by <code>xmlns</code>) may be specified by
\r
2086 using <code>#default</code> instead of a prefix. If a namespace URI
\r
2087 is declared to be an alias for multiple different namespace URIs, then
\r
2088 the declaration with the highest <a href="#dt-import-precedence">import precedence</a> is used. It is
\r
2089 an error if there is more than one such declaration. An XSLT
\r
2090 processor may signal the error; if it does not signal the error, it
\r
2091 must recover by choosing, from amongst the declarations with the
\r
2092 highest import precedence, the one that occurs last in the
\r
2095 <p>When literal result elements are being used to create element,
\r
2096 attribute, or namespace nodes that use the XSLT namespace URI, the
\r
2097 stylesheet must use an alias. For example, the stylesheet</p>
\r
2099 <pre><xsl:stylesheet
\r
2101 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
\r
2102 xmlns:fo="http://www.w3.org/1999/XSL/Format"
\r
2103 xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias">
\r
2105 <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
\r
2107 <xsl:template match="/">
\r
2108 <axsl:stylesheet>
\r
2109 <xsl:apply-templates/>
\r
2110 </axsl:stylesheet>
\r
2111 </xsl:template>
\r
2113 <xsl:template match="block">
\r
2114 <axsl:template match="{.}">
\r
2115 <fo:block><axsl:apply-templates/></fo:block>
\r
2116 </axsl:template>
\r
2117 </xsl:template>
\r
2119 </xsl:stylesheet></pre>
\r
2121 <p>will generate an XSLT stylesheet from a document of the form:</p>
\r
2123 <pre><elements>
\r
2124 <block>p</block>
\r
2125 <block>h1</block>
\r
2126 <block>h2</block>
\r
2127 <block>h3</block>
\r
2128 <block>h4</block>
\r
2129 </elements></pre>
\r
2132 <b>NOTE: </b>It may be necessary also to use aliases for namespaces other
\r
2133 than the XSLT namespace URI. For example, literal result elements
\r
2134 belonging to a namespace dealing with digital signatures might cause
\r
2135 XSLT stylesheets to be mishandled by general-purpose security
\r
2136 software; using an alias for the namespace would avoid the possibility
\r
2137 of such mishandling.</blockquote>
\r
2143 <a name="section-Creating-Elements-with-xsl:element"></a>7.1.2 Creating Elements with <code>xsl:element</code>
\r
2146 <p class="element-syntax">
\r
2147 <a name="element-element"></a><code><!-- Category: instruction --><br><xsl:element<br> <b>name</b> = { <var>qname</var> }<br> namespace = { <var>uri-reference</var> }<br> use-attribute-sets = <var>qnames</var>><br> <!-- Content: <var>template</var> --><br></xsl:element></code>
\r
2150 <p>The <code>xsl:element</code> element allows an element to be
\r
2151 created with a computed name. The <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> of the
\r
2152 element to be created is specified by a required <code>name</code>
\r
2153 attribute and an optional <code>namespace</code> attribute. The
\r
2154 content of the <code>xsl:element</code> element is a template for the
\r
2155 attributes and children of the created element.</p>
\r
2157 <p>The <code>name</code> attribute is interpreted as an <a href="#dt-attribute-value-template">attribute value template</a>.
\r
2158 It is an error if the string that results from instantiating the
\r
2159 attribute value template is not a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>. An XSLT processor may signal
\r
2160 the error; if it does not signal the error, then it must recover
\r
2161 by making the the result of instantiating the <code>xsl:element</code>
\r
2162 element be the sequence of nodes created by instantiating
\r
2163 the content of the <code>xsl:element</code> element, excluding
\r
2164 any initial attribute nodes. If the <code>namespace</code> attribute is
\r
2165 not present then the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> is
\r
2166 expanded into an expanded-name using the namespace declarations in
\r
2167 effect for the <code>xsl:element</code> element, including any default
\r
2168 namespace declaration.</p>
\r
2170 <p>If the <code>namespace</code> attribute is present, then it also is
\r
2171 interpreted as an <a href="#dt-attribute-value-template">attribute
\r
2172 value template</a>. The string that results from instantiating
\r
2173 the attribute value template should be a URI reference. It is not an
\r
2174 error if the string is not a syntactically legal URI reference. If
\r
2175 the string is empty, then the expanded-name of the element has a null
\r
2176 namespace URI. Otherwise, the string is used as the namespace URI of
\r
2177 the expanded-name of the element to be created. The local part of the
\r
2178 <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> specified by the
\r
2179 <code>name</code> attribute is used as the local part of the
\r
2180 expanded-name of the element to be created.</p>
\r
2182 <p>XSLT processors may make use of the prefix of the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> specified in the
\r
2183 <code>name</code> attribute when selecting the prefix used for
\r
2184 outputting the created element as XML; however, they are not required
\r
2191 <a name="creating-attributes"></a>7.1.3 Creating Attributes with <code>xsl:attribute</code>
\r
2194 <p class="element-syntax">
\r
2195 <a name="element-attribute"></a><code><!-- Category: instruction --><br><xsl:attribute<br> <b>name</b> = { <var>qname</var> }<br> namespace = { <var>uri-reference</var> }><br> <!-- Content: <var>template</var> --><br></xsl:attribute></code>
\r
2198 <p>The <code>xsl:attribute</code> element can be used to add
\r
2199 attributes to result elements whether created by literal result
\r
2200 elements in the stylesheet or by instructions such as
\r
2201 <code>xsl:element</code>. The <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> of the
\r
2202 attribute to be created is specified by a required <code>name</code>
\r
2203 attribute and an optional <code>namespace</code> attribute.
\r
2204 Instantiating an <code>xsl:attribute</code> element adds an attribute
\r
2205 node to the containing result element node. The content of the
\r
2206 <code>xsl:attribute</code> element is a template for the value of the
\r
2207 created attribute.</p>
\r
2209 <p>The <code>name</code> attribute is interpreted as an <a href="#dt-attribute-value-template">attribute value template</a>.
\r
2210 It is an error if the string that results from instantiating the
\r
2211 attribute value template is not a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> or is the string
\r
2212 <code>xmlns</code>. An XSLT processor may signal the error; if it
\r
2213 does not signal the error, it must recover by not adding the attribute
\r
2214 to the result tree. If the <code>namespace</code> attribute is not
\r
2215 present, then the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> is
\r
2216 expanded into an expanded-name using the namespace declarations in
\r
2217 effect for the <code>xsl:attribute</code> element, <i>not</i>
\r
2218 including any default namespace declaration.</p>
\r
2220 <p>If the <code>namespace</code> attribute is present, then it also is
\r
2221 interpreted as an <a href="#dt-attribute-value-template">attribute
\r
2222 value template</a>. The string that results from instantiating
\r
2223 it should be a URI reference. It is not an error if the string is not
\r
2224 a syntactically legal URI reference. If the string is empty, then the
\r
2225 expanded-name of the attribute has a null namespace URI. Otherwise,
\r
2226 the string is used as the namespace URI of the expanded-name of the
\r
2227 attribute to be created. The local part of the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> specified by the
\r
2228 <code>name</code> attribute is used as the local part of the
\r
2229 expanded-name of the attribute to be created.</p>
\r
2231 <p>XSLT processors may make use of the prefix of the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> specified in the
\r
2232 <code>name</code> attribute when selecting the prefix used for
\r
2233 outputting the created attribute as XML; however, they are not
\r
2234 required to do so and, if the prefix is <code>xmlns</code>, they must
\r
2235 not do so. Thus, although it is not an error to do:</p>
\r
2237 <pre><xsl:attribute name="xmlns:xsl" namespace="whatever">http://www.w3.org/1999/XSL/Transform</xsl:attribute></pre>
\r
2239 <p>it will not result in a namespace declaration being output.</p>
\r
2241 <p>Adding an attribute to an element replaces any existing attribute
\r
2242 of that element with the same expanded-name.</p>
\r
2244 <p>The following are all errors:</p>
\r
2249 <p>Adding an attribute to an element after children have been
\r
2250 added to it; implementations may either signal the error or ignore the
\r
2255 <p>Adding an attribute to a node that is not an element;
\r
2256 implementations may either signal the error or ignore the
\r
2261 <p>Creating nodes other than text nodes during the
\r
2262 instantiation of the content of the <code>xsl:attribute</code>
\r
2263 element; implementations may either signal the error or ignore the
\r
2264 offending nodes.</p>
\r
2270 <b>NOTE: </b>When an <code>xsl:attribute</code> contains a text node with
\r
2271 a newline, then the XML output must contain a character reference.
\r
2274 <pre><xsl:attribute name="a">x
\r
2275 y</xsl:attribute></pre>
\r
2277 will result in the output
\r
2279 <pre>a="x&#xA;y"</pre>
\r
2281 (or with any equivalent character reference). The XML output cannot
\r
2287 This is because XML 1.0 requires newline characters in attribute
\r
2288 values to be normalized into spaces but requires character references
\r
2289 to newline characters not to be normalized. The attribute values in
\r
2290 the data model represent the attribute value after normalization. If
\r
2291 a newline occurring in an attribute value in the tree were output as a
\r
2292 newline character rather than as character reference, then the
\r
2293 attribute value in the tree created by reparsing the XML would contain
\r
2294 a space not a newline, which would mean that the tree had not been
\r
2295 output correctly.</blockquote>
\r
2302 <a name="attribute-sets"></a>7.1.4 Named Attribute Sets</h4>
\r
2304 <p class="element-syntax">
\r
2305 <a name="element-attribute-set"></a><code><!-- Category: top-level-element --><br><xsl:attribute-set<br> <b>name</b> = <var>qname</var>
\r
2306 <br> use-attribute-sets = <var>qnames</var>><br> <!-- Content: <a href="#element-attribute">xsl:attribute</a>* --><br></xsl:attribute-set></code>
\r
2309 <p>The <code>xsl:attribute-set</code> element defines a named set of
\r
2310 attributes. The <code>name</code> attribute specifies the name of the
\r
2311 attribute set. The value of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>, which is expanded as described
\r
2312 in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>. The content of the <code>xsl:attribute-set</code>
\r
2313 element consists of zero or more <code>xsl:attribute</code> elements
\r
2314 that specify the attributes in the set.</p>
\r
2316 <p>Attribute sets are used by specifying a
\r
2317 <code>use-attribute-sets</code> attribute on <code>xsl:element</code>,
\r
2318 <code>xsl:copy</code> (see <a href="#copying">[<b>7.5 Copying</b>]</a>) or
\r
2319 <code>xsl:attribute-set</code> elements. The value of the
\r
2320 <code>use-attribute-sets</code> attribute is a whitespace-separated
\r
2321 list of names of attribute sets. Each name is specified as a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>, which is expanded as described
\r
2322 in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>. Specifying a
\r
2323 <code>use-attribute-sets</code> attribute is equivalent to adding
\r
2324 <code>xsl:attribute</code> elements for each of the attributes in each
\r
2325 of the named attribute sets to the beginning of the content of the
\r
2326 element with the <code>use-attribute-sets</code> attribute, in the
\r
2327 same order in which the names of the attribute sets are specified in
\r
2328 the <code>use-attribute-sets</code> attribute. It is an error if use
\r
2329 of <code>use-attribute-sets</code> attributes on
\r
2330 <code>xsl:attribute-set</code> elements causes an attribute set to
\r
2331 directly or indirectly use itself.</p>
\r
2333 <p>Attribute sets can also be used by specifying an
\r
2334 <code>xsl:use-attribute-sets</code> attribute on a literal result
\r
2335 element. The value of the <code>xsl:use-attribute-sets</code>
\r
2336 attribute is a whitespace-separated list of names of attribute sets.
\r
2337 The <code>xsl:use-attribute-sets</code> attribute has the same effect
\r
2338 as the <code>use-attribute-sets</code> attribute on
\r
2339 <code>xsl:element</code> with the additional rule that attributes
\r
2340 specified on the literal result element itself are treated as if they
\r
2341 were specified by <code>xsl:attribute</code> elements before any
\r
2342 actual <code>xsl:attribute</code> elements but after any
\r
2343 <code>xsl:attribute</code> elements implied by the
\r
2344 <code>xsl:use-attribute-sets</code> attribute. Thus, for a literal
\r
2345 result element, attributes from attribute sets named in an
\r
2346 <code>xsl:use-attribute-sets</code> attribute will be added first, in
\r
2347 the order listed in the attribute; next, attributes specified on the
\r
2348 literal result element will be added; finally, any attributes
\r
2349 specified by <code>xsl:attribute</code> elements will be added. Since
\r
2350 adding an attribute to an element replaces any existing attribute of
\r
2351 that element with the same name, this means that attributes specified
\r
2352 in attribute sets can be overridden by attributes specified on the
\r
2353 literal result element itself.</p>
\r
2355 <p>The template within each <code>xsl:attribute</code> element in an
\r
2356 <code>xsl:attribute-set</code> element is instantiated each time the
\r
2357 attribute set is used; it is instantiated using the same current node
\r
2358 and current node list as is used for instantiating the element bearing
\r
2359 the <code>use-attribute-sets</code> or
\r
2360 <code>xsl:use-attribute-sets</code> attribute. However, it is the
\r
2361 position in the stylesheet of the <code>xsl:attribute</code> element
\r
2362 rather than of the element bearing the <code>use-attribute-sets</code>
\r
2363 or <code>xsl:use-attribute-sets</code> attribute that determines which
\r
2364 variable bindings are visible (see <a href="#variables">[<b>11 Variables and Parameters</b>]</a>); thus,
\r
2365 only variables and parameters declared by <a href="#dt-top-level">top-level</a> <code>xsl:variable</code> and
\r
2366 <code>xsl:param</code> elements are visible.</p>
\r
2368 <p>The following example creates a named attribute set
\r
2369 <code>title-style</code> and uses it in a template rule.</p>
\r
2371 <pre><xsl:template match="chapter/heading">
\r
2372 <fo:block quadding="start" xsl:use-attribute-sets="title-style">
\r
2373 <xsl:apply-templates/>
\r
2375 </xsl:template>
\r
2377 <xsl:attribute-set name="title-style">
\r
2378 <xsl:attribute name="font-size">12pt</xsl:attribute>
\r
2379 <xsl:attribute name="font-weight">bold</xsl:attribute>
\r
2380 </xsl:attribute-set></pre>
\r
2382 <p>Multiple definitions of an attribute set with the same
\r
2383 expanded-name are merged. An attribute from a definition that has
\r
2384 higher <a href="#dt-import-precedence">import precedence</a>
\r
2385 takes precedence over an attribute from a definition that has lower
\r
2386 <a href="#dt-import-precedence">import precedence</a>. It
\r
2387 is an error if there are two attribute sets that have the same
\r
2388 expanded-name and equal import precedence and that both contain
\r
2389 the same attribute, unless there is a definition of the attribute set
\r
2390 with higher <a href="#dt-import-precedence">import
\r
2391 precedence</a> that also contains the attribute. An XSLT
\r
2392 processor may signal the error; if it does not signal the error, it
\r
2393 must recover by choosing from amongst the definitions that specify the
\r
2394 attribute that have the highest import precedence the one that was
\r
2395 specified last in the stylesheet. Where the attributes in an
\r
2396 attribute set were specified is relevant only in merging the
\r
2397 attributes into the attribute set; it makes no difference when the
\r
2398 attribute set is used.</p>
\r
2407 <a name="section-Creating-Text"></a>7.2 Creating Text</h3>
\r
2409 <p>A template can also contain text nodes. Each text node in a
\r
2410 template remaining after whitespace has been stripped as specified in
\r
2411 <a href="#strip">[<b>3.4 Whitespace Stripping</b>]</a> will create a text node with the same
\r
2412 string-value in the result tree. Adjacent text nodes in the result
\r
2413 tree are automatically merged.</p>
\r
2415 <p>Note that text is processed at the tree level. Thus, markup of
\r
2416 <code>&lt;</code> in a template will be represented in the
\r
2417 stylesheet tree by a text node that includes the character
\r
2418 <code><</code>. This will create a text node in the result tree
\r
2419 that contains a <code><</code> character, which will be represented
\r
2420 by the markup <code>&lt;</code> (or an equivalent character
\r
2421 reference) when the result tree is externalized as an XML document
\r
2422 (unless output escaping is disabled as described in <a href="#disable-output-escaping">[<b>16.4 Disabling Output Escaping</b>]</a>).</p>
\r
2424 <p class="element-syntax">
\r
2425 <a name="element-text"></a><code><!-- Category: instruction --><br><xsl:text<br> disable-output-escaping = "yes" | "no"><br> <!-- Content: #PCDATA --><br></xsl:text></code>
\r
2428 <p>Literal data characters may also be wrapped in an
\r
2429 <code>xsl:text</code> element. This wrapping may change what
\r
2430 whitespace characters are stripped (see <a href="#strip">[<b>3.4 Whitespace Stripping</b>]</a>) but
\r
2431 does not affect how the characters are handled by the XSLT processor
\r
2435 <b>NOTE: </b>The <code>xml:lang</code> and <code>xml:space</code>
\r
2436 attributes are not treated specially by XSLT. In particular,
\r
2440 <p>it is the responsibility of the stylesheet author explicitly
\r
2441 to generate any <code>xml:lang</code> or <code>xml:space</code>
\r
2442 attributes that are needed in the result;</p>
\r
2446 <p>specifying an <code>xml:lang</code> or <code>xml:space</code>
\r
2447 attribute on an element in the XSLT namespace will not cause any
\r
2448 <code>xml:lang</code> or <code>xml:space</code> attributes to appear
\r
2449 in the result.</p>
\r
2459 <a name="section-Creating-Processing-Instructions"></a>7.3 Creating Processing Instructions</h3>
\r
2462 <p class="element-syntax">
\r
2463 <a name="element-processing-instruction"></a><code><!-- Category: instruction --><br><xsl:processing-instruction<br> <b>name</b> = { <var>ncname</var> }><br> <!-- Content: <var>template</var> --><br></xsl:processing-instruction></code>
\r
2466 <p>The <code>xsl:processing-instruction</code> element is instantiated
\r
2467 to create a processing instruction node. The content of the
\r
2468 <code>xsl:processing-instruction</code> element is a template for the
\r
2469 string-value of the processing instruction node. The
\r
2470 <code>xsl:processing-instruction</code> element has a required
\r
2471 <code>name</code> attribute that specifies the name of the processing
\r
2472 instruction node. The value of the <code>name</code> attribute is
\r
2473 interpreted as an <a href="#dt-attribute-value-template">attribute
\r
2474 value template</a>.</p>
\r
2476 <p>For example, this</p>
\r
2478 <pre><xsl:processing-instruction name="xml-stylesheet">href="book.css" type="text/css"</xsl:processing-instruction></pre>
\r
2480 <p>would create the processing instruction</p>
\r
2482 <pre><?xml-stylesheet href="book.css" type="text/css"?></pre>
\r
2484 <p>It is an error if the string that results from instantiating the
\r
2485 <code>name</code> attribute is not both an <a href="http://www.w3.org/TR/REC-xml-names#NT-NCName">NCName</a> and a <a href="http://www.w3.org/TR/REC-xml#NT-PITarget">PITarget</a>. An XSLT processor may signal
\r
2486 the error; if it does not signal the error, it must recover by not
\r
2487 adding the processing instruction to the result tree.</p>
\r
2490 <b>NOTE: </b>This means that <code>xsl:processing-instruction</code>
\r
2491 cannot be used to output an XML declaration. The
\r
2492 <code>xsl:output</code> element should be used instead (see <a href="#output">[<b>16 Output</b>]</a>).</blockquote>
\r
2494 <p>It is an error if instantiating the content of
\r
2495 <code>xsl:processing-instruction</code> creates nodes other than
\r
2496 text nodes. An XSLT processor may signal the error; if it does not
\r
2497 signal the error, it must recover by ignoring the offending nodes
\r
2498 together with their content.</p>
\r
2500 <p>It is an error if the result of instantiating the content of the
\r
2501 <code>xsl:processing-instruction</code> contains the string
\r
2502 <code>?></code>. An XSLT processor may signal the error; if it does
\r
2503 not signal the error, it must recover by inserting a space after any
\r
2504 occurrence of <code>?</code> that is followed by a <code>></code>.</p>
\r
2510 <a name="section-Creating-Comments"></a>7.4 Creating Comments</h3>
\r
2512 <p class="element-syntax">
\r
2513 <a name="element-comment"></a><code><!-- Category: instruction --><br><xsl:comment><br> <!-- Content: <var>template</var> --><br></xsl:comment></code>
\r
2516 <p>The <code>xsl:comment</code> element is instantiated to create a
\r
2517 comment node in the result tree. The content of the
\r
2518 <code>xsl:comment</code> element is a template for the string-value of
\r
2519 the comment node.</p>
\r
2521 <p>For example, this</p>
\r
2523 <pre><xsl:comment>This file is automatically generated. Do not edit!</xsl:comment></pre>
\r
2525 <p>would create the comment</p>
\r
2527 <pre><!--This file is automatically generated. Do not edit!--></pre>
\r
2529 <p>It is an error if instantiating the content of
\r
2530 <code>xsl:comment</code> creates nodes other than text nodes. An
\r
2531 XSLT processor may signal the error; if it does not signal the error,
\r
2532 it must recover by ignoring the offending nodes together with their
\r
2535 <p>It is an error if the result of instantiating the content of the
\r
2536 <code>xsl:comment</code> contains the string <code>--</code> or ends
\r
2537 with <code>-</code>. An XSLT processor may signal the error; if it
\r
2538 does not signal the error, it must recover by inserting a space after
\r
2539 any occurrence of <code>-</code> that is followed by another
\r
2540 <code>-</code> or that ends the comment.</p>
\r
2546 <a name="copying"></a>7.5 Copying</h3>
\r
2548 <p class="element-syntax">
\r
2549 <a name="element-copy"></a><code><!-- Category: instruction --><br><xsl:copy<br> use-attribute-sets = <var>qnames</var>><br> <!-- Content: <var>template</var> --><br></xsl:copy></code>
\r
2552 <p>The <code>xsl:copy</code> element provides an easy way of copying
\r
2553 the current node. Instantiating the <code>xsl:copy</code> element
\r
2554 creates a copy of the current node. The namespace nodes of the
\r
2555 current node are automatically copied as well, but the attributes and
\r
2556 children of the node are not automatically copied. The content of the
\r
2557 <code>xsl:copy</code> element is a template for the attributes and
\r
2558 children of the created node; the content is instantiated only for
\r
2559 nodes of types that can have attributes or children (i.e. root
\r
2560 nodes and element nodes).</p>
\r
2562 <p>The <code>xsl:copy</code> element may have a
\r
2563 <code>use-attribute-sets</code> attribute (see <a href="#attribute-sets">[<b>7.1.4 Named Attribute Sets</b>]</a>). This is used only when copying element
\r
2566 <p>The root node is treated specially because the root node of the
\r
2567 result tree is created implicitly. When the current node is the root
\r
2568 node, <code>xsl:copy</code> will not create a root node, but will just
\r
2569 use the content template.</p>
\r
2571 <p>For example, the identity transformation can be written using
\r
2572 <code>xsl:copy</code> as follows:</p>
\r
2574 <pre><xsl:template match="@*|node()">
\r
2576 <xsl:apply-templates select="@*|node()"/>
\r
2578 </xsl:template></pre>
\r
2580 <p>When the current node is an attribute, then if it would be an error
\r
2581 to use <code>xsl:attribute</code> to create an attribute with the same
\r
2582 name as the current node, then it is also an error to use
\r
2583 <code>xsl:copy</code> (see <a href="#creating-attributes">[<b>7.1.3 Creating Attributes with <code>xsl:attribute</code></b>]</a>).</p>
\r
2585 <p>The following example shows how <code>xml:lang</code> attributes
\r
2586 can be easily copied through from source to result. If a stylesheet
\r
2587 defines the following named template:</p>
\r
2589 <pre><xsl:template name="apply-templates-copy-lang">
\r
2590 <xsl:for-each select="@xml:lang">
\r
2592 </xsl:for-each>
\r
2593 <xsl:apply-templates/>
\r
2594 </xsl:template></pre>
\r
2596 <p>then it can simply do</p>
\r
2598 <pre><xsl:call-template name="apply-templates-copy-lang"/></pre>
\r
2602 <pre><xsl:apply-templates/></pre>
\r
2604 <p>when it wants to copy the <code>xml:lang</code> attribute.</p>
\r
2610 <a name="section-Computing-Generated-Text"></a>7.6 Computing Generated Text</h3>
\r
2612 <p>Within a template, the <code>xsl:value-of</code> element can be
\r
2613 used to compute generated text, for example by extracting text from
\r
2614 the source tree or by inserting the value of a variable. The
\r
2615 <code>xsl:value-of</code> element does this with an <a href="#dt-expression">expression</a> that is specified as the
\r
2616 value of the <code>select</code> attribute. Expressions can
\r
2617 also be used inside attribute values of literal result elements by
\r
2618 enclosing the expression in curly braces (<code>{}</code>).</p>
\r
2622 <a name="value-of"></a>7.6.1 Generating Text with <code>xsl:value-of</code>
\r
2625 <p class="element-syntax">
\r
2626 <a name="element-value-of"></a><code><!-- Category: instruction --><br><xsl:value-of<br> <b>select</b> = <var>string-expression</var>
\r
2627 <br> disable-output-escaping = "yes" | "no" /></code>
\r
2630 <p>The <code>xsl:value-of</code> element is instantiated to create a
\r
2631 text node in the result tree. The required <code>select</code>
\r
2632 attribute is an <a href="#dt-expression">expression</a>;
\r
2633 this expression is evaluated and the resulting object is converted to
\r
2634 a string as if by a call to the <b><a href="http://www.w3.org/TR/xpath#function-string">string</a></b>
\r
2635 function. The string specifies the string-value of the created text
\r
2636 node. If the string is empty, no text node will be created. The
\r
2637 created text node will be merged with any adjacent text nodes.</p>
\r
2639 <p>The <code>xsl:copy-of</code> element can be used to copy a node-set
\r
2640 over to the result tree without converting it to a string. See <a href="#copy-of">[<b>11.3 Using Values of Variables and Parameters with
\r
2641 <code>xsl:copy-of</code></b>]</a>.</p>
\r
2643 <p>For example, the following creates an HTML paragraph from a
\r
2644 <code>person</code> element with <code>given-name</code> and
\r
2645 <code>family-name</code> attributes. The paragraph will contain the value
\r
2646 of the <code>given-name</code> attribute of the current node followed
\r
2647 by a space and the value of the <code>family-name</code> attribute of the
\r
2650 <pre><xsl:template match="person">
\r
2652 <xsl:value-of select="@given-name"/>
\r
2653 <xsl:text> </xsl:text>
\r
2654 <xsl:value-of select="@family-name"/>
\r
2656 </xsl:template></pre>
\r
2658 <p>For another example, the following creates an HTML paragraph from a
\r
2659 <code>person</code> element with <code>given-name</code> and
\r
2660 <code>family-name</code> children elements. The paragraph will
\r
2661 contain the string-value of the first <code>given-name</code> child
\r
2662 element of the current node followed by a space and the string-value
\r
2663 of the first <code>family-name</code> child element of the current
\r
2666 <pre><xsl:template match="person">
\r
2668 <xsl:value-of select="given-name"/>
\r
2669 <xsl:text> </xsl:text>
\r
2670 <xsl:value-of select="family-name"/>
\r
2672 </xsl:template></pre>
\r
2674 <p>The following precedes each <code>procedure</code> element with a
\r
2675 paragraph containing the security level of the procedure. It assumes
\r
2676 that the security level that applies to a procedure is determined by a
\r
2677 <code>security</code> attribute on the procedure element or on an
\r
2678 ancestor element of the procedure. It also assumes that if more than
\r
2679 one such element has a <code>security</code> attribute then the
\r
2680 security level is determined by the element that is closest to the
\r
2683 <pre><xsl:template match="procedure">
\r
2685 <xsl:value-of select="ancestor-or-self::*[@security][1]/@security"/>
\r
2687 <xsl:apply-templates/>
\r
2688 </xsl:template></pre>
\r
2694 <a name="attribute-value-templates"></a>7.6.2 Attribute Value Templates</h4>
\r
2697 <a name="dt-attribute-value-template"></a>In an attribute value that is interpreted as an
\r
2698 <b>attribute value template</b>, such as an attribute of a
\r
2699 literal result element, an <a href="#dt-expression">expression</a> can be used by surrounding
\r
2700 the expression with curly braces (<code>{}</code>). The
\r
2701 attribute value template is instantiated by replacing the expression
\r
2702 together with surrounding curly braces by the result of evaluating the
\r
2703 expression and converting the resulting object to a string as if by a
\r
2704 call to the <b><a href="http://www.w3.org/TR/xpath#function-string">string</a></b> function. Curly braces are
\r
2705 not recognized in an attribute value in an XSLT stylesheet unless the
\r
2706 attribute is specifically stated to be one that is interpreted as an
\r
2707 attribute value template; in an element syntax summary, the value
\r
2708 of such attributes is surrounded by curly braces.</p>
\r
2711 <b>NOTE: </b>Not all attributes are interpreted as attribute value
\r
2712 templates. Attributes whose value is an expression or pattern,
\r
2713 attributes of <a href="#dt-top-level">top-level</a> elements
\r
2714 and attributes that refer to named XSLT objects are not interpreted as
\r
2715 attribute value templates. In addition, <code>xmlns</code> attributes
\r
2716 are not interpreted as attribute value templates; it would not be
\r
2717 conformant with the XML Namespaces Recommendation to do
\r
2718 this.</blockquote>
\r
2720 <p>The following example creates an <code>img</code> result element
\r
2721 from a <code>photograph</code> element in the source; the value of the
\r
2722 <code>src</code> attribute of the <code>img</code> element is computed
\r
2723 from the value of the <code>image-dir</code> variable and the
\r
2724 string-value of the <code>href</code> child of the
\r
2725 <code>photograph</code> element; the value of the <code>width</code>
\r
2726 attribute of the <code>img</code> element is computed from the value
\r
2727 of the <code>width</code> attribute of the <code>size</code> child of
\r
2728 the <code>photograph</code> element:</p>
\r
2730 <pre><xsl:variable name="image-dir">/images</xsl:variable>
\r
2732 <xsl:template match="photograph">
\r
2733 <img src="{$image-dir}/{href}" width="{size/@width}"/>
\r
2734 </xsl:template></pre>
\r
2736 <p>With this source</p>
\r
2738 <pre><photograph>
\r
2739 <href>headquarters.jpg</href>
\r
2740 <size width="300"/>
\r
2741 </photograph></pre>
\r
2743 <p>the result would be</p>
\r
2745 <pre><img src="/images/headquarters.jpg" width="300"/></pre>
\r
2747 <p>When an attribute value template is instantiated, a double left or
\r
2748 right curly brace outside an expression will be replaced by a single
\r
2749 curly brace. It is an error if a right curly brace occurs in an
\r
2750 attribute value template outside an expression without being followed
\r
2751 by a second right curly brace. A right curly brace inside a <a href="http://www.w3.org/TR/xpath#NT-Literal">Literal</a> in an expression is not
\r
2752 recognized as terminating the expression.</p>
\r
2754 <p>Curly braces are <i>not</i> recognized recursively inside
\r
2755 expressions. For example:</p>
\r
2757 <pre style="color: red"><a href="#{id({@ref})/title}"></pre>
\r
2759 <p>is <i>not</i> allowed. Instead, use simply:</p>
\r
2761 <pre><a href="#{id(@ref)/title}"></pre>
\r
2769 <a name="number"></a>7.7 Numbering</h3>
\r
2771 <p class="element-syntax">
\r
2772 <a name="element-number"></a><code><!-- Category: instruction --><br><xsl:number<br> level = "single" | "multiple" | "any"<br> count = <var>pattern</var>
\r
2773 <br> from = <var>pattern</var>
\r
2774 <br> value = <var>number-expression</var>
\r
2775 <br> format = { <var>string</var> }<br> lang = { <var>nmtoken</var> }<br> letter-value = { "alphabetic" | "traditional" }<br> grouping-separator = { <var>char</var> }<br> grouping-size = { <var>number</var> } /></code>
\r
2778 <p>The <code>xsl:number</code> element is used to insert a formatted
\r
2779 number into the result tree. The number to be inserted may be
\r
2780 specified by an expression. The <code>value</code> attribute contains
\r
2781 an <a href="#dt-expression">expression</a>. The expression
\r
2782 is evaluated and the resulting object is converted to a number as if
\r
2783 by a call to the <b><a href="http://www.w3.org/TR/xpath#function-number">number</a></b> function. The number is
\r
2784 rounded to an integer and then converted to a string using the
\r
2785 attributes specified in <a href="#convert">[<b>7.7.1 Number to String Conversion Attributes</b>]</a>; in this
\r
2786 context, the value of each of these attributes is
\r
2787 interpreted as an <a href="#dt-attribute-value-template">attribute
\r
2788 value template</a>. After conversion, the resulting string is
\r
2789 inserted in the result tree. For example, the following example
\r
2790 numbers a sorted list:</p>
\r
2792 <pre><xsl:template match="items">
\r
2793 <xsl:for-each select="item">
\r
2794 <xsl:sort select="."/>
\r
2796 <xsl:number value="position()" format="1. "/>
\r
2797 <xsl:value-of select="."/>
\r
2799 </xsl:for-each>
\r
2800 </xsl:template></pre>
\r
2802 <p>If no <code>value</code> attribute is specified, then the
\r
2803 <code>xsl:number</code> element inserts a number based on the position
\r
2804 of the current node in the source tree. The following attributes
\r
2805 control how the current node is to be numbered:</p>
\r
2810 <p>The <code>level</code> attribute specifies what levels of the
\r
2811 source tree should be considered; it has the values
\r
2812 <code>single</code>, <code>multiple</code> or <code>any</code>. The
\r
2813 default is <code>single</code>.</p>
\r
2817 <p>The <code>count</code> attribute is a pattern that specifies
\r
2818 what nodes should be counted at those levels. If <code>count</code>
\r
2819 attribute is not specified, then it defaults to the pattern that
\r
2820 matches any node with the same node type as the current node and, if
\r
2821 the current node has an expanded-name, with the same expanded-name as
\r
2822 the current node.</p>
\r
2826 <p>The <code>from</code> attribute is a pattern that specifies
\r
2827 where counting starts.</p>
\r
2832 <p>In addition, the attributes specified in <a href="#convert">[<b>7.7.1 Number to String Conversion Attributes</b>]</a>
\r
2833 are used for number to string conversion, as in the case when the
\r
2834 <code>value</code> attribute is specified.</p>
\r
2836 <p>The <code>xsl:number</code> element first constructs a list of
\r
2837 positive integers using the <code>level</code>, <code>count</code> and
\r
2838 <code>from</code> attributes:</p>
\r
2843 <p>When <code>level="single"</code>, it goes up to the first
\r
2844 node in the ancestor-or-self axis that matches
\r
2845 the <code>count</code> pattern, and constructs a list of length one
\r
2846 containing one plus the number of preceding siblings of that ancestor
\r
2847 that match the <code>count</code> pattern. If there is no such
\r
2848 ancestor, it constructs an empty list. If the <code>from</code>
\r
2849 attribute is specified, then the only ancestors that are searched are
\r
2850 those that are descendants of the nearest ancestor that matches the
\r
2851 <code>from</code> pattern. Preceding siblings has the same meaning
\r
2852 here as with the <code>preceding-sibling</code> axis.</p>
\r
2856 <p>When <code>level="multiple"</code>, it constructs a list of all
\r
2857 ancestors of the current node in document order followed by the
\r
2858 element itself; it then selects from the list those nodes that match
\r
2859 the <code>count</code> pattern; it then maps each node in the list to
\r
2860 one plus the number of preceding siblings of that node that match the
\r
2861 <code>count</code> pattern. If the <code>from</code> attribute is
\r
2862 specified, then the only ancestors that are searched are those that
\r
2863 are descendants of the nearest ancestor that matches the
\r
2864 <code>from</code> pattern. Preceding siblings has the same meaning
\r
2865 here as with the <code>preceding-sibling</code> axis.</p>
\r
2869 <p>When <code>level="any"</code>, it constructs a list of length
\r
2870 one containing the number of nodes that match the <code>count</code>
\r
2871 pattern and belong to the set containing the current node and all
\r
2872 nodes at any level of the document that are before the current node in
\r
2873 document order, excluding any namespace and attribute nodes (in other
\r
2874 words the union of the members of the <code>preceding</code> and
\r
2875 <code>ancestor-or-self</code> axes). If the <code>from</code>
\r
2876 attribute is specified, then only nodes after the first node before
\r
2877 the current node that match the <code>from</code> pattern are
\r
2883 <p>The list of numbers is then converted into a string using the
\r
2884 attributes specified in <a href="#convert">[<b>7.7.1 Number to String Conversion Attributes</b>]</a>; in this
\r
2885 context, the value of each of these attributes is
\r
2886 interpreted as an <a href="#dt-attribute-value-template">attribute
\r
2887 value template</a>. After conversion, the resulting string is
\r
2888 inserted in the result tree.</p>
\r
2890 <p>The following would number the items in an ordered list:</p>
\r
2892 <pre><xsl:template match="ol/item">
\r
2894 <xsl:number/><xsl:text>. </xsl:text><xsl:apply-templates/>
\r
2896 <xsl:template></pre>
\r
2898 <p>The following two rules would number <code>title</code> elements.
\r
2899 This is intended for a document that contains a sequence of chapters
\r
2900 followed by a sequence of appendices, where both chapters and
\r
2901 appendices contain sections, which in turn contain subsections.
\r
2902 Chapters are numbered 1, 2, 3; appendices are numbered A, B, C;
\r
2903 sections in chapters are numbered 1.1, 1.2, 1.3; sections in
\r
2904 appendices are numbered A.1, A.2, A.3.</p>
\r
2906 <pre><xsl:template match="title">
\r
2908 <xsl:number level="multiple"
\r
2909 count="chapter|section|subsection"
\r
2910 format="1.1 "/>
\r
2911 <xsl:apply-templates/>
\r
2913 </xsl:template>
\r
2915 <xsl:template match="appendix//title" priority="1">
\r
2917 <xsl:number level="multiple"
\r
2918 count="appendix|section|subsection"
\r
2919 format="A.1 "/>
\r
2920 <xsl:apply-templates/>
\r
2922 </xsl:template></pre>
\r
2924 <p>The following example numbers notes sequentially within a
\r
2927 <pre><xsl:template match="note">
\r
2929 <xsl:number level="any" from="chapter" format="(1) "/>
\r
2930 <xsl:apply-templates/>
\r
2932 </xsl:template></pre>
\r
2934 <p>The following example would number <code>H4</code> elements in HTML
\r
2935 with a three-part label:</p>
\r
2937 <pre><xsl:template match="H4">
\r
2939 <xsl:number level="any" from="H1" count="H2"/>
\r
2940 <xsl:text>.</xsl:text>
\r
2941 <xsl:number level="any" from="H2" count="H3"/>
\r
2942 <xsl:text>.</xsl:text>
\r
2943 <xsl:number level="any" from="H3" count="H4"/>
\r
2944 <xsl:text> </xsl:text>
\r
2945 <xsl:apply-templates/>
\r
2947 </xsl:template></pre>
\r
2951 <a name="convert"></a>7.7.1 Number to String Conversion Attributes</h4>
\r
2953 <p>The following attributes are used to control conversion of a list
\r
2954 of numbers into a string. The numbers are integers greater than
\r
2955 0. The attributes are all optional.</p>
\r
2957 <p>The main attribute is <code>format</code>. The default value for
\r
2958 the <code>format</code> attribute is <code>1</code>. The
\r
2959 <code>format</code> attribute is split into a sequence of tokens where
\r
2960 each token is a maximal sequence of alphanumeric characters or a
\r
2961 maximal sequence of non-alphanumeric characters. Alphanumeric means
\r
2962 any character that has a Unicode category of Nd, Nl, No, Lu, Ll, Lt,
\r
2963 Lm or Lo. The alphanumeric tokens (format tokens) specify the format
\r
2964 to be used for each number in the list. If the first token is a
\r
2965 non-alphanumeric token, then the constructed string will start with
\r
2966 that token; if the last token is non-alphanumeric token, then the
\r
2967 constructed string will end with that token. Non-alphanumeric tokens
\r
2968 that occur between two format tokens are separator tokens that are
\r
2969 used to join numbers in the list. The <var>n</var>th format token
\r
2970 will be used to format the <var>n</var>th number in the list. If
\r
2971 there are more numbers than format tokens, then the last format token
\r
2972 will be used to format remaining numbers. If there are no format
\r
2973 tokens, then a format token of <code>1</code> is used to format all
\r
2974 numbers. The format token specifies the string to be used to
\r
2975 represent the number 1. Each number after the first will be separated
\r
2976 from the preceding number by the separator token preceding the format
\r
2977 token used to format that number, or, if there are no separator
\r
2978 tokens, then by <code>.</code> (a period character).</p>
\r
2980 <p>Format tokens are a superset of the allowed values for the
\r
2981 <code>type</code> attribute for the <code>OL</code> element in HTML
\r
2982 4.0 and are interpreted as follows:</p>
\r
2987 <p>Any token where the last character has a decimal digit value
\r
2988 of 1 (as specified in the Unicode character property database),
\r
2989 and the Unicode value of preceding characters is one less than the
\r
2990 Unicode value of the last character generates a decimal
\r
2991 representation of the number where each number is at least as long as
\r
2992 the format token. Thus, a format token <code>1</code> generates the
\r
2993 sequence <code>1 2 ... 10 11 12 ...</code>, and a format token
\r
2994 <code>01</code> generates the sequence <code>01 02 ... 09 10 11 12
\r
2995 ... 99 100 101</code>.</p>
\r
2999 <p>A format token <code>A</code> generates the sequence <code>A
\r
3000 B C ... Z AA AB AC...</code>.</p>
\r
3004 <p>A format token <code>a</code> generates the sequence <code>a
\r
3005 b c ... z aa ab ac...</code>.</p>
\r
3009 <p>A format token <code>i</code> generates the sequence <code>i
\r
3010 ii iii iv v vi vii viii ix x ...</code>.</p>
\r
3014 <p>A format token <code>I</code> generates the sequence <code>I
\r
3015 II III IV V VI VII VIII IX X ...</code>.</p>
\r
3019 <p>Any other format token indicates a numbering sequence that
\r
3020 starts with that token. If an implementation does not support a
\r
3021 numbering sequence that starts with that token, it must use a format
\r
3022 token of <code>1</code>.</p>
\r
3027 <p>When numbering with an alphabetic sequence, the <code>lang</code>
\r
3028 attribute specifies which language's alphabet is to be used; it has
\r
3029 the same range of values as <code>xml:lang</code> <a href="#XML">[XML]</a>;
\r
3030 if no <code>lang</code> value is specified, the language should be
\r
3031 determined from the system environment. Implementers should document
\r
3032 for which languages they support numbering.</p>
\r
3035 <b>NOTE: </b>Implementers should not make any assumptions about how
\r
3036 numbering works in particular languages and should properly research
\r
3037 the languages that they wish to support. The numbering conventions of
\r
3038 many languages are very different from English.</blockquote>
\r
3040 <p>The <code>letter-value</code> attribute disambiguates between
\r
3041 numbering sequences that use letters. In many languages there are two
\r
3042 commonly used numbering sequences that use letters. One numbering
\r
3043 sequence assigns numeric values to letters in alphabetic sequence, and
\r
3044 the other assigns numeric values to each letter in some other manner
\r
3045 traditional in that language. In English, these would correspond to
\r
3046 the numbering sequences specified by the format tokens <code>a</code>
\r
3047 and <code>i</code>. In some languages, the first member of each
\r
3048 sequence is the same, and so the format token alone would be
\r
3049 ambiguous. A value of <code>alphabetic</code> specifies the
\r
3050 alphabetic sequence; a value of <code>traditional</code> specifies the
\r
3051 other sequence. If the <code>letter-value</code> attribute is not
\r
3052 specified, then it is implementation-dependent how any ambiguity is
\r
3056 <b>NOTE: </b>It is possible for two conforming XSLT processors not to
\r
3057 convert a number to exactly the same string. Some XSLT processors may not
\r
3058 support some languages. Furthermore, there may be variations possible
\r
3059 in the way conversions are performed for any particular language that
\r
3060 are not specifiable by the attributes on <code>xsl:number</code>.
\r
3061 Future versions of XSLT may provide additional attributes to provide
\r
3062 control over these variations. Implementations may also use
\r
3063 implementation-specific namespaced attributes on
\r
3064 <code>xsl:number</code> for this.</blockquote>
\r
3066 <p>The <code>grouping-separator</code> attribute gives the separator
\r
3067 used as a grouping (e.g. thousands) separator in decimal numbering
\r
3068 sequences, and the optional <code>grouping-size</code> specifies the
\r
3069 size (normally 3) of the grouping. For example,
\r
3070 <code>grouping-separator=","</code> and <code>grouping-size="3"</code>
\r
3071 would produce numbers of the form <code>1,000,000</code>. If only one
\r
3072 of the <code>grouping-separator</code> and <code>grouping-size</code>
\r
3073 attributes is specified, then it is ignored.</p>
\r
3075 <p>Here are some examples of conversion specifications:</p>
\r
3081 <code>format="&#x30A2;"</code> specifies Katakana
\r
3087 <code>format="&#x30A4;"</code> specifies Katakana
\r
3088 numbering in the "iroha" order</p>
\r
3093 <code>format="&#x0E51;"</code> specifies numbering with
\r
3099 <code>format="&#x05D0;" letter-value="traditional"</code>
\r
3100 specifies "traditional" Hebrew numbering</p>
\r
3105 <code>format="&#x10D0;" letter-value="traditional"</code>
\r
3106 specifies Georgian numbering</p>
\r
3111 <code>format="&#x03B1;" letter-value="traditional"</code>
\r
3112 specifies "classical" Greek numbering</p>
\r
3117 <code>format="&#x0430;" letter-value="traditional"</code>
\r
3118 specifies Old Slavic numbering</p>
\r
3130 <a name="for-each"></a>8 Repetition</h2>
\r
3132 <p class="element-syntax">
\r
3133 <a name="element-for-each"></a><code><!-- Category: instruction --><br><xsl:for-each<br> <b>select</b> = <var>node-set-expression</var>><br> <!-- Content: (<a href="#element-sort">xsl:sort</a>*, <var>template</var>) --><br></xsl:for-each></code>
\r
3136 <p>When the result has a known regular structure, it is useful to be
\r
3137 able to specify directly the template for selected nodes. The
\r
3138 <code>xsl:for-each</code> instruction contains a template, which is
\r
3139 instantiated for each node selected by the <a href="#dt-expression">expression</a> specified by the
\r
3140 <code>select</code> attribute. The <code>select</code> attribute is
\r
3141 required. The expression must evaluate to a node-set. The template
\r
3142 is instantiated with the selected node as the <a href="#dt-current-node">current node</a>, and with a list of all
\r
3143 of the selected nodes as the <a href="#dt-current-node-list">current node list</a>. The nodes are
\r
3144 processed in document order, unless a sorting specification is present
\r
3145 (see <a href="#sorting">[<b>10 Sorting</b>]</a>).</p>
\r
3147 <p>For example, given an XML document with this structure</p>
\r
3149 <pre><customers>
\r
3151 <name>...</name>
\r
3152 <order>...</order>
\r
3153 <order>...</order>
\r
3156 <name>...</name>
\r
3157 <order>...</order>
\r
3158 <order>...</order>
\r
3160 </customers></pre>
\r
3162 <p>the following would create an HTML document containing a table with
\r
3163 a row for each <code>customer</code> element</p>
\r
3165 <pre><xsl:template match="/">
\r
3168 <title>Customers</title>
\r
3173 <xsl:for-each select="customers/customer">
\r
3176 <xsl:apply-templates select="name"/>
\r
3178 <xsl:for-each select="order">
\r
3180 <xsl:apply-templates/>
\r
3182 </xsl:for-each>
\r
3184 </xsl:for-each>
\r
3189 </xsl:template></pre>
\r
3195 <a name="section-Conditional-Processing"></a>9 Conditional Processing</h2>
\r
3197 <p>There are two instructions in XSLT that support conditional
\r
3198 processing in a template: <code>xsl:if</code> and
\r
3199 <code>xsl:choose</code>. The <code>xsl:if</code> instruction provides
\r
3200 simple if-then conditionality; the <code>xsl:choose</code> instruction
\r
3201 supports selection of one choice when there are several
\r
3202 possibilities.</p>
\r
3206 <a name="section-Conditional-Processing-with-xsl:if"></a>9.1 Conditional Processing with <code>xsl:if</code>
\r
3209 <p class="element-syntax">
\r
3210 <a name="element-if"></a><code><!-- Category: instruction --><br><xsl:if<br> <b>test</b> = <var>boolean-expression</var>><br> <!-- Content: <var>template</var> --><br></xsl:if></code>
\r
3213 <p>The <code>xsl:if</code> element has a <code>test</code> attribute,
\r
3214 which specifies an <a href="#dt-expression">expression</a>.
\r
3215 The content is a template. The expression is evaluated and the
\r
3216 resulting object is converted to a boolean as if by a call to the
\r
3217 <b><a href="http://www.w3.org/TR/xpath#function-boolean">boolean</a></b> function. If the result is true, then
\r
3218 the content template is instantiated; otherwise, nothing is created.
\r
3219 In the following example, the names in a group of names are formatted
\r
3220 as a comma separated list:</p>
\r
3222 <pre><xsl:template match="namelist/name">
\r
3223 <xsl:apply-templates/>
\r
3224 <xsl:if test="not(position()=last())">, </xsl:if>
\r
3225 </xsl:template></pre>
\r
3227 <p>The following colors every other table row yellow:</p>
\r
3229 <pre><xsl:template match="item">
\r
3231 <xsl:if test="position() mod 2 = 0">
\r
3232 <xsl:attribute name="bgcolor">yellow</xsl:attribute>
\r
3234 <xsl:apply-templates/>
\r
3236 </xsl:template></pre>
\r
3243 <a name="section-Conditional-Processing-with-xsl:choose"></a>9.2 Conditional Processing with <code>xsl:choose</code>
\r
3246 <p class="element-syntax">
\r
3247 <a name="element-choose"></a><code><!-- Category: instruction --><br><xsl:choose><br> <!-- Content: (<a href="#element-when">xsl:when</a>+, <a href="#element-otherwise">xsl:otherwise</a>?) --><br></xsl:choose></code>
\r
3250 <p class="element-syntax">
\r
3251 <a name="element-when"></a><code><xsl:when<br> <b>test</b> = <var>boolean-expression</var>><br> <!-- Content: <var>template</var> --><br></xsl:when></code>
\r
3254 <p class="element-syntax">
\r
3255 <a name="element-otherwise"></a><code><xsl:otherwise><br> <!-- Content: <var>template</var> --><br></xsl:otherwise></code>
\r
3258 <p>The <code>xsl:choose</code> element selects one among a number of
\r
3259 possible alternatives. It consists of a sequence of
\r
3260 <code>xsl:when</code> elements followed by an optional
\r
3261 <code>xsl:otherwise</code> element. Each <code>xsl:when</code>
\r
3262 element has a single attribute, <code>test</code>, which specifies an
\r
3263 <a href="#dt-expression">expression</a>. The content of the
\r
3264 <code>xsl:when</code> and <code>xsl:otherwise</code> elements is a
\r
3265 template. When an <code>xsl:choose</code> element is processed, each
\r
3266 of the <code>xsl:when</code> elements is tested in turn, by evaluating
\r
3267 the expression and converting the resulting object to a boolean as if
\r
3268 by a call to the <b><a href="http://www.w3.org/TR/xpath#function-boolean">boolean</a></b> function. The content
\r
3269 of the first, and only the first, <code>xsl:when</code> element whose
\r
3270 test is true is instantiated. If no <code>xsl:when</code> is true,
\r
3271 the content of the <code>xsl:otherwise</code> element is
\r
3272 instantiated. If no <code>xsl:when</code> element is true, and no
\r
3273 <code>xsl:otherwise</code> element is present, nothing is created.</p>
\r
3275 <p>The following example enumerates items in an ordered list using
\r
3276 arabic numerals, letters, or roman numerals depending on the depth to
\r
3277 which the ordered lists are nested.</p>
\r
3279 <pre><xsl:template match="orderedlist/listitem">
\r
3280 <fo:list-item indent-start='2pi'>
\r
3281 <fo:list-item-label>
\r
3282 <xsl:variable name="level"
\r
3283 select="count(ancestor::orderedlist) mod 3"/>
\r
3284 <xsl:choose>
\r
3285 <xsl:when test='$level=1'>
\r
3286 <xsl:number format="i"/>
\r
3288 <xsl:when test='$level=2'>
\r
3289 <xsl:number format="a"/>
\r
3291 <xsl:otherwise>
\r
3292 <xsl:number format="1"/>
\r
3293 </xsl:otherwise>
\r
3294 </xsl:choose>
\r
3295 <xsl:text>. </xsl:text>
\r
3296 </fo:list-item-label>
\r
3297 <fo:list-item-body>
\r
3298 <xsl:apply-templates/>
\r
3299 </fo:list-item-body>
\r
3300 </fo:list-item>
\r
3301 </xsl:template></pre>
\r
3308 <a name="sorting"></a>10 Sorting</h2>
\r
3310 <p class="element-syntax">
\r
3311 <a name="element-sort"></a><code><xsl:sort<br> select = <var>string-expression</var>
\r
3312 <br> lang = { <var>nmtoken</var> }<br> data-type = { "text" | "number" | <var>qname-but-not-ncname</var> }<br> order = { "ascending" | "descending" }<br> case-order = { "upper-first" | "lower-first" } /></code>
\r
3315 <p>Sorting is specified by adding <code>xsl:sort</code> elements as
\r
3316 children of an <code>xsl:apply-templates</code> or
\r
3317 <code>xsl:for-each</code> element. The first <code>xsl:sort</code>
\r
3318 child specifies the primary sort key, the second <code>xsl:sort</code>
\r
3319 child specifies the secondary sort key and so on. When an
\r
3320 <code>xsl:apply-templates</code> or <code>xsl:for-each</code> element
\r
3321 has one or more <code>xsl:sort</code> children, then instead of
\r
3322 processing the selected nodes in document order, it sorts the nodes
\r
3323 according to the specified sort keys and then processes them in sorted
\r
3324 order. When used in <code>xsl:for-each</code>, <code>xsl:sort</code>
\r
3325 elements must occur first. When a template is instantiated by
\r
3326 <code>xsl:apply-templates</code> and <code>xsl:for-each</code>, the
\r
3327 <a href="#dt-current-node-list">current node list</a> list
\r
3328 consists of the complete list of nodes being processed in sorted
\r
3332 <code>xsl:sort</code> has a <code>select</code> attribute whose
\r
3333 value is an <a href="#dt-expression">expression</a>. For
\r
3334 each node to be processed, the expression is evaluated with that node
\r
3335 as the current node and with the complete list of nodes being
\r
3336 processed in unsorted order as the current node list.
\r
3337 The resulting object is converted to a string as
\r
3338 if by a call to the <b><a href="http://www.w3.org/TR/xpath#function-string">string</a></b> function; this string
\r
3339 is used as the sort key for that node. The default value of the
\r
3340 <code>select</code> attribute is <code>.</code>, which will cause the
\r
3341 string-value of the current node to be used as the sort key.</p>
\r
3343 <p>This string serves as a sort key for the node. The following
\r
3344 optional attributes on <code>xsl:sort</code> control how the list of
\r
3345 sort keys are sorted; the values of all of these attributes are
\r
3346 interpreted as <a href="#dt-attribute-value-template">attribute
\r
3347 value templates</a>.</p>
\r
3353 <code>order</code> specifies whether the strings should be
\r
3354 sorted in ascending or descending order; <code>ascending</code>
\r
3355 specifies ascending order; <code>descending</code> specifies
\r
3356 descending order; the default is <code>ascending</code>
\r
3362 <code>lang</code> specifies the language of the sort keys; it
\r
3363 has the same range of values as <code>xml:lang</code> <a href="#XML">[XML]</a>; if no <code>lang</code> value is specified, the language
\r
3364 should be determined from the system environment</p>
\r
3369 <code>data-type</code> specifies the data type of the
\r
3370 strings; the following values are allowed:</p>
\r
3376 <code>text</code> specifies that the sort keys should be
\r
3377 sorted lexicographically in the culturally correct manner for the
\r
3378 language specified by <code>lang</code>
\r
3384 <code>number</code> specifies that the sort keys should be
\r
3385 converted to numbers and then sorted according to the numeric value;
\r
3386 the sort key is converted to a number as if by a call to the
\r
3387 <b><a href="http://www.w3.org/TR/xpath#function-number">number</a></b> function; the <code>lang</code>
\r
3388 attribute is ignored</p>
\r
3392 <p>a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> with a prefix
\r
3393 is expanded into an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> as described
\r
3394 in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>; the expanded-name identifies the data-type;
\r
3395 the behavior in this case is not specified by this document</p>
\r
3400 <p>The default value is <code>text</code>.</p>
\r
3403 <b>NOTE: </b>The XSL Working Group plans that future versions of XSLT will
\r
3404 leverage XML Schemas to define further values for this
\r
3405 attribute.</blockquote>
\r
3411 <code>case-order</code> has the value
\r
3412 <code>upper-first</code> or <code>lower-first</code>; this applies
\r
3413 when <code>data-type="text"</code>, and specifies that upper-case
\r
3414 letters should sort before lower-case letters or vice-versa
\r
3415 respectively. For example, if <code>lang="en"</code>, then <code>A a B
\r
3416 b</code> are sorted with <code>case-order="upper-first"</code> and
\r
3417 <code>a A b B</code> are sorted with
\r
3418 <code>case-order="lower-first"</code>. The default value is language
\r
3425 <b>NOTE: </b>It is possible for two conforming XSLT processors not to sort
\r
3426 exactly the same. Some XSLT processors may not support some
\r
3427 languages. Furthermore, there may be variations possible in the
\r
3428 sorting of any particular language that are not specified by the
\r
3429 attributes on <code>xsl:sort</code>, for example, whether Hiragana or
\r
3430 Katakana is sorted first in Japanese. Future versions of XSLT may
\r
3431 provide additional attributes to provide control over these
\r
3432 variations. Implementations may also use implementation-specific
\r
3433 namespaced attributes on <code>xsl:sort</code> for this.</blockquote>
\r
3436 <b>NOTE: </b>It is recommended that implementers consult <a href="#UNICODE-TR10">[UNICODE TR10]</a> for information on internationalized
\r
3437 sorting.</blockquote>
\r
3439 <p>The sort must be stable: in the sorted list of nodes, any sub list
\r
3440 that has sort keys that all compare equal must be in document
\r
3443 <p>For example, suppose an employee database has the form</p>
\r
3445 <pre><employees>
\r
3448 <given>James</given>
\r
3449 <family>Clark</family>
\r
3453 </employees>
\r
3456 <p>Then a list of employees sorted by name could be generated
\r
3459 <pre><xsl:template match="employees">
\r
3461 <xsl:apply-templates select="employee">
\r
3462 <xsl:sort select="name/family"/>
\r
3463 <xsl:sort select="name/given"/>
\r
3464 </xsl:apply-templates>
\r
3466 </xsl:template>
\r
3468 <xsl:template match="employee">
\r
3470 <xsl:value-of select="name/given"/>
\r
3471 <xsl:text> </xsl:text>
\r
3472 <xsl:value-of select="name/family"/>
\r
3474 </xsl:template></pre>
\r
3480 <a name="variables"></a>11 Variables and Parameters</h2>
\r
3482 <p class="element-syntax">
\r
3483 <a name="element-variable"></a><code><!-- Category: top-level-element --><br><!-- Category: instruction --><br><xsl:variable<br> <b>name</b> = <var>qname</var>
\r
3484 <br> select = <var>expression</var>><br> <!-- Content: <var>template</var> --><br></xsl:variable></code>
\r
3487 <p class="element-syntax">
\r
3488 <a name="element-param"></a><code><!-- Category: top-level-element --><br><xsl:param<br> <b>name</b> = <var>qname</var>
\r
3489 <br> select = <var>expression</var>><br> <!-- Content: <var>template</var> --><br></xsl:param></code>
\r
3492 <p>A variable is a name that may be bound to a value. The value to
\r
3493 which a variable is bound (the <b>value</b> of the variable) can
\r
3494 be an object of any of the types that can be returned by expressions.
\r
3495 There are two elements that can be used to bind variables:
\r
3496 <code>xsl:variable</code> and <code>xsl:param</code>. The difference
\r
3497 is that the value specified on the <code>xsl:param</code> variable is
\r
3498 only a default value for the binding; when the template or stylesheet
\r
3499 within which the <code>xsl:param</code> element occurs is invoked,
\r
3500 parameters may be passed that are used in place of the default
\r
3503 <p>Both <code>xsl:variable</code> and <code>xsl:param</code> have a
\r
3504 required <code>name</code> attribute, which specifies the name of the
\r
3505 variable. The value of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>, which is expanded as described
\r
3506 in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>.</p>
\r
3508 <p>For any use of these variable-binding elements, there is a region
\r
3509 of the stylesheet tree within which the binding is visible; within
\r
3510 this region, any binding of the variable that was visible on the
\r
3511 variable-binding element itself is hidden. Thus, only the innermost
\r
3512 binding of a variable is visible. The set of variable bindings in
\r
3513 scope for an expression consists of those bindings that are visible at
\r
3514 the point in the stylesheet where the expression occurs.</p>
\r
3518 <a name="section-Result-Tree-Fragments"></a>11.1 Result Tree Fragments</h3>
\r
3520 <p>Variables introduce an additional data-type into the expression
\r
3521 language. <a name="dt-result-tree-fragment"></a>This additional data type is called <b>result tree
\r
3522 fragment</b>. A variable may be bound to a result tree fragment
\r
3523 instead of one of the four basic XPath data-types (string, number,
\r
3524 boolean, node-set). A result tree fragment represents a fragment of
\r
3525 the result tree. A result tree fragment is treated equivalently to a
\r
3526 node-set that contains just a single root node. However, the
\r
3527 operations permitted on a result tree fragment are a subset of those
\r
3528 permitted on a node-set. An operation is permitted on a result tree
\r
3529 fragment only if that operation would be permitted on a string (the
\r
3530 operation on the string may involve first converting the string to a
\r
3531 number or boolean). In particular, it is not permitted to use the
\r
3532 <code>/</code>, <code>//</code>, and <code>[]</code> operators on
\r
3533 result tree fragments. When a permitted operation is performed on a
\r
3534 result tree fragment, it is performed exactly as it would be on the
\r
3535 equivalent node-set.</p>
\r
3537 <p>When a result tree fragment is copied into the result tree (see
\r
3538 <a href="#copy-of">[<b>11.3 Using Values of Variables and Parameters with
\r
3539 <code>xsl:copy-of</code></b>]</a>), then all the nodes that are children of the
\r
3540 root node in the equivalent node-set are added in sequence to the
\r
3543 <p>Expressions can only return values of type result tree fragment by
\r
3544 referencing variables of type result tree fragment or calling
\r
3545 extension functions that return a result tree fragment or getting a
\r
3546 system property whose value is a result tree fragment.</p>
\r
3552 <a name="variable-values"></a>11.2 Values of Variables and Parameters</h3>
\r
3554 <p>A variable-binding element can specify the value of the variable in
\r
3555 three alternative ways.</p>
\r
3560 <p>If the variable-binding element has a <code>select</code>
\r
3561 attribute, then the value of the attribute must be an <a href="#dt-expression">expression</a> and the value of the variable
\r
3562 is the object that results from evaluating the expression. In this
\r
3563 case, the content must be empty.</p>
\r
3568 <p>If the variable-binding element does not have a <code>select</code>
\r
3569 attribute and has non-empty content (i.e. the variable-binding element
\r
3570 has one or more child nodes), then the content of the
\r
3571 variable-binding element specifies the value. The content of the
\r
3572 variable-binding element is a template, which is instantiated to give
\r
3573 the value of the variable. The value is a result tree fragment
\r
3574 equivalent to a node-set containing just a single root node having as
\r
3575 children the sequence of nodes produced by instantiating the template.
\r
3576 The base URI of the nodes in the result tree fragment is the base URI
\r
3577 of the variable-binding element.</p>
\r
3579 <p>It is an error if a member of the sequence of nodes created by
\r
3580 instantiating the template is an attribute node or a namespace node,
\r
3581 since a root node cannot have an attribute node or a namespace node as
\r
3582 a child. An XSLT processor may signal the error; if it does not signal
\r
3583 the error, it must recover by not adding the attribute node or
\r
3584 namespace node.</p>
\r
3590 <p>If the variable-binding element has empty content and does not have
\r
3591 a <code>select</code> attribute, then the value of the variable is an
\r
3592 empty string. Thus</p>
\r
3594 <pre><xsl:variable name="x"/></pre>
\r
3596 <p>is equivalent to</p>
\r
3598 <pre><xsl:variable name="x" select="''"/></pre>
\r
3605 <b>NOTE: </b>When a variable is used to select nodes by position, be careful
\r
3608 <pre><xsl:variable name="n">2</xsl:variable>
\r
3610 <xsl:value-of select="item[$n]"/></pre>
\r
3612 This will output the value of the first item element, because the
\r
3613 variable <code>n</code> will be bound to a result tree fragment, not a
\r
3614 number. Instead, do either
\r
3616 <pre><xsl:variable name="n" select="2"/>
\r
3618 <xsl:value-of select="item[$n]"/></pre>
\r
3622 <pre><xsl:variable name="n">2</xsl:variable>
\r
3624 <xsl:value-of select="item[position()=$n]"/></pre>
\r
3628 <b>NOTE: </b>One convenient way to specify the empty node-set as the default
\r
3629 value of a parameter is:
\r
3631 <pre><xsl:param name="x" select="/.."/></pre>
\r
3638 <a name="copy-of"></a>11.3 Using Values of Variables and Parameters with
\r
3639 <code>xsl:copy-of</code>
\r
3642 <p class="element-syntax">
\r
3643 <a name="element-copy-of"></a><code><!-- Category: instruction --><br><xsl:copy-of<br> <b>select</b> = <var>expression</var> /></code>
\r
3646 <p>The <code>xsl:copy-of</code> element can be used to insert a result
\r
3647 tree fragment into the result tree, without first converting it to a
\r
3648 string as <code>xsl:value-of</code> does (see <a href="#value-of">[<b>7.6.1 Generating Text with <code>xsl:value-of</code></b>]</a>). The required <code>select</code> attribute
\r
3649 contains an <a href="#dt-expression">expression</a>. When
\r
3650 the result of evaluating the expression is a result tree fragment, the
\r
3651 complete fragment is copied into the result tree. When the result is
\r
3652 a node-set, all the nodes in the set are copied in document order into
\r
3653 the result tree; copying an element node copies the attribute nodes,
\r
3654 namespace nodes and children of the element node as well as the
\r
3655 element node itself; a root node is copied by copying its children.
\r
3656 When the result is neither a node-set nor a result tree fragment, the
\r
3657 result is converted to a string and then inserted into the result
\r
3658 tree, as with <code>xsl:value-of</code>.</p>
\r
3664 <a name="top-level-variables"></a>11.4 Top-level Variables and Parameters</h3>
\r
3666 <p>Both <code>xsl:variable</code> and <code>xsl:param</code> are
\r
3667 allowed as <a href="#dt-top-level">top-level</a> elements.
\r
3668 A top-level variable-binding element declares a global variable that
\r
3669 is visible everywhere. A top-level <code>xsl:param</code> element
\r
3670 declares a parameter to the stylesheet; XSLT does not define the
\r
3671 mechanism by which parameters are passed to the stylesheet. It is an
\r
3672 error if a stylesheet contains more than one binding of a top-level
\r
3673 variable with the same name and same <a href="#dt-import-precedence">import precedence</a>. At the
\r
3674 top-level, the expression or template specifying the variable value is
\r
3675 evaluated with the same context as that used to process the root node
\r
3676 of the source document: the current node is the root node of the
\r
3677 source document and the current node list is a list containing just
\r
3678 the root node of the source document. If the template or expression
\r
3679 specifying the value of a global variable <var>x</var> references a
\r
3680 global variable <var>y</var>, then the value for <var>y</var> must
\r
3681 be computed before the value of <var>x</var>. It is an error if it
\r
3682 is impossible to do this for all global variable definitions; in other
\r
3683 words, it is an error if the definitions are circular.</p>
\r
3685 <p>This example declares a global variable <code>para-font-size</code>,
\r
3686 which it references in an attribute value template.</p>
\r
3688 <pre><xsl:variable name="para-font-size">12pt</xsl:variable>
\r
3690 <xsl:template match="para">
\r
3691 <fo:block font-size="{$para-font-size}">
\r
3692 <xsl:apply-templates/>
\r
3694 </xsl:template>
\r
3701 <a name="local-variables"></a>11.5 Variables and Parameters within Templates</h3>
\r
3703 <p>As well as being allowed at the top-level, both
\r
3704 <code>xsl:variable</code> and <code>xsl:param</code> are also
\r
3705 allowed in templates. <code>xsl:variable</code> is allowed anywhere
\r
3706 within a template that an instruction is allowed. In this case, the
\r
3707 binding is visible for all following siblings and their descendants.
\r
3708 Note that the binding is not visible for the <code>xsl:variable</code>
\r
3709 element itself. <code>xsl:param</code> is allowed as a child
\r
3710 at the beginning of an <code>xsl:template</code> element. In this
\r
3711 context, the binding is visible for all following siblings and their
\r
3712 descendants. Note that the binding is not visible for the
\r
3713 <code>xsl:param</code> element itself.</p>
\r
3716 <a name="dt-shadows"></a>A binding
\r
3717 <b>shadows</b> another binding if the binding occurs at a point
\r
3718 where the other binding is visible, and the bindings have the same
\r
3719 name. It is an error if a binding established by an
\r
3720 <code>xsl:variable</code> or <code>xsl:param</code> element within a
\r
3721 template <a href="#dt-shadows">shadows</a> another binding
\r
3722 established by an <code>xsl:variable</code> or <code>xsl:param</code>
\r
3723 element also within the template. It is not an error if a binding
\r
3724 established by an <code>xsl:variable</code> or <code>xsl:param</code>
\r
3725 element in a template <a href="#dt-shadows">shadows</a>
\r
3726 another binding established by an <code>xsl:variable</code> or
\r
3727 <code>xsl:param</code> <a href="#dt-top-level">top-level</a>
\r
3728 element. Thus, the following is an error:</p>
\r
3730 <pre style="color: red"><xsl:template name="foo">
\r
3731 <xsl:param name="x" select="1"/>
\r
3732 <xsl:variable name="x" select="2"/>
\r
3733 </xsl:template></pre>
\r
3735 <p>However, the following is allowed:</p>
\r
3737 <pre><xsl:param name="x" select="1"/>
\r
3738 <xsl:template name="foo">
\r
3739 <xsl:variable name="x" select="2"/>
\r
3740 </xsl:template></pre>
\r
3743 <b>NOTE: </b>The nearest equivalent in Java to an <code>xsl:variable</code>
\r
3744 element in a template is a final local variable declaration with an
\r
3745 initializer. For example,
\r
3747 <pre><xsl:variable name="x" select="'value'"/></pre>
\r
3749 has similar semantics to
\r
3751 <pre>final Object x = "value";</pre>
\r
3753 XSLT does not provide an equivalent to the Java assignment operator
\r
3755 <pre>x = "value";</pre>
\r
3757 because this would make it harder to create an implementation that
\r
3758 processes a document other than in a batch-like way, starting at the
\r
3759 beginning and continuing through to the end.</blockquote>
\r
3765 <a name="section-Passing-Parameters-to-Templates"></a>11.6 Passing Parameters to Templates</h3>
\r
3767 <p class="element-syntax">
\r
3768 <a name="element-with-param"></a><code><xsl:with-param<br> <b>name</b> = <var>qname</var>
\r
3769 <br> select = <var>expression</var>><br> <!-- Content: <var>template</var> --><br></xsl:with-param></code>
\r
3772 <p>Parameters are passed to templates using the
\r
3773 <code>xsl:with-param</code> element. The required <code>name</code>
\r
3774 attribute specifies the name of the parameter (the variable the value
\r
3775 of whose binding is to be replaced). The value of the
\r
3776 <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>, which is expanded as described
\r
3777 in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>. <code>xsl:with-param</code> is allowed
\r
3778 within both <code>xsl:call-template</code> and
\r
3779 <code>xsl:apply-templates</code>. The value of the parameter is
\r
3780 specified in the same way as for <code>xsl:variable</code> and
\r
3781 <code>xsl:param</code>. The current node and current node list used
\r
3782 for computing the value specified by <code>xsl:with-param</code>
\r
3783 element is the same as that used for the
\r
3784 <code>xsl:apply-templates</code> or <code>xsl:call-template</code>
\r
3785 element within which it occurs. It is not an error to pass a
\r
3786 parameter <var>x</var> to a template that does not have an
\r
3787 <code>xsl:param</code> element for <var>x</var>; the parameter is
\r
3788 simply ignored.</p>
\r
3790 <p>This example defines a named template for a
\r
3791 <code>numbered-block</code> with an argument to control the format of
\r
3794 <pre><xsl:template name="numbered-block">
\r
3795 <xsl:param name="format">1. </xsl:param>
\r
3797 <xsl:number format="{$format}"/>
\r
3798 <xsl:apply-templates/>
\r
3800 </xsl:template>
\r
3802 <xsl:template match="ol//ol/li">
\r
3803 <xsl:call-template name="numbered-block">
\r
3804 <xsl:with-param name="format">a. </xsl:with-param>
\r
3805 </xsl:call-template>
\r
3806 </xsl:template></pre>
\r
3814 <a name="add-func"></a>12 Additional Functions</h2>
\r
3816 <p>This section describes XSLT-specific additions to the core XPath
\r
3817 function library. Some of these additional functions also make use of
\r
3818 information specified by <a href="#dt-top-level">top-level</a>
\r
3819 elements in the stylesheet; this section also describes these
\r
3825 <a name="document"></a>12.1 Multiple Source Documents</h3>
\r
3828 <a name="function-document"><b>Function: </b><i>node-set</i> <b>document</b>(<i>object</i>, <i>node-set</i>?)</a>
\r
3831 <p>The <b><a href="#function-document">document</a></b> function allows
\r
3832 access to XML documents other than the main source document.</p>
\r
3834 <p>When the <b><a href="#function-document">document</a></b> function has exactly one
\r
3835 argument and the argument is a node-set, then the result is the union,
\r
3836 for each node in the argument node-set, of the result of calling the
\r
3837 <b><a href="#function-document">document</a></b> function with the first argument being
\r
3838 the <a href="http://www.w3.org/TR/xpath#dt-string-value">string-value</a>
\r
3839 of the node, and the second argument being a node-set with the node as
\r
3840 its only member. When the <b><a href="#function-document">document</a></b> function has
\r
3841 two arguments and the first argument is a node-set, then the result is
\r
3842 the union, for each node in the argument node-set, of the result of
\r
3843 calling the <b><a href="#function-document">document</a></b> function with the first
\r
3844 argument being the <a href="http://www.w3.org/TR/xpath#dt-string-value">string-value</a> of the node,
\r
3845 and with the second argument being the second argument passed to the
\r
3846 <b><a href="#function-document">document</a></b> function.</p>
\r
3848 <p>When the first argument to the <b><a href="#function-document">document</a></b>
\r
3849 function is not a node-set, the first argument is converted to a
\r
3850 string as if by a call to the <b><a href="http://www.w3.org/TR/xpath#function-string">string</a></b> function.
\r
3851 This string is treated as a URI reference; the resource identified by
\r
3852 the URI is retrieved. The data resulting from the retrieval action is
\r
3853 parsed as an XML document and a tree is constructed in accordance with
\r
3854 the data model (see <a href="#data-model">[<b>3 Data Model</b>]</a>). If there is an
\r
3855 error retrieving the resource, then the XSLT processor may signal an
\r
3856 error; if it does not signal an error, it must recover by returning an
\r
3857 empty node-set. One possible kind of retrieval error is that the XSLT
\r
3858 processor does not support the URI scheme used by the URI. An XSLT
\r
3859 processor is not required to support any particular URI schemes. The
\r
3860 documentation for an XSLT processor should specify which URI schemes
\r
3861 the XSLT processor supports.</p>
\r
3863 <p>If the URI reference does not contain a fragment identifier, then a
\r
3864 node-set containing just the root node of the document is returned.
\r
3865 If the URI reference does contain a fragment identifier, the function
\r
3866 returns a node-set containing the nodes in the tree identified by the
\r
3867 fragment identifier of the URI reference. The semantics of the
\r
3868 fragment identifier is dependent on the media type of the result of
\r
3869 retrieving the URI. If there is an error in processing the fragment
\r
3870 identifier, the XSLT processor may signal the error; if it does not
\r
3871 signal the error, it must recover by returning an empty node-set.
\r
3872 Possible errors include:</p>
\r
3877 <p>The fragment identifier identifies something that cannot be
\r
3878 represented by an XSLT node-set (such as a range of characters within
\r
3883 <p>The XSLT processor does not support fragment identifiers for
\r
3884 the media-type of the retrieval result. An XSLT processor is not
\r
3885 required to support any particular media types. The documentation for
\r
3886 an XSLT processor should specify for which media types the XSLT
\r
3887 processor supports fragment identifiers.</p>
\r
3892 <p>The data resulting from the retrieval action is parsed as an XML
\r
3893 document regardless of the media type of the retrieval result; if the
\r
3894 top-level media type is <code>text</code>, then it is parsed in the
\r
3895 same way as if the media type were <code>text/xml</code>; otherwise,
\r
3896 it is parsed in the same way as if the media type were
\r
3897 <code>application/xml</code>.</p>
\r
3900 <b>NOTE: </b>Since there is no top-level <code>xml</code> media type, data
\r
3901 with a media type other than <code>text/xml</code> or
\r
3902 <code>application/xml</code> may in fact be XML.</blockquote>
\r
3904 <p>The URI reference may be relative. The base URI (see <a href="#base-uri">[<b>3.2 Base URI</b>]</a>) of the node in the second argument node-set that is
\r
3905 first in document order is used as the base URI for resolving the
\r
3906 relative URI into an absolute URI. If the second argument is omitted,
\r
3907 then it defaults to the node in the stylesheet that contains the
\r
3908 expression that includes the call to the <b><a href="#function-document">document</a></b>
\r
3909 function. Note that a zero-length URI reference is a reference to the
\r
3910 document relative to which the URI reference is being resolved; thus
\r
3911 <code>document("")</code> refers to the root node of the stylesheet;
\r
3912 the tree representation of the stylesheet is exactly the same as if
\r
3913 the XML document containing the stylesheet was the initial source
\r
3916 <p>Two documents are treated as the same document if they are
\r
3917 identified by the same URI. The URI used for the comparison is the
\r
3918 absolute URI into which any relative URI was resolved and does not
\r
3919 include any fragment identifier. One root node is treated as the same
\r
3920 node as another root node if the two nodes are from the same document.
\r
3921 Thus, the following expression will always be true:</p>
\r
3923 <pre>generate-id(document("foo.xml"))=generate-id(document("foo.xml"))</pre>
\r
3925 <p>The <b><a href="#function-document">document</a></b> function gives rise to the
\r
3926 possibility that a node-set may contain nodes from more than one
\r
3927 document. With such a node-set, the relative document order of two
\r
3928 nodes in the same document is the normal <a href="http://www.w3.org/TR/xpath#dt-document-order">document order</a> defined by
\r
3929 XPath <a href="#XPATH">[XPath]</a>. The relative document order of two nodes
\r
3930 in different documents is determined by an implementation-dependent
\r
3931 ordering of the documents containing the two nodes. There are no
\r
3932 constraints on how the implementation orders documents other than that
\r
3933 it must do so consistently: an implementation must always use the same
\r
3934 order for the same set of documents.</p>
\r
3940 <a name="key"></a>12.2 Keys</h3>
\r
3942 <p>Keys provide a way to work with documents that contain an implicit
\r
3943 cross-reference structure. The <code>ID</code>, <code>IDREF</code>
\r
3944 and <code>IDREFS</code> attribute types in XML provide a mechanism to
\r
3945 allow XML documents to make their cross-reference explicit. XSLT
\r
3946 supports this through the XPath <b><a href="http://www.w3.org/TR/xpath#function-id">id</a></b> function.
\r
3947 However, this mechanism has a number of limitations:</p>
\r
3952 <p>ID attributes must be declared as such in the DTD. If an ID
\r
3953 attribute is declared as an ID attribute only in the external DTD
\r
3954 subset, then it will be recognized as an ID attribute only if the XML
\r
3955 processor reads the external DTD subset. However, XML does not require
\r
3956 XML processors to read the external DTD, and they may well choose not
\r
3957 to do so, especially if the document is declared
\r
3958 <code>standalone="yes"</code>.</p>
\r
3962 <p>A document can contain only a single set of unique IDs.
\r
3963 There cannot be separate independent sets of unique IDs.</p>
\r
3967 <p>The ID of an element can only be specified in an attribute;
\r
3968 it cannot be specified by the content of the element, or by a child
\r
3973 <p>An ID is constrained to be an XML name. For example, it
\r
3974 cannot contain spaces.</p>
\r
3978 <p>An element can have at most one ID.</p>
\r
3982 <p>At most one element can have a particular ID.</p>
\r
3987 <p>Because of these limitations XML documents sometimes contain a
\r
3988 cross-reference structure that is not explicitly declared by
\r
3989 ID/IDREF/IDREFS attributes.</p>
\r
3991 <p>A key is a triple containing:</p>
\r
3996 <p>the node which has the key</p>
\r
4000 <p>the name of the key (an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a>)</p>
\r
4004 <p>the value of the key (a string)</p>
\r
4009 <p>A stylesheet declares a set of keys for each document using the
\r
4010 <code>xsl:key</code> element. When this set of keys contains a member
\r
4011 with node <var>x</var>, name <var>y</var> and value
\r
4012 <var>z</var>, we say that node <var>x</var> has a key with name
\r
4013 <var>y</var> and value <var>z</var>.</p>
\r
4015 <p>Thus, a key is a kind of generalized ID, which is not subject to the
\r
4016 same limitations as an XML ID:</p>
\r
4021 <p>Keys are declared in the stylesheet using
\r
4022 <code>xsl:key</code> elements.</p>
\r
4026 <p>A key has a name as well as a value; each key name may be
\r
4027 thought of as distinguishing a separate, independent space of
\r
4032 <p>The value of a named key for an element may be specified in
\r
4033 any convenient place; for example, in an attribute, in a child element
\r
4034 or in content. An XPath expression is used to specify where to find
\r
4035 the value for a particular named key.</p>
\r
4039 <p>The value of a key can be an arbitrary string; it is not
\r
4040 constrained to be a name.</p>
\r
4044 <p>There can be multiple keys in a document with the same node,
\r
4045 same key name, but different key values.</p>
\r
4049 <p>There can be multiple keys in a document with the same key
\r
4050 name, same key value, but different nodes.</p>
\r
4055 <p class="element-syntax">
\r
4056 <a name="element-key"></a><code><!-- Category: top-level-element --><br><xsl:key<br> <b>name</b> = <var>qname</var>
\r
4057 <br> <b>match</b> = <var>pattern</var>
\r
4058 <br> <b>use</b> = <var>expression</var> /></code>
\r
4061 <p>The <code>xsl:key</code> element is used to declare keys. The
\r
4062 <code>name</code> attribute specifies the name of the key. The value
\r
4063 of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>, which is expanded as described
\r
4064 in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>. The <code>match</code> attribute is a <a href="#NT-Pattern">Pattern</a>; an <code>xsl:key</code> element gives
\r
4065 information about the keys of any node that matches the pattern
\r
4066 specified in the match attribute. The <code>use</code> attribute is
\r
4067 an <a href="#dt-expression">expression</a> specifying the
\r
4068 values of the key; the expression is evaluated once for each node that
\r
4069 matches the pattern. If the result is a node-set, then for each node
\r
4070 in the node-set, the node that matches the pattern has a key of the
\r
4071 specified name whose value is the string-value of the node in the
\r
4072 node-set; otherwise, the result is converted to a string, and the node
\r
4073 that matches the pattern has a key of the specified name with value
\r
4074 equal to that string. Thus, a node <var>x</var> has a key with name
\r
4075 <var>y</var> and value <var>z</var> if and only if there is an
\r
4076 <code>xsl:key</code> element such that:</p>
\r
4082 <var>x</var> matches the pattern specified in the
\r
4083 <code>match</code> attribute of the <code>xsl:key</code> element;</p>
\r
4087 <p>the value of the <code>name</code> attribute of the
\r
4088 <code>xsl:key</code> element is equal to <var>y</var>;
\r
4093 <p>when the expression specified in the <code>use</code>
\r
4094 attribute of the <code>xsl:key</code> element is evaluated with
\r
4095 <var>x</var> as the current node and with a node list containing
\r
4096 just <var>x</var> as the current node list resulting in an object
\r
4097 <var>u</var>, then either <var>z</var> is equal to the result of
\r
4098 converting <var>u</var> to a string as if by a call to the
\r
4099 <b><a href="http://www.w3.org/TR/xpath#function-string">string</a></b> function, or <var>u</var> is a
\r
4100 node-set and <var>z</var> is equal to the string-value of one or
\r
4101 more of the nodes in <var>u</var>.</p>
\r
4106 <p>Note also that there may be more than one <code>xsl:key</code>
\r
4107 element that matches a given node; all of the matching
\r
4108 <code>xsl:key</code> elements are used, even if they do not have the
\r
4109 same <a href="#dt-import-precedence">import
\r
4110 precedence</a>.</p>
\r
4112 <p>It is an error for the value of either the <code>use</code>
\r
4113 attribute or the <code>match</code> attribute to contain a <a href="http://www.w3.org/TR/xpath#NT-VariableReference">VariableReference</a>.</p>
\r
4116 <a name="function-key"><b>Function: </b><i>node-set</i> <b>key</b>(<i>string</i>, <i>object</i>)</a>
\r
4119 <p>The <b><a href="#function-key">key</a></b> function does for keys what the
\r
4120 <b><a href="http://www.w3.org/TR/xpath#function-id">id</a></b> function does for IDs. The first argument
\r
4121 specifies the name of the key. The value of the argument must be a
\r
4122 <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>, which is expanded as
\r
4123 described in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>. When the second argument to the
\r
4124 <b><a href="#function-key">key</a></b> function is of type node-set, then the result
\r
4125 is the union of the result of applying the <b><a href="#function-key">key</a></b>
\r
4126 function to the string <a href="http://www.w3.org/TR/xpath#dt-value">value</a> of each of the nodes in the
\r
4127 argument node-set. When the second argument to
\r
4128 <b><a href="#function-key">key</a></b> is of any other type, the argument is
\r
4129 converted to a string as if by a call to the
\r
4130 <b><a href="http://www.w3.org/TR/xpath#function-string">string</a></b> function; it returns a node-set
\r
4131 containing the nodes in the same document as the context node that
\r
4132 have a value for the named key equal to this string.</p>
\r
4134 <p>For example, given a declaration</p>
\r
4136 <pre><xsl:key name="idkey" match="div" use="@id"/></pre>
\r
4138 <p>an expression <code>key("idkey",@ref)</code> will return the same
\r
4139 node-set as <code>id(@ref)</code>, assuming that the only ID attribute
\r
4140 declared in the XML source document is:</p>
\r
4142 <pre><!ATTLIST div id ID #IMPLIED></pre>
\r
4144 <p>and that the <code>ref</code> attribute of the current node
\r
4145 contains no whitespace.</p>
\r
4147 <p>Suppose a document describing a function library uses a
\r
4148 <code>prototype</code> element to define functions</p>
\r
4150 <pre><prototype name="key" return-type="node-set">
\r
4151 <arg type="string"/>
\r
4152 <arg type="object"/>
\r
4153 </prototype></pre>
\r
4155 <p>and a <code>function</code> element to refer to function names</p>
\r
4157 <pre><function>key</function></pre>
\r
4159 <p>Then the stylesheet could generate hyperlinks between the
\r
4160 references and definitions as follows:</p>
\r
4162 <pre><xsl:key name="func" match="prototype" use="@name"/>
\r
4164 <xsl:template match="function">
\r
4166 <a href="#{generate-id(key('func',.))}">
\r
4167 <xsl:apply-templates/>
\r
4170 </xsl:template>
\r
4172 <xsl:template match="prototype">
\r
4173 <p><a name="{generate-id()}">
\r
4174 <b>Function: </b>
\r
4176 </a></p>
\r
4177 </xsl:template></pre>
\r
4179 <p>The <b><a href="#function-key">key</a></b> can be used to retrieve a key from a
\r
4180 document other than the document containing the context node. For
\r
4181 example, suppose a document contains bibliographic references in the
\r
4182 form <code><bibref>XSLT</bibref></code>, and there is a
\r
4183 separate XML document <code>bib.xml</code> containing a bibliographic
\r
4184 database with entries in the form:</p>
\r
4186 <pre><entry name="XSLT">...</entry></pre>
\r
4188 <p>Then the stylesheet could use the following to transform the
\r
4189 <code>bibref</code> elements:</p>
\r
4191 <pre><xsl:key name="bib" match="entry" use="@name"/>
\r
4193 <xsl:template match="bibref">
\r
4194 <xsl:variable name="name" select="."/>
\r
4195 <xsl:for-each select="document('bib.xml')">
\r
4196 <xsl:apply-templates select="key('bib',$name)"/>
\r
4197 </xsl:for-each>
\r
4198 </xsl:template></pre>
\r
4204 <a name="format-number"></a>12.3 Number Formatting</h3>
\r
4207 <a name="function-format-number"><b>Function: </b><i>string</i> <b>format-number</b>(<i>number</i>, <i>string</i>, <i>string</i>?)</a>
\r
4210 <p>The <b><a href="#function-format-number">format-number</a></b> function converts its first
\r
4211 argument to a string using the format pattern string specified by the
\r
4212 second argument and the decimal-format named by the third argument, or
\r
4213 the default decimal-format, if there is no third argument. The format
\r
4214 pattern string is in the syntax specified by the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.text.DecimalFormat.html">DecimalFormat</a> class. The format pattern string is in a
\r
4215 localized notation: the decimal-format determines what characters have
\r
4216 a special meaning in the pattern (with the exception of the quote
\r
4217 character, which is not localized). The format pattern must not
\r
4218 contain the currency sign (#x00A4); support for this feature was added
\r
4219 after the initial release of JDK 1.1. The decimal-format name must be
\r
4220 a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>, which is expanded as
\r
4221 described in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>. It is an error if the stylesheet
\r
4222 does not contain a declaration of the decimal-format with the specified
\r
4223 <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a>.</p>
\r
4226 <b>NOTE: </b>Implementations are not required to use the JDK 1.1
\r
4227 implementation, nor are implementations required to be implemented in
\r
4228 Java.</blockquote>
\r
4231 <b>NOTE: </b>Stylesheets can use other facilities in XPath to control
\r
4232 rounding.</blockquote>
\r
4234 <p class="element-syntax">
\r
4235 <a name="element-decimal-format"></a><code><!-- Category: top-level-element --><br><xsl:decimal-format<br> name = <var>qname</var>
\r
4236 <br> decimal-separator = <var>char</var>
\r
4237 <br> grouping-separator = <var>char</var>
\r
4238 <br> infinity = <var>string</var>
\r
4239 <br> minus-sign = <var>char</var>
\r
4240 <br> NaN = <var>string</var>
\r
4241 <br> percent = <var>char</var>
\r
4242 <br> per-mille = <var>char</var>
\r
4243 <br> zero-digit = <var>char</var>
\r
4244 <br> digit = <var>char</var>
\r
4245 <br> pattern-separator = <var>char</var> /></code>
\r
4248 <p>The <code>xsl:decimal-format</code> element declares a
\r
4249 decimal-format, which controls the interpretation of a format pattern
\r
4250 used by the <b><a href="#function-format-number">format-number</a></b> function. If there is
\r
4251 a <code>name</code> attribute, then the element declares a named
\r
4252 decimal-format; otherwise, it declares the default decimal-format.
\r
4253 The value of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>, which is expanded as described
\r
4254 in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>. It is an error to declare either the
\r
4255 default decimal-format or a decimal-format with a given name more than
\r
4256 once (even with different <a href="#dt-import-precedence">import
\r
4257 precedence</a>), unless it is declared every time with the same
\r
4258 value for all attributes (taking into account any default values).</p>
\r
4260 <p>The other attributes on <code>xsl:decimal-format</code> correspond
\r
4261 to the methods on the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.text.DecimalFormatSymbols.html">DecimalFormatSymbols</a> class. For each
\r
4262 <code>get</code>/<code>set</code> method pair there is an attribute
\r
4263 defined for the <code>xsl:decimal-format</code> element.</p>
\r
4265 <p>The following attributes both control the interpretation of
\r
4266 characters in the format pattern and specify characters that may
\r
4267 appear in the result of formatting the number:</p>
\r
4273 <code>decimal-separator</code> specifies the character used
\r
4274 for the decimal sign; the default value is the period character
\r
4275 (<code>.</code>)</p>
\r
4280 <code>grouping-separator</code> specifies the character used
\r
4281 as a grouping (e.g. thousands) separator; the default value is the
\r
4282 comma character (<code>,</code>)</p>
\r
4287 <code>percent</code> specifies the character used as a
\r
4288 percent sign; the default value is the percent character
\r
4289 (<code>%</code>)</p>
\r
4294 <code>per-mille</code> specifies the character used as a per
\r
4295 mille sign; the default value is the Unicode per-mille character
\r
4301 <code>zero-digit</code> specifies the character used as the
\r
4302 digit zero; the default value is the digit zero
\r
4303 (<code>0</code>)</p>
\r
4308 <p>The following attributes control the interpretation of characters
\r
4309 in the format pattern:</p>
\r
4315 <code>digit</code> specifies the character used for a digit
\r
4316 in the format pattern; the default value is the number sign character
\r
4317 (<code>#</code>)</p>
\r
4322 <code>pattern-separator</code> specifies the character used
\r
4323 to separate positive and negative sub patterns in a pattern; the
\r
4324 default value is the semi-colon character (<code>;</code>)</p>
\r
4329 <p>The following attributes specify characters or strings that may
\r
4330 appear in the result of formatting the number:</p>
\r
4336 <code>infinity</code> specifies the string used to represent
\r
4337 infinity; the default value is the string
\r
4338 <code>Infinity</code>
\r
4344 <code>NaN</code> specifies the string used to represent the
\r
4345 NaN value; the default value is the string <code>NaN</code>
\r
4351 <code>minus-sign</code> specifies the character used as the
\r
4352 default minus sign; the default value is the hyphen-minus character
\r
4353 (<code>-</code>, #x2D)</p>
\r
4362 <a name="misc-func"></a>12.4 Miscellaneous Additional Functions</h3>
\r
4365 <a name="function-current"><b>Function: </b><i>node-set</i> <b>current</b>()</a>
\r
4368 <p>The <b><a href="#function-current">current</a></b> function returns a node-set that
\r
4369 has the <a href="#dt-current-node">current node</a> as its
\r
4370 only member. For an outermost expression (an expression not occurring
\r
4371 within another expression), the current node is always the same as the
\r
4372 context node. Thus,</p>
\r
4374 <pre><xsl:value-of select="current()"/></pre>
\r
4376 <p>means the same as</p>
\r
4378 <pre><xsl:value-of select="."/></pre>
\r
4380 <p>However, within square brackets the current node is usually
\r
4381 different from the context node. For example,</p>
\r
4383 <pre><xsl:apply-templates select="//glossary/item[@name=current()/@ref]"/></pre>
\r
4385 <p>will process all <code>item</code> elements that have a
\r
4386 <code>glossary</code> parent element and that have a <code>name</code>
\r
4387 attribute with value equal to the value of the current node's
\r
4388 <code>ref</code> attribute. This is different from</p>
\r
4390 <pre><xsl:apply-templates select="//glossary/item[@name=./@ref]"/></pre>
\r
4392 <p>which means the same as</p>
\r
4394 <pre><xsl:apply-templates select="//glossary/item[@name=@ref]"/></pre>
\r
4396 <p>and so would process all <code>item</code> elements that have a
\r
4397 <code>glossary</code> parent element and that have a <code>name</code>
\r
4398 attribute and a <code>ref</code> attribute with the same value.</p>
\r
4400 <p>It is an error to use the <b><a href="#function-current">current</a></b> function in
\r
4401 a <a href="#dt-pattern">pattern</a>.</p>
\r
4404 <a name="function-unparsed-entity-uri"><b>Function: </b><i>string</i> <b>unparsed-entity-uri</b>(<i>string</i>)</a>
\r
4407 <p>The <b><a href="#function-unparsed-entity-uri">unparsed-entity-uri</a></b> returns the URI of the
\r
4408 unparsed entity with the specified name in the same document as the
\r
4409 context node (see <a href="#unparsed-entities">[<b>3.3 Unparsed Entities</b>]</a>). It returns the
\r
4410 empty string if there is no such entity.</p>
\r
4413 <a name="function-generate-id"><b>Function: </b><i>string</i> <b>generate-id</b>(<i>node-set</i>?)</a>
\r
4416 <p>The <b><a href="#function-generate-id">generate-id</a></b> function returns a string that
\r
4417 uniquely identifies the node in the argument node-set that is first in
\r
4418 document order. The unique identifier must consist of ASCII
\r
4419 alphanumeric characters and must start with an alphabetic character.
\r
4420 Thus, the string is syntactically an XML name. An implementation is
\r
4421 free to generate an identifier in any convenient way provided that it
\r
4422 always generates the same identifier for the same node and that
\r
4423 different identifiers are always generated from different nodes. An
\r
4424 implementation is under no obligation to generate the same identifiers
\r
4425 each time a document is transformed. There is no guarantee that a
\r
4426 generated unique identifier will be distinct from any unique IDs
\r
4427 specified in the source document. If the argument node-set is empty,
\r
4428 the empty string is returned. If the argument is omitted, it defaults
\r
4429 to the context node.</p>
\r
4432 <a name="function-system-property"><b>Function: </b><i>object</i> <b>system-property</b>(<i>string</i>)</a>
\r
4435 <p>The argument must evaluate to a string that is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>. The <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> is expanded into a name using
\r
4436 the namespace declarations in scope for the expression. The
\r
4437 <b><a href="#function-system-property">system-property</a></b> function returns an object
\r
4438 representing the value of the system property identified by the name.
\r
4439 If there is no such system property, the empty string should be
\r
4442 <p>Implementations must provide the following system properties, which
\r
4443 are all in the XSLT namespace:</p>
\r
4448 <code>xsl:version</code>, a number giving the version of XSLT
\r
4449 implemented by the processor; for XSLT processors implementing the
\r
4450 version of XSLT specified by this document, this is the number
\r
4454 <code>xsl:vendor</code>, a string identifying the vendor of the
\r
4455 XSLT processor</li>
\r
4458 <code>xsl:vendor-url</code>, a string containing a URL
\r
4459 identifying the vendor of the XSLT processor; typically this is the
\r
4460 host page (home page) of the vendor's Web site.</li>
\r
4470 <a name="message"></a>13 Messages</h2>
\r
4472 <p class="element-syntax">
\r
4473 <a name="element-message"></a><code><!-- Category: instruction --><br><xsl:message<br> terminate = "yes" | "no"><br> <!-- Content: <var>template</var> --><br></xsl:message></code>
\r
4476 <p>The <code>xsl:message</code> instruction sends a message in a way
\r
4477 that is dependent on the XSLT processor. The content of the
\r
4478 <code>xsl:message</code> instruction is a template. The
\r
4479 <code>xsl:message</code> is instantiated by instantiating the content
\r
4480 to create an XML fragment. This XML fragment is the content of the
\r
4484 <b>NOTE: </b>An XSLT processor might implement <code>xsl:message</code> by
\r
4485 popping up an alert box or by writing to a log file.</blockquote>
\r
4487 <p>If the <code>terminate</code> attribute has the value
\r
4488 <code>yes</code>, then the XSLT processor should terminate processing
\r
4489 after sending the message. The default value is <code>no</code>.</p>
\r
4491 <p>One convenient way to do localization is to put the localized
\r
4492 information (message text, etc.) in an XML document, which becomes an
\r
4493 additional input file to the stylesheet. For example, suppose
\r
4494 messages for a language <code><var>L</var></code> are stored in an XML
\r
4495 file <code>resources/<var>L</var>.xml</code> in the form:</p>
\r
4497 <pre><messages>
\r
4498 <message name="problem">A problem was detected.</message>
\r
4499 <message name="error">An error was detected.</message>
\r
4503 <p>Then a stylesheet could use the following approach to localize
\r
4506 <pre><xsl:param name="lang" select="en"/>
\r
4507 <xsl:variable name="messages"
\r
4508 select="document(concat('resources/', $lang, '.xml'))/messages"/>
\r
4510 <xsl:template name="localized-message">
\r
4511 <xsl:param name="name"/>
\r
4512 <xsl:message>
\r
4513 <xsl:value-of select="$messages/message[@name=$name]"/>
\r
4514 </xsl:message>
\r
4515 </xsl:template>
\r
4517 <xsl:template name="problem">
\r
4518 <xsl:call-template name="localized-message"/>
\r
4519 <xsl:with-param name="name">problem</xsl:with-param>
\r
4520 </xsl:call-template>
\r
4521 </xsl:template></pre>
\r
4527 <a name="extension"></a>14 Extensions</h2>
\r
4529 <p>XSLT allows two kinds of extension, extension elements and
\r
4530 extension functions.</p>
\r
4532 <p>This version of XSLT does not provide a mechanism for defining
\r
4533 implementations of extensions. Therefore, an XSLT stylesheet that must
\r
4534 be portable between XSLT implementations cannot rely on particular
\r
4535 extensions being available. XSLT provides mechanisms that allow an
\r
4536 XSLT stylesheet to determine whether the XSLT processor by which it is
\r
4537 being processed has implementations of particular extensions
\r
4538 available, and to specify what should happen if those extensions are
\r
4539 not available. If an XSLT stylesheet is careful to make use of these
\r
4540 mechanisms, it is possible for it to take advantage of extensions and
\r
4541 still work with any XSLT implementation.</p>
\r
4545 <a name="extension-element"></a>14.1 Extension Elements</h3>
\r
4548 <a name="dt-extension-namespace"></a>The
\r
4549 element extension mechanism allows namespaces to be designated as
\r
4550 <b>extension namespace</b>s. When a namespace is designated as
\r
4551 an extension namespace and an element with a name from that namespace
\r
4552 occurs in a template, then the element is treated as an instruction
\r
4553 rather than as a literal result element. The namespace
\r
4554 determines the semantics of the instruction.</p>
\r
4557 <b>NOTE: </b>Since an element that is a child of an
\r
4558 <code>xsl:stylesheet</code> element is not occurring <i>in a
\r
4559 template</i>, non-XSLT <a href="#dt-top-level">top-level</a> elements are not extension
\r
4560 elements as defined here, and nothing in this section applies to
\r
4561 them.</blockquote>
\r
4563 <p>A namespace is designated as an extension namespace by using an
\r
4564 <code>extension-element-prefixes</code> attribute on an
\r
4565 <code>xsl:stylesheet</code> element or an
\r
4566 <code>xsl:extension-element-prefixes</code> attribute on a literal
\r
4567 result element or extension element.
\r
4568 The value of both these attributes is a
\r
4569 whitespace-separated list of namespace prefixes. The namespace bound
\r
4570 to each of the prefixes is designated as an extension namespace. It
\r
4571 is an error if there is no namespace bound to the prefix on the
\r
4572 element bearing the <code>extension-element-prefixes</code> or
\r
4573 <code>xsl:extension-element-prefixes</code> attribute. The default
\r
4574 namespace (as declared by <code>xmlns</code>) may be designated as an
\r
4575 extension namespace by including <code>#default</code> in the list of
\r
4576 namespace prefixes. The designation of a namespace as an extension
\r
4577 namespace is effective within the subtree of the stylesheet rooted at
\r
4578 the element bearing the <code>extension-element-prefixes</code> or
\r
4579 <code>xsl:extension-element-prefixes</code> attribute;
\r
4580 a subtree rooted at an <code>xsl:stylesheet</code> element
\r
4581 does not include any stylesheets imported or included by children
\r
4582 of that <code>xsl:stylesheet</code> element.</p>
\r
4584 <p>If the XSLT processor does not have an implementation of a
\r
4585 particular extension element available, then the
\r
4586 <b><a href="#function-element-available">element-available</a></b> function must return false for
\r
4587 the name of the element. When such an extension element is
\r
4588 instantiated, then the XSLT processor must perform fallback for the
\r
4589 element as specified in <a href="#fallback">[<b>15 Fallback</b>]</a>. An XSLT processor
\r
4590 must not signal an error merely because a template contains an
\r
4591 extension element for which no implementation is available.</p>
\r
4593 <p>If the XSLT processor has an implementation of a particular
\r
4594 extension element available, then the
\r
4595 <b><a href="#function-element-available">element-available</a></b> function must return true for
\r
4596 the name of the element.</p>
\r
4602 <a name="section-Extension-Functions"></a>14.2 Extension Functions</h3>
\r
4604 <p>If a <a href="http://www.w3.org/TR/xpath#NT-FunctionName">FunctionName</a> in a
\r
4605 <a href="http://www.w3.org/TR/xpath#NT-FunctionCall">FunctionCall</a> expression is
\r
4606 not an <a href="http://www.w3.org/TR/REC-xml-names#NT-NCName">NCName</a> (i.e. if it
\r
4607 contains a colon), then it is treated as a call to an extension
\r
4608 function. The <a href="http://www.w3.org/TR/xpath#NT-FunctionName">FunctionName</a>
\r
4609 is expanded to a name using the namespace declarations from the
\r
4610 evaluation context.</p>
\r
4612 <p>If the XSLT processor does not have an implementation of an
\r
4613 extension function of a particular name available, then the
\r
4614 <b><a href="#function-function-available">function-available</a></b> function must return false for
\r
4615 that name. If such an extension function occurs in an expression and
\r
4616 the extension function is actually called, the XSLT processor must
\r
4617 signal an error. An XSLT processor must not signal an error merely
\r
4618 because an expression contains an extension function for which no
\r
4619 implementation is available.</p>
\r
4621 <p>If the XSLT processor has an implementation of an extension
\r
4622 function of a particular name available, then the
\r
4623 <b><a href="#function-function-available">function-available</a></b> function must return
\r
4624 true for that name. If such an extension is called, then the XSLT
\r
4625 processor must call the implementation passing it the function call
\r
4626 arguments; the result returned by the implementation is returned as
\r
4627 the result of the function call.</p>
\r
4635 <a name="fallback"></a>15 Fallback</h2>
\r
4637 <p class="element-syntax">
\r
4638 <a name="element-fallback"></a><code><!-- Category: instruction --><br><xsl:fallback><br> <!-- Content: <var>template</var> --><br></xsl:fallback></code>
\r
4641 <p>Normally, instantiating an <code>xsl:fallback</code> element does
\r
4642 nothing. However, when an XSLT processor performs fallback for an
\r
4643 instruction element, if the instruction element has one or more
\r
4644 <code>xsl:fallback</code> children, then the content of each of the
\r
4645 <code>xsl:fallback</code> children must be instantiated in sequence;
\r
4646 otherwise, an error must be signaled. The content of an
\r
4647 <code>xsl:fallback</code> element is a template.</p>
\r
4649 <p>The following functions can be used with the
\r
4650 <code>xsl:choose</code> and <code>xsl:if</code> instructions to
\r
4651 explicitly control how a stylesheet should behave if particular
\r
4652 elements or functions are not available.</p>
\r
4655 <a name="function-element-available"><b>Function: </b><i>boolean</i> <b>element-available</b>(<i>string</i>)</a>
\r
4658 <p>The argument must evaluate to a string that is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>. The <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> is expanded into an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> using the
\r
4659 namespace declarations in scope for the expression. The
\r
4660 <b><a href="#function-element-available">element-available</a></b> function returns true if and
\r
4661 only if the expanded-name is the name of an instruction. If the
\r
4662 expanded-name has a namespace URI equal to the XSLT namespace URI,
\r
4663 then it refers to an element defined by XSLT. Otherwise, it refers to
\r
4664 an extension element. If the expanded-name has a null namespace URI,
\r
4665 the <b><a href="#function-element-available">element-available</a></b> function will return
\r
4669 <a name="function-function-available"><b>Function: </b><i>boolean</i> <b>function-available</b>(<i>string</i>)</a>
\r
4672 <p>The argument must evaluate to a string that is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>. The <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> is expanded into an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> using the
\r
4673 namespace declarations in scope for the expression. The
\r
4674 <b><a href="#function-function-available">function-available</a></b> function returns true if and
\r
4675 only if the expanded-name is the name of a function in the function
\r
4676 library. If the expanded-name has a non-null namespace URI, then it
\r
4677 refers to an extension function; otherwise, it refers to a function
\r
4678 defined by XPath or XSLT.</p>
\r
4684 <a name="output"></a>16 Output</h2>
\r
4686 <p class="element-syntax">
\r
4687 <a name="element-output"></a><code><!-- Category: top-level-element --><br><xsl:output<br> method = "xml" | "html" | "text" | <var>qname-but-not-ncname</var>
\r
4688 <br> version = <var>nmtoken</var>
\r
4689 <br> encoding = <var>string</var>
\r
4690 <br> omit-xml-declaration = "yes" | "no"<br> standalone = "yes" | "no"<br> doctype-public = <var>string</var>
\r
4691 <br> doctype-system = <var>string</var>
\r
4692 <br> cdata-section-elements = <var>qnames</var>
\r
4693 <br> indent = "yes" | "no"<br> media-type = <var>string</var> /></code>
\r
4696 <p>An XSLT processor may output the result tree as a sequence of
\r
4697 bytes, although it is not required to be able to do so (see <a href="#conformance">[<b>17 Conformance</b>]</a>). The <code>xsl:output</code> element allows
\r
4698 stylesheet authors to specify how they wish the result tree to be
\r
4699 output. If an XSLT processor outputs the result tree, it should do so
\r
4700 as specified by the <code>xsl:output</code> element; however, it is
\r
4701 not required to do so.</p>
\r
4703 <p>The <code>xsl:output</code> element is only allowed as a <a href="#dt-top-level">top-level</a> element.</p>
\r
4705 <p>The <code>method</code> attribute on <code>xsl:output</code>
\r
4706 identifies the overall method that should be used for outputting the
\r
4707 result tree. The value must be a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>. If the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> does not have a prefix, then it
\r
4708 identifies a method specified in this document and must be one of
\r
4709 <code>xml</code>, <code>html</code> or <code>text</code>. If the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> has a prefix, then the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> is expanded into an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> as described
\r
4710 in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>; the expanded-name identifies the output
\r
4711 method; the behavior in this case is not specified by this
\r
4714 <p>The default for the <code>method</code> attribute is chosen as
\r
4720 <p>the root node of the result tree has an element
\r
4725 <p>the expanded-name of the first element child of the root node
\r
4726 (i.e. the document element) of the result tree has local part
\r
4727 <code>html</code> (in any combination of upper and lower case) and a
\r
4728 null namespace URI, and</p>
\r
4732 <p>any text nodes preceding the first element child of the root
\r
4733 node of the result tree contain only whitespace characters,</p>
\r
4738 <p>then the default output method is <code>html</code>; otherwise, the
\r
4739 default output method is <code>xml</code>. The default output method
\r
4740 should be used if there are no <code>xsl:output</code> elements or if
\r
4741 none of the <code>xsl:output</code> elements specifies a value for the
\r
4742 <code>method</code> attribute.</p>
\r
4744 <p>The other attributes on <code>xsl:output</code> provide parameters
\r
4745 for the output method. The following attributes are allowed:</p>
\r
4751 <code>version</code> specifies the version of the output
\r
4757 <code>indent</code> specifies whether the XSLT processor may
\r
4758 add additional whitespace when outputting the result tree; the value
\r
4759 must be <code>yes</code> or <code>no</code>
\r
4765 <code>encoding</code> specifies the preferred character
\r
4766 encoding that the XSLT processor should use to encode sequences of
\r
4767 characters as sequences of bytes; the value of the attribute should be
\r
4768 treated case-insensitively; the value must contain only characters in
\r
4769 the range #x21 to #x7E (i.e. printable ASCII characters); the value
\r
4770 should either be a <code>charset</code> registered with the Internet
\r
4771 Assigned Numbers Authority <a href="#IANA">[IANA]</a>, <a href="#RFC2278">[RFC2278]</a> or start with <code>X-</code>
\r
4777 <code>media-type</code> specifies the media type (MIME
\r
4778 content type) of the data that results from outputting the result
\r
4779 tree; the <code>charset</code> parameter should not be specified
\r
4780 explicitly; instead, when the top-level media type is
\r
4781 <code>text</code>, a <code>charset</code> parameter should be added
\r
4782 according to the character encoding actually used by the output
\r
4788 <code>doctype-system</code> specifies the system identifier
\r
4789 to be used in the document type declaration</p>
\r
4794 <code>doctype-public</code> specifies the public identifier
\r
4795 to be used in the document type declaration</p>
\r
4800 <code>omit-xml-declaration</code> specifies whether the XSLT
\r
4801 processor should output an XML declaration; the value must be
\r
4802 <code>yes</code> or <code>no</code>
\r
4808 <code>standalone</code> specifies whether the XSLT processor
\r
4809 should output a standalone document declaration; the value must be
\r
4810 <code>yes</code> or <code>no</code>
\r
4816 <code>cdata-section-elements</code> specifies a list of the
\r
4817 names of elements whose text node children should be output using
\r
4818 CDATA sections</p>
\r
4823 <p>The detailed semantics of each attribute will be described
\r
4824 separately for each output method for which it is applicable. If the
\r
4825 semantics of an attribute are not described for an output method, then
\r
4826 it is not applicable to that output method.</p>
\r
4828 <p>A stylesheet may contain multiple <code>xsl:output</code> elements
\r
4829 and may include or import stylesheets that also contain
\r
4830 <code>xsl:output</code> elements. All the <code>xsl:output</code>
\r
4831 elements occurring in a stylesheet are merged into a single effective
\r
4832 <code>xsl:output</code> element. For the
\r
4833 <code>cdata-section-elements</code> attribute, the effective value is
\r
4834 the union of the specified values. For other attributes, the
\r
4835 effective value is the specified value with the highest <a href="#dt-import-precedence">import precedence</a>. It is an error
\r
4836 if there is more than one such value for an attribute. An XSLT
\r
4837 processor may signal the error; if it does not signal the error, if
\r
4838 should recover by using the value that occurs last in the stylesheet.
\r
4839 The values of attributes are defaulted after the
\r
4840 <code>xsl:output</code> elements have been merged; different output
\r
4841 methods may have different default values for an attribute.</p>
\r
4845 <a name="section-XML-Output-Method"></a>16.1 XML Output Method</h3>
\r
4847 <p>The <code>xml</code> output method outputs the result tree as a
\r
4848 well-formed XML external general parsed entity. If the root node of
\r
4849 the result tree has a single element node child and no text node
\r
4850 children, then the entity should also be a well-formed XML document
\r
4851 entity. When the entity is referenced within a trivial XML document
\r
4852 wrapper like this</p>
\r
4855 <!DOCTYPE doc [
\r
4856 <!ENTITY e SYSTEM "<var>entity-URI</var>">
\r
4858 <doc>&e;</doc></pre>
\r
4860 <p>where <code><var>entity-URI</var></code> is a URI for the entity,
\r
4862 document as a whole should be a well-formed XML document conforming to
\r
4863 the XML Namespaces Recommendation <a href="#XMLNAMES">[XML Names]</a>. In
\r
4864 addition, the output should be such that if a new tree was constructed
\r
4865 by parsing the wrapper as an XML document as specified in <a href="#data-model">[<b>3 Data Model</b>]</a>, and then removing the document element, making its
\r
4866 children instead be children of the root node, then the new tree would
\r
4867 be the same as the result tree, with the following possible
\r
4873 <p>The order of attributes in the two trees may be
\r
4878 <p>The new tree may contain namespace nodes that were not
\r
4879 present in the result tree.</p>
\r
4881 <b>NOTE: </b>An XSLT processor may need to add
\r
4882 namespace declarations in the course of outputting the result tree as
\r
4888 <p>If the XSLT processor generated a document type declaration because
\r
4889 of the <code>doctype-system</code> attribute, then the above
\r
4890 requirements apply to the entity with the generated document type
\r
4891 declaration removed.</p>
\r
4893 <p>The <code>version</code> attribute specifies the version of XML to
\r
4894 be used for outputting the result tree. If the XSLT processor does
\r
4895 not support this version of XML, it should use a version of XML that
\r
4896 it does support. The version output in the XML declaration (if an XML
\r
4897 declaration is output) should correspond to the version of XML that
\r
4898 the processor used for outputting the result tree. The value of the
\r
4899 <code>version</code> attribute should match the <a href="http://www.w3.org/TR/REC-xml#NT-VersionNum">VersionNum</a> production of the XML
\r
4900 Recommendation <a href="#XML">[XML]</a>. The default value is
\r
4901 <code>1.0</code>.</p>
\r
4903 <p>The <code>encoding</code> attribute specifies the preferred
\r
4904 encoding to use for outputting the result tree. XSLT processors are
\r
4905 required to respect values of <code>UTF-8</code> and
\r
4906 <code>UTF-16</code>. For other values, if the XSLT processor does not
\r
4907 support the specified encoding it may signal an error; if it does not
\r
4908 signal an error it should use <code>UTF-8</code> or
\r
4909 <code>UTF-16</code> instead. The XSLT processor must not use an
\r
4910 encoding whose name does not match the <a href="http://www.w3.org/TR/REC-xml#NT-EncName">EncName</a> production of the XML
\r
4911 Recommendation <a href="#XML">[XML]</a>. If no <code>encoding</code>
\r
4912 attribute is specified, then the XSLT processor should use either
\r
4913 <code>UTF-8</code> or <code>UTF-16</code>. It is possible that the
\r
4914 result tree will contain a character that cannot be represented in the
\r
4915 encoding that the XSLT processor is using for output. In this case,
\r
4916 if the character occurs in a context where XML recognizes character
\r
4917 references (i.e. in the value of an attribute node or text node), then
\r
4918 the character should be output as a character reference; otherwise
\r
4919 (for example if the character occurs in the name of an element) the
\r
4920 XSLT processor should signal an error.</p>
\r
4922 <p>If the <code>indent</code> attribute has the value
\r
4923 <code>yes</code>, then the <code>xml</code> output method may output
\r
4924 whitespace in addition to the whitespace in the result tree (possibly
\r
4925 based on whitespace stripped from either the source document or the
\r
4926 stylesheet) in order to indent the result nicely; if the
\r
4927 <code>indent</code> attribute has the value <code>no</code>, it should
\r
4928 not output any additional whitespace. The default value is
\r
4929 <code>no</code>. The <code>xml</code> output method should use an
\r
4930 algorithm to output additional whitespace that ensures that the result
\r
4931 if whitespace were to be stripped from the output using the process
\r
4932 described in <a href="#strip">[<b>3.4 Whitespace Stripping</b>]</a> with the set of
\r
4933 whitespace-preserving elements consisting of just
\r
4934 <code>xsl:text</code> would be the same when additional whitespace is
\r
4935 output as when additional whitespace is not output.</p>
\r
4938 <b>NOTE: </b>It is usually not safe to use <code>indent="yes"</code> with
\r
4939 document types that include element types with mixed content.</blockquote>
\r
4941 <p>The <code>cdata-section-elements</code> attribute contains a
\r
4942 whitespace-separated list of <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>s. Each <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> is expanded into an
\r
4943 expanded-name using the namespace declarations in effect on the
\r
4944 <code>xsl:output</code> element in which the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> occurs; if there is a default
\r
4945 namespace, it is used for <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a>s
\r
4946 that do not have a prefix. The expansion is performed before the
\r
4947 merging of multiple <code>xsl:output</code> elements into a single
\r
4948 effective <code>xsl:output</code> element. If the expanded-name of the
\r
4949 parent of a text node is a member of the list, then the text node
\r
4950 should be output as a CDATA section. For example,</p>
\r
4952 <pre><xsl:output cdata-section-elements="example"/></pre>
\r
4954 <p>would cause a literal result element written in the stylesheet as</p>
\r
4956 <pre><example>&lt;foo></example></pre>
\r
4960 <pre><example><![CDATA[<foo>]]></example></pre>
\r
4962 <p>to be output as</p>
\r
4964 <pre><example><![CDATA[<foo>]]></example></pre>
\r
4966 <p>If the text node contains the sequence of characters
\r
4967 <code>]]></code>, then the currently open CDATA section should be
\r
4968 closed following the <code>]]</code> and a new CDATA section opened
\r
4969 before the <code>></code>. For example, a literal result element
\r
4970 written in the stylesheet as</p>
\r
4972 <pre><example>]]&gt;</example></pre>
\r
4974 <p>would be output as</p>
\r
4976 <pre><example><![CDATA[]]]]><![CDATA[>]]></example></pre>
\r
4978 <p>If the text node contains a character that is not representable in
\r
4979 the character encoding being used to output the result tree, then the
\r
4980 currently open CDATA section should be closed before the character,
\r
4981 the character should be output using a character reference or entity
\r
4982 reference, and a new CDATA section should be opened for any further
\r
4983 characters in the text node.</p>
\r
4985 <p>CDATA sections should not be used except for text nodes that the
\r
4986 <code>cdata-section-elements</code> attribute explicitly specifies
\r
4987 should be output using CDATA sections.</p>
\r
4989 <p>The <code>xml</code> output method should output an XML declaration
\r
4990 unless the <code>omit-xml-declaration</code> attribute has the value
\r
4991 <code>yes</code>. The XML declaration should include both version
\r
4992 information and an encoding declaration. If the
\r
4993 <code>standalone</code> attribute is specified, it should include a
\r
4994 standalone document declaration with the same value as the value as
\r
4995 the value of the <code>standalone</code> attribute. Otherwise, it
\r
4996 should not include a standalone document declaration; this ensures
\r
4997 that it is both a XML declaration (allowed at the beginning of a
\r
4998 document entity) and a text declaration (allowed at the beginning of
\r
4999 an external general parsed entity).</p>
\r
5001 <p>If the <code>doctype-system</code> attribute is specified, the
\r
5002 <code>xml</code> output method should output a document type
\r
5003 declaration immediately before the first element. The name following
\r
5004 <code><!DOCTYPE</code> should be the name of the first element. If
\r
5005 <code>doctype-public</code> attribute is also specified, then the
\r
5006 <code>xml</code> output method should output <code>PUBLIC</code>
\r
5007 followed by the public identifier and then the system identifier;
\r
5008 otherwise, it should output <code>SYSTEM</code> followed by the system
\r
5009 identifier. The internal subset should be empty. The
\r
5010 <code>doctype-public</code> attribute should be ignored unless the
\r
5011 <code>doctype-system</code> attribute is specified.</p>
\r
5013 <p>The <code>media-type</code> attribute is applicable for the
\r
5014 <code>xml</code> output method. The default value for the
\r
5015 <code>media-type</code> attribute is <code>text/xml</code>.</p>
\r
5021 <a name="section-HTML-Output-Method"></a>16.2 HTML Output Method</h3>
\r
5023 <p>The <code>html</code> output method outputs the result tree as
\r
5024 HTML; for example,</p>
\r
5026 <pre><xsl:stylesheet version="1.0"
\r
5027 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
\r
5029 <xsl:output method="html"/>
\r
5031 <xsl:template match="/">
\r
5033 <xsl:apply-templates/>
\r
5035 </xsl:template>
\r
5039 </xsl:stylesheet></pre>
\r
5041 <p>The <code>version</code> attribute indicates the version of the
\r
5042 HTML. The default value is <code>4.0</code>, which specifies that the
\r
5043 result should be output as HTML conforming to the HTML 4.0
\r
5044 Recommendation <a href="#HTML">[HTML]</a>.</p>
\r
5046 <p>The <code>html</code> output method should not output an element
\r
5047 differently from the <code>xml</code> output method unless the
\r
5048 expanded-name of the element has a null namespace URI; an element
\r
5049 whose expanded-name has a non-null namespace URI should be output as
\r
5050 XML. If the expanded-name of the element has a null namespace URI,
\r
5051 but the local part of the expanded-name is not recognized as the name
\r
5052 of an HTML element, the element should output in the same way as a
\r
5053 non-empty, inline element such as <code>span</code>.</p>
\r
5055 <p>The <code>html</code> output method should not output an end-tag
\r
5056 for empty elements. For HTML 4.0, the empty elements are
\r
5057 <code>area</code>, <code>base</code>, <code>basefont</code>,
\r
5058 <code>br</code>, <code>col</code>, <code>frame</code>,
\r
5059 <code>hr</code>, <code>img</code>, <code>input</code>,
\r
5060 <code>isindex</code>, <code>link</code>, <code>meta</code> and
\r
5061 <code>param</code>. For example, an element written as
\r
5062 <code><br/></code> or <code><br></br></code> in the
\r
5063 stylesheet should be output as <code><br></code>.</p>
\r
5065 <p>The <code>html</code> output method should recognize the names of
\r
5066 HTML elements regardless of case. For example, elements named
\r
5067 <code>br</code>, <code>BR</code> or <code>Br</code> should all be
\r
5068 recognized as the HTML <code>br</code> element and output without an
\r
5071 <p>The <code>html</code> output method should not perform escaping for
\r
5072 the content of the <code>script</code> and <code>style</code>
\r
5073 elements. For example, a literal result element written in the
\r
5076 <pre><script>if (a &lt; b) foo()</script></pre>
\r
5080 <pre><script><![CDATA[if (a < b) foo()]]></script></pre>
\r
5082 <p>should be output as</p>
\r
5084 <pre><script>if (a < b) foo()</script></pre>
\r
5086 <p>The <code>html</code> output method should not escape
\r
5087 <code><</code> characters occurring in attribute values.</p>
\r
5089 <p>If the <code>indent</code> attribute has the value
\r
5090 <code>yes</code>, then the <code>html</code> output method may add or
\r
5091 remove whitespace as it outputs the result tree, so long as it does
\r
5092 not change how an HTML user agent would render the output. The
\r
5093 default value is <code>yes</code>.</p>
\r
5095 <p>The <code>html</code> output method should escape non-ASCII
\r
5096 characters in URI attribute values using the method recommended in
\r
5097 <a href="http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.2.1">Section
\r
5098 B.2.1</a> of the HTML 4.0 Recommendation.</p>
\r
5100 <p>The <code>html</code> output method may output a character using a
\r
5101 character entity reference, if one is defined for it in the version of
\r
5102 HTML that the output method is using.</p>
\r
5104 <p>The <code>html</code> output method should terminate processing
\r
5105 instructions with <code>></code> rather than
\r
5106 <code>?></code>.</p>
\r
5108 <p>The <code>html</code> output method should output boolean
\r
5109 attributes (that is attributes with only a single allowed value that
\r
5110 is equal to the name of the attribute) in minimized form. For example,
\r
5111 a start-tag written in the stylesheet as</p>
\r
5113 <pre><OPTION selected="selected"></pre>
\r
5115 <p>should be output as</p>
\r
5117 <pre><OPTION selected></pre>
\r
5119 <p>The <code>html</code> output method should not escape a
\r
5120 <code>&</code> character occurring in an attribute value
\r
5121 immediately followed by a <code>{</code> character (see <a href="http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.7.1.1">Section
\r
5122 B.7.1</a> of the HTML 4.0 Recommendation). For example, a start-tag
\r
5123 written in the stylesheet as</p>
\r
5125 <pre><BODY bgcolor='&amp;{{randomrbg}};'></pre>
\r
5127 <p>should be output as</p>
\r
5129 <pre><BODY bgcolor='&{randomrbg};'></pre>
\r
5131 <p>The <code>encoding</code> attribute specifies the preferred
\r
5132 encoding to be used. If there is a <code>HEAD</code> element, then the
\r
5133 <code>html</code> output method should add a <code>META</code> element
\r
5134 immediately after the start-tag of the <code>HEAD</code> element
\r
5135 specifying the character encoding actually used. For example,</p>
\r
5138 <META http-equiv="Content-Type" content="text/html; charset=EUC-JP">
\r
5141 <p>It is possible that the result tree will contain a character that
\r
5142 cannot be represented in the encoding that the XSLT processor is using
\r
5143 for output. In this case, if the character occurs in a context where
\r
5144 HTML recognizes character references, then the character should be
\r
5145 output as a character entity reference or decimal numeric character
\r
5146 reference; otherwise (for example, in a
\r
5147 <code>script</code> or <code>style</code> element or in a comment),
\r
5148 the XSLT processor should signal an error.</p>
\r
5150 <p>If the <code>doctype-public</code> or <code>doctype-system</code>
\r
5151 attributes are specified, then the <code>html</code> output method
\r
5152 should output a document type declaration immediately before the first
\r
5153 element. The name following <code><!DOCTYPE</code> should be
\r
5154 <code>HTML</code> or <code>html</code>. If the
\r
5155 <code>doctype-public</code> attribute is specified, then the output
\r
5156 method should output <code>PUBLIC</code> followed by the specified
\r
5157 public identifier; if the <code>doctype-system</code> attribute is
\r
5158 also specified, it should also output the specified system identifier
\r
5159 following the public identifier. If the <code>doctype-system</code>
\r
5160 attribute is specified but the <code>doctype-public</code> attribute
\r
5161 is not specified, then the output method should output
\r
5162 <code>SYSTEM</code> followed by the specified system identifier.</p>
\r
5164 <p>The <code>media-type</code> attribute is applicable for the
\r
5165 <code>html</code> output method. The default value is
\r
5166 <code>text/html</code>.</p>
\r
5172 <a name="section-Text-Output-Method"></a>16.3 Text Output Method</h3>
\r
5174 <p>The <code>text</code> output method outputs the result tree by
\r
5175 outputting the string-value of every text node in the result tree in
\r
5176 document order without any escaping.</p>
\r
5178 <p>The <code>media-type</code> attribute is applicable for the
\r
5179 <code>text</code> output method. The default value for the
\r
5180 <code>media-type</code> attribute is <code>text/plain</code>.</p>
\r
5182 <p>The <code>encoding</code> attribute identifies the encoding that
\r
5183 the <code>text</code> output method should use to convert sequences of
\r
5184 characters to sequences of bytes. The default is system-dependent. If
\r
5185 the result tree contains a character that cannot be represented in the
\r
5186 encoding that the XSLT processor is using for output, the XSLT
\r
5187 processor should signal an error.</p>
\r
5193 <a name="disable-output-escaping"></a>16.4 Disabling Output Escaping</h3>
\r
5195 <p>Normally, the <code>xml</code> output method escapes & and <
\r
5196 (and possibly other characters) when outputting text nodes. This
\r
5197 ensures that the output is well-formed XML. However, it is sometimes
\r
5198 convenient to be able to produce output that is almost, but not quite
\r
5199 well-formed XML; for example, the output may include ill-formed
\r
5200 sections which are intended to be transformed into well-formed XML by
\r
5201 a subsequent non-XML aware process. For this reason, XSLT provides a
\r
5202 mechanism for disabling output escaping. An <code>xsl:value-of</code>
\r
5203 or <code>xsl:text</code> element may have a
\r
5204 <code>disable-output-escaping</code> attribute; the allowed values are
\r
5205 <code>yes</code> or <code>no</code>; the default is <code>no</code>;
\r
5206 if the value is <code>yes</code>, then a text node generated by
\r
5207 instantiating the <code>xsl:value-of</code> or <code>xsl:text</code>
\r
5208 element should be output without any escaping. For example,</p>
\r
5210 <pre><xsl:text disable-output-escaping="yes">&lt;</xsl:text></pre>
\r
5212 <p>should generate the single character <code><</code>.</p>
\r
5214 <p>It is an error for output escaping to be disabled for a text node
\r
5215 that is used for something other than a text node in the result tree.
\r
5216 Thus, it is an error to disable output escaping for an
\r
5217 <code>xsl:value-of</code> or <code>xsl:text</code> element that is
\r
5218 used to generate the string-value of a comment, processing instruction
\r
5219 or attribute node; it is also an error to convert a <a href="#dt-result-tree-fragment">result tree fragment</a> to a
\r
5220 number or a string if the result tree fragment contains a text node for
\r
5221 which escaping was disabled. In both cases, an XSLT processor may
\r
5222 signal the error; if it does not signal the error, it must recover by
\r
5223 ignoring the <code>disable-output-escaping</code> attribute.</p>
\r
5225 <p>The <code>disable-output-escaping</code> attribute may be used with
\r
5226 the <code>html</code> output method as well as with the
\r
5227 <code>xml</code> output method. The <code>text</code> output method
\r
5228 ignores the <code>disable-output-escaping</code> attribute, since it
\r
5229 does not perform any output escaping.</p>
\r
5231 <p>An XSLT processor will only be able to disable output escaping if
\r
5232 it controls how the result tree is output. This may not always be the
\r
5233 case. For example, the result tree may be used as the source tree for
\r
5234 another XSLT transformation instead of being output. An XSLT
\r
5235 processor is not required to support disabling output escaping. If an
\r
5236 <code>xsl:value-of</code> or <code>xsl:text</code> specifies that
\r
5237 output escaping should be disabled and the XSLT processor does not
\r
5238 support this, the XSLT processor may signal an error; if it does not
\r
5239 signal an error, it must recover by not disabling output escaping.</p>
\r
5241 <p>If output escaping is disabled for a character that is not
\r
5242 representable in the encoding that the XSLT processor is using for
\r
5243 output, then the XSLT processor may signal an error; if it does not
\r
5244 signal an error, it must recover by not disabling output escaping.</p>
\r
5246 <p>Since disabling output escaping may not work with all XSLT
\r
5247 processors and can result in XML that is not well-formed, it should be
\r
5248 used only when there is no alternative.</p>
\r
5257 <a name="conformance"></a>17 Conformance</h2>
\r
5259 <p>A conforming XSLT processor must be able to use a stylesheet to
\r
5260 transform a source tree into a result tree as specified in this
\r
5261 document. A conforming XSLT processor need not be able to output the
\r
5262 result in XML or in any other form.</p>
\r
5265 <b>NOTE: </b>Vendors of XSLT processors are strongly encouraged to provide
\r
5266 a way to verify that their processor is behaving conformingly by
\r
5267 allowing the result tree to be output as XML or by providing access to
\r
5268 the result tree through a standard API such as the DOM or
\r
5271 <p>A conforming XSLT processor must signal any errors except for those
\r
5272 that this document specifically allows an XSLT processor not to
\r
5273 signal. A conforming XSLT processor may but need not recover from any
\r
5274 errors that it signals.</p>
\r
5276 <p>A conforming XSLT processor may impose limits on the processing
\r
5277 resources consumed by the processing of a stylesheet.</p>
\r
5283 <a name="notation"></a>18 Notation</h2>
\r
5285 <p>The specification of each XSLT-defined element type is preceded by
\r
5286 a summary of its syntax in the form of a model for elements of that
\r
5287 element type. The meaning of syntax summary notation is as
\r
5293 <p>An attribute is required if and only if its name is in
\r
5298 <p>The string that occurs in the place of an attribute value
\r
5299 specifies the allowed values of the attribute. If this is surrounded
\r
5300 by curly braces, then the attribute value is treated as an <a href="#dt-attribute-value-template">attribute value template</a>,
\r
5301 and the string occurring within curly braces specifies the allowed
\r
5302 values of the result of instantiating the attribute value template.
\r
5303 Alternative allowed values are separated by <code>|</code>. A quoted
\r
5304 string indicates a value equal to that specific string. An unquoted,
\r
5305 italicized name specifies a particular type of value.</p>
\r
5309 <p>If the element is allowed not to be empty, then the element
\r
5310 contains a comment specifying the allowed content. The allowed
\r
5311 content is specified in a similar way to an element type declaration
\r
5312 in XML; <i>template</i> means that any mixture of text nodes,
\r
5313 literal result elements, extension elements, and XSLT elements from
\r
5314 the <code>instruction</code> category is allowed;
\r
5315 <i>top-level-elements</i> means that any mixture of XSLT
\r
5316 elements from the <code>top-level-element</code> category is
\r
5321 <p>The element is prefaced by comments indicating if it belongs
\r
5322 to the <code>instruction</code> category or
\r
5323 <code>top-level-element</code> category or both. The category of an
\r
5324 element just affects whether it is allowed in the content of elements
\r
5325 that allow a <i>template</i> or
\r
5326 <i>top-level-elements</i>.</p>
\r
5335 <hr title="Separator from footer">
\r
5338 <a name="section-References"></a>A References</h2>
\r
5341 <a name="section-Normative-References"></a>A.1 Normative References</h3>
\r
5346 <a name="XML">XML</a>
\r
5348 <dd>World Wide Web Consortium. <i>Extensible
\r
5349 Markup Language (XML) 1.0.</i> W3C Recommendation. See <a href="http://www.w3.org/TR/1998/REC-xml-19980210">http://www.w3.org/TR/1998/REC-xml-19980210</a>
\r
5353 <a name="XMLNAMES">XML Names</a>
\r
5355 <dd>World Wide Web
\r
5356 Consortium. <i>Namespaces in XML.</i> W3C Recommendation. See
\r
5357 <a href="http://www.w3.org/TR/REC-xml-names">http://www.w3.org/TR/REC-xml-names</a>
\r
5361 <a name="XPATH">XPath</a>
\r
5363 <dd>World Wide Web Consortium. <i>XML Path
\r
5364 Language.</i> W3C Recommendation. See <a href="http://www.w3.org/TR/xpath">http://www.w3.org/TR/xpath</a>
\r
5371 <a name="section-Other-References"></a>A.2 Other References</h3>
\r
5376 <a name="CSS2">CSS2</a>
\r
5378 <dd>World Wide Web Consortium. <i>Cascading
\r
5379 Style Sheets, level 2 (CSS2)</i>. W3C Recommendation. See <a href="http://www.w3.org/TR/1998/REC-CSS2-19980512">http://www.w3.org/TR/1998/REC-CSS2-19980512</a>
\r
5383 <a name="DSSSL">DSSSL</a>
\r
5385 <dd>International Organization
\r
5386 for Standardization, International Electrotechnical Commission.
\r
5387 <i>ISO/IEC 10179:1996. Document Style Semantics and Specification
\r
5388 Language (DSSSL)</i>. International Standard.</dd>
\r
5391 <a name="HTML">HTML</a>
\r
5393 <dd>World Wide Web Consortium. <i>HTML 4.0
\r
5394 specification</i>. W3C Recommendation. See <a href="http://www.w3.org/TR/REC-html40">http://www.w3.org/TR/REC-html40</a>
\r
5398 <a name="IANA">IANA</a>
\r
5400 <dd>Internet Assigned Numbers
\r
5401 Authority. <i>Character Sets</i>. See <a href="ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets">ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets</a>.</dd>
\r
5404 <a name="RFC2278">RFC2278</a>
\r
5406 <dd>N. Freed, J. Postel. <i>IANA
\r
5407 Charset Registration Procedures</i>. IETF RFC 2278. See <a href="http://www.ietf.org/rfc/rfc2278.txt">http://www.ietf.org/rfc/rfc2278.txt</a>.</dd>
\r
5410 <a name="RFC2376">RFC2376</a>
\r
5412 <dd>E. Whitehead, M. Murata. <i>XML
\r
5413 Media Types</i>. IETF RFC 2376. See <a href="http://www.ietf.org/rfc/rfc2376.txt">http://www.ietf.org/rfc/rfc2376.txt</a>.</dd>
\r
5416 <a name="RFC2396">RFC2396</a>
\r
5418 <dd>T. Berners-Lee, R. Fielding, and
\r
5419 L. Masinter. <i>Uniform Resource Identifiers (URI): Generic
\r
5420 Syntax</i>. IETF RFC 2396. See <a href="http://www.ietf.org/rfc/rfc2396.txt">http://www.ietf.org/rfc/rfc2396.txt</a>.</dd>
\r
5423 <a name="UNICODE-TR10">UNICODE TR10</a>
\r
5425 <dd>Unicode Consortium.
\r
5426 <i>Unicode Technical Report #10. Unicode Collation
\r
5427 Algorithm</i>. Unicode Technical Report. See <a href="http://www.unicode.org/unicode/reports/tr10/index.html">http://www.unicode.org/unicode/reports/tr10/index.html</a>.</dd>
\r
5430 <a name="XHTML">XHTML</a>
\r
5432 <dd>World Wide Web Consortium. <i>XHTML
\r
5433 1.0: The Extensible HyperText Markup Language.</i> W3C Proposed
\r
5434 Recommendation. See <a href="http://www.w3.org/TR/xhtml1">http://www.w3.org/TR/xhtml1</a>
\r
5438 <a name="XPTR">XPointer</a>
\r
5440 <dd>World Wide Web
\r
5441 Consortium. <i>XML Pointer Language (XPointer).</i> W3C Working
\r
5442 Draft. See <a href="http://www.w3.org/TR/xptr">http://www.w3.org/TR/xptr</a>
\r
5446 <a name="XMLSTYLE">XML Stylesheet</a>
\r
5448 <dd>World Wide Web
\r
5449 Consortium. <i>Associating stylesheets with XML documents.</i>
\r
5450 W3C Recommendation. See <a href="http://www.w3.org/TR/xml-stylesheet">http://www.w3.org/TR/xml-stylesheet</a>
\r
5454 <a name="XSL">XSL</a>
\r
5456 <dd>World Wide Web Consortium. <i>Extensible
\r
5457 Stylesheet Language (XSL).</i> W3C Working Draft. See <a href="http://www.w3.org/TR/WD-xsl">http://www.w3.org/TR/WD-xsl</a>
\r
5467 <a name="element-syntax-summary"></a>B Element Syntax Summary</h2>
\r
5469 <p class="element-syntax-summary">
\r
5470 <code><!-- Category: instruction --><br><<a href="#element-apply-imports">xsl:apply-imports</a> /></code>
\r
5472 <p class="element-syntax-summary">
\r
5473 <code><!-- Category: instruction --><br><<a href="#element-apply-templates">xsl:apply-templates</a>
\r
5474 <br> select = <var>node-set-expression</var>
\r
5475 <br> mode = <var>qname</var>><br> <!-- Content: (<a href="#element-sort">xsl:sort</a> | <a href="#element-with-param">xsl:with-param</a>)* --><br></xsl:apply-templates></code>
\r
5477 <p class="element-syntax-summary">
\r
5478 <code><!-- Category: instruction --><br><<a href="#element-attribute">xsl:attribute</a>
\r
5479 <br> <b>name</b> = { <var>qname</var> }<br> namespace = { <var>uri-reference</var> }><br> <!-- Content: <var>template</var> --><br></xsl:attribute></code>
\r
5481 <p class="element-syntax-summary">
\r
5482 <code><!-- Category: top-level-element --><br><<a href="#element-attribute-set">xsl:attribute-set</a>
\r
5483 <br> <b>name</b> = <var>qname</var>
\r
5484 <br> use-attribute-sets = <var>qnames</var>><br> <!-- Content: <a href="#element-attribute">xsl:attribute</a>* --><br></xsl:attribute-set></code>
\r
5486 <p class="element-syntax-summary">
\r
5487 <code><!-- Category: instruction --><br><<a href="#element-call-template">xsl:call-template</a>
\r
5488 <br> <b>name</b> = <var>qname</var>><br> <!-- Content: <a href="#element-with-param">xsl:with-param</a>* --><br></xsl:call-template></code>
\r
5490 <p class="element-syntax-summary">
\r
5491 <code><!-- Category: instruction --><br><<a href="#element-choose">xsl:choose</a>><br> <!-- Content: (<a href="#element-when">xsl:when</a>+, <a href="#element-otherwise">xsl:otherwise</a>?) --><br></xsl:choose></code>
\r
5493 <p class="element-syntax-summary">
\r
5494 <code><!-- Category: instruction --><br><<a href="#element-comment">xsl:comment</a>><br> <!-- Content: <var>template</var> --><br></xsl:comment></code>
\r
5496 <p class="element-syntax-summary">
\r
5497 <code><!-- Category: instruction --><br><<a href="#element-copy">xsl:copy</a>
\r
5498 <br> use-attribute-sets = <var>qnames</var>><br> <!-- Content: <var>template</var> --><br></xsl:copy></code>
\r
5500 <p class="element-syntax-summary">
\r
5501 <code><!-- Category: instruction --><br><<a href="#element-copy-of">xsl:copy-of</a>
\r
5502 <br> <b>select</b> = <var>expression</var> /></code>
\r
5504 <p class="element-syntax-summary">
\r
5505 <code><!-- Category: top-level-element --><br><<a href="#element-decimal-format">xsl:decimal-format</a>
\r
5506 <br> name = <var>qname</var>
\r
5507 <br> decimal-separator = <var>char</var>
\r
5508 <br> grouping-separator = <var>char</var>
\r
5509 <br> infinity = <var>string</var>
\r
5510 <br> minus-sign = <var>char</var>
\r
5511 <br> NaN = <var>string</var>
\r
5512 <br> percent = <var>char</var>
\r
5513 <br> per-mille = <var>char</var>
\r
5514 <br> zero-digit = <var>char</var>
\r
5515 <br> digit = <var>char</var>
\r
5516 <br> pattern-separator = <var>char</var> /></code>
\r
5518 <p class="element-syntax-summary">
\r
5519 <code><!-- Category: instruction --><br><<a href="#element-element">xsl:element</a>
\r
5520 <br> <b>name</b> = { <var>qname</var> }<br> namespace = { <var>uri-reference</var> }<br> use-attribute-sets = <var>qnames</var>><br> <!-- Content: <var>template</var> --><br></xsl:element></code>
\r
5522 <p class="element-syntax-summary">
\r
5523 <code><!-- Category: instruction --><br><<a href="#element-fallback">xsl:fallback</a>><br> <!-- Content: <var>template</var> --><br></xsl:fallback></code>
\r
5525 <p class="element-syntax-summary">
\r
5526 <code><!-- Category: instruction --><br><<a href="#element-for-each">xsl:for-each</a>
\r
5527 <br> <b>select</b> = <var>node-set-expression</var>><br> <!-- Content: (<a href="#element-sort">xsl:sort</a>*, <var>template</var>) --><br></xsl:for-each></code>
\r
5529 <p class="element-syntax-summary">
\r
5530 <code><!-- Category: instruction --><br><<a href="#element-if">xsl:if</a>
\r
5531 <br> <b>test</b> = <var>boolean-expression</var>><br> <!-- Content: <var>template</var> --><br></xsl:if></code>
\r
5533 <p class="element-syntax-summary">
\r
5534 <code><<a href="#element-import">xsl:import</a>
\r
5535 <br> <b>href</b> = <var>uri-reference</var> /></code>
\r
5537 <p class="element-syntax-summary">
\r
5538 <code><!-- Category: top-level-element --><br><<a href="#element-include">xsl:include</a>
\r
5539 <br> <b>href</b> = <var>uri-reference</var> /></code>
\r
5541 <p class="element-syntax-summary">
\r
5542 <code><!-- Category: top-level-element --><br><<a href="#element-key">xsl:key</a>
\r
5543 <br> <b>name</b> = <var>qname</var>
\r
5544 <br> <b>match</b> = <var>pattern</var>
\r
5545 <br> <b>use</b> = <var>expression</var> /></code>
\r
5547 <p class="element-syntax-summary">
\r
5548 <code><!-- Category: instruction --><br><<a href="#element-message">xsl:message</a>
\r
5549 <br> terminate = "yes" | "no"><br> <!-- Content: <var>template</var> --><br></xsl:message></code>
\r
5551 <p class="element-syntax-summary">
\r
5552 <code><!-- Category: top-level-element --><br><<a href="#element-namespace-alias">xsl:namespace-alias</a>
\r
5553 <br> <b>stylesheet-prefix</b> = <var>prefix</var> | "#default"<br> <b>result-prefix</b> = <var>prefix</var> | "#default" /></code>
\r
5555 <p class="element-syntax-summary">
\r
5556 <code><!-- Category: instruction --><br><<a href="#element-number">xsl:number</a>
\r
5557 <br> level = "single" | "multiple" | "any"<br> count = <var>pattern</var>
\r
5558 <br> from = <var>pattern</var>
\r
5559 <br> value = <var>number-expression</var>
\r
5560 <br> format = { <var>string</var> }<br> lang = { <var>nmtoken</var> }<br> letter-value = { "alphabetic" | "traditional" }<br> grouping-separator = { <var>char</var> }<br> grouping-size = { <var>number</var> } /></code>
\r
5562 <p class="element-syntax-summary">
\r
5563 <code><<a href="#element-otherwise">xsl:otherwise</a>><br> <!-- Content: <var>template</var> --><br></xsl:otherwise></code>
\r
5565 <p class="element-syntax-summary">
\r
5566 <code><!-- Category: top-level-element --><br><<a href="#element-output">xsl:output</a>
\r
5567 <br> method = "xml" | "html" | "text" | <var>qname-but-not-ncname</var>
\r
5568 <br> version = <var>nmtoken</var>
\r
5569 <br> encoding = <var>string</var>
\r
5570 <br> omit-xml-declaration = "yes" | "no"<br> standalone = "yes" | "no"<br> doctype-public = <var>string</var>
\r
5571 <br> doctype-system = <var>string</var>
\r
5572 <br> cdata-section-elements = <var>qnames</var>
\r
5573 <br> indent = "yes" | "no"<br> media-type = <var>string</var> /></code>
\r
5575 <p class="element-syntax-summary">
\r
5576 <code><!-- Category: top-level-element --><br><<a href="#element-param">xsl:param</a>
\r
5577 <br> <b>name</b> = <var>qname</var>
\r
5578 <br> select = <var>expression</var>><br> <!-- Content: <var>template</var> --><br></xsl:param></code>
\r
5580 <p class="element-syntax-summary">
\r
5581 <code><!-- Category: top-level-element --><br><<a href="#element-preserve-space">xsl:preserve-space</a>
\r
5582 <br> <b>elements</b> = <var>tokens</var> /></code>
\r
5584 <p class="element-syntax-summary">
\r
5585 <code><!-- Category: instruction --><br><<a href="#element-processing-instruction">xsl:processing-instruction</a>
\r
5586 <br> <b>name</b> = { <var>ncname</var> }><br> <!-- Content: <var>template</var> --><br></xsl:processing-instruction></code>
\r
5588 <p class="element-syntax-summary">
\r
5589 <code><<a href="#element-sort">xsl:sort</a>
\r
5590 <br> select = <var>string-expression</var>
\r
5591 <br> lang = { <var>nmtoken</var> }<br> data-type = { "text" | "number" | <var>qname-but-not-ncname</var> }<br> order = { "ascending" | "descending" }<br> case-order = { "upper-first" | "lower-first" } /></code>
\r
5593 <p class="element-syntax-summary">
\r
5594 <code><!-- Category: top-level-element --><br><<a href="#element-strip-space">xsl:strip-space</a>
\r
5595 <br> <b>elements</b> = <var>tokens</var> /></code>
\r
5597 <p class="element-syntax-summary">
\r
5598 <code><<a href="#element-stylesheet">xsl:stylesheet</a>
\r
5599 <br> id = <var>id</var>
\r
5600 <br> extension-element-prefixes = <var>tokens</var>
\r
5601 <br> exclude-result-prefixes = <var>tokens</var>
\r
5602 <br> <b>version</b> = <var>number</var>><br> <!-- Content: (<a href="#element-import">xsl:import</a>*, <var>top-level-elements</var>) --><br></xsl:stylesheet></code>
\r
5604 <p class="element-syntax-summary">
\r
5605 <code><!-- Category: top-level-element --><br><<a href="#element-template">xsl:template</a>
\r
5606 <br> match = <var>pattern</var>
\r
5607 <br> name = <var>qname</var>
\r
5608 <br> priority = <var>number</var>
\r
5609 <br> mode = <var>qname</var>><br> <!-- Content: (<a href="#element-param">xsl:param</a>*, <var>template</var>) --><br></xsl:template></code>
\r
5611 <p class="element-syntax-summary">
\r
5612 <code><!-- Category: instruction --><br><<a href="#element-text">xsl:text</a>
\r
5613 <br> disable-output-escaping = "yes" | "no"><br> <!-- Content: #PCDATA --><br></xsl:text></code>
\r
5615 <p class="element-syntax-summary">
\r
5616 <code><<a href="#element-transform">xsl:transform</a>
\r
5617 <br> id = <var>id</var>
\r
5618 <br> extension-element-prefixes = <var>tokens</var>
\r
5619 <br> exclude-result-prefixes = <var>tokens</var>
\r
5620 <br> <b>version</b> = <var>number</var>><br> <!-- Content: (<a href="#element-import">xsl:import</a>*, <var>top-level-elements</var>) --><br></xsl:transform></code>
\r
5622 <p class="element-syntax-summary">
\r
5623 <code><!-- Category: instruction --><br><<a href="#element-value-of">xsl:value-of</a>
\r
5624 <br> <b>select</b> = <var>string-expression</var>
\r
5625 <br> disable-output-escaping = "yes" | "no" /></code>
\r
5627 <p class="element-syntax-summary">
\r
5628 <code><!-- Category: top-level-element --><br><!-- Category: instruction --><br><<a href="#element-variable">xsl:variable</a>
\r
5629 <br> <b>name</b> = <var>qname</var>
\r
5630 <br> select = <var>expression</var>><br> <!-- Content: <var>template</var> --><br></xsl:variable></code>
\r
5632 <p class="element-syntax-summary">
\r
5633 <code><<a href="#element-when">xsl:when</a>
\r
5634 <br> <b>test</b> = <var>boolean-expression</var>><br> <!-- Content: <var>template</var> --><br></xsl:when></code>
\r
5636 <p class="element-syntax-summary">
\r
5637 <code><<a href="#element-with-param">xsl:with-param</a>
\r
5638 <br> <b>name</b> = <var>qname</var>
\r
5639 <br> select = <var>expression</var>><br> <!-- Content: <var>template</var> --><br></xsl:with-param></code>
\r
5646 <a name="dtd"></a>C DTD Fragment for XSLT Stylesheets (Non-Normative)</h2>
\r
5649 <b>NOTE: </b>This DTD Fragment is not normative because XML 1.0 DTDs do
\r
5650 not support XML Namespaces and thus cannot correctly describe the
\r
5651 allowed structure of an XSLT stylesheet.</blockquote>
\r
5653 <p>The following entity can be used to construct a DTD for XSLT
\r
5654 stylesheets that create instances of a particular result DTD. Before
\r
5655 referencing the entity, the stylesheet DTD must define a
\r
5656 <code>result-elements</code> parameter entity listing the allowed
\r
5657 result element types. For example:</p>
\r
5659 <pre><!ENTITY % result-elements "
\r
5660 | fo:inline-sequence
\r
5664 <p>Such result elements should be declared to have
\r
5665 <code>xsl:use-attribute-sets</code> and
\r
5666 <code>xsl:extension-element-prefixes</code> attributes. The following
\r
5667 entity declares the <code>result-element-atts</code> parameter for
\r
5668 this purpose. The content that XSLT allows for result elements is the
\r
5669 same as it allows for the XSLT elements that are declared in the
\r
5670 following entity with a content model of <code>%template;</code>. The
\r
5671 DTD may use a more restrictive content model than
\r
5672 <code>%template;</code> to reflect the constraints of the result
\r
5675 <p>The DTD may define the <code>non-xsl-top-level</code> parameter
\r
5676 entity to allow additional top-level elements from namespaces other
\r
5677 than the XSLT namespace.</p>
\r
5679 <p>The use of the <code>xsl:</code> prefix in this DTD does not imply
\r
5680 that XSLT stylesheets are required to use this prefix. Any of the
\r
5681 elements declared in this DTD may have attributes whose name starts
\r
5682 with <code>xmlns:</code> or is equal to <code>xmlns</code> in addition
\r
5683 to the attributes declared in this DTD.</p>
\r
5685 <pre><!ENTITY % char-instructions "
\r
5686 | xsl:apply-templates
\r
5687 | xsl:call-template
\r
5688 | xsl:apply-imports
\r
5702 <!ENTITY % instructions "
\r
5703 %char-instructions;
\r
5704 | xsl:processing-instruction
\r
5710 <!ENTITY % char-template "
\r
5712 %char-instructions;)*
\r
5715 <!ENTITY % template "
\r
5718 %result-elements;)*
\r
5721 <!-- Used for the type of an attribute value that is a URI reference.-->
\r
5722 <!ENTITY % URI "CDATA">
\r
5724 <!-- Used for the type of an attribute value that is a pattern.-->
\r
5725 <!ENTITY % pattern "CDATA">
\r
5727 <!-- Used for the type of an attribute value that is an
\r
5728 attribute value template.-->
\r
5729 <!ENTITY % avt "CDATA">
\r
5731 <!-- Used for the type of an attribute value that is a QName; the prefix
\r
5732 gets expanded by the XSLT processor. -->
\r
5733 <!ENTITY % qname "NMTOKEN">
\r
5735 <!-- Like qname but a whitespace-separated list of QNames. -->
\r
5736 <!ENTITY % qnames "NMTOKENS">
\r
5738 <!-- Used for the type of an attribute value that is an expression.-->
\r
5739 <!ENTITY % expr "CDATA">
\r
5741 <!-- Used for the type of an attribute value that consists
\r
5742 of a single character.-->
\r
5743 <!ENTITY % char "CDATA">
\r
5745 <!-- Used for the type of an attribute value that is a priority. -->
\r
5746 <!ENTITY % priority "NMTOKEN">
\r
5748 <!ENTITY % space-att "xml:space (default|preserve) #IMPLIED">
\r
5750 <!-- This may be overridden to customize the set of elements allowed
\r
5751 at the top-level. -->
\r
5753 <!ENTITY % non-xsl-top-level "">
\r
5755 <!ENTITY % top-level "
\r
5759 | xsl:preserve-space
\r
5762 | xsl:decimal-format
\r
5763 | xsl:attribute-set
\r
5767 | xsl:namespace-alias
\r
5768 %non-xsl-top-level;)*)
\r
5771 <!ENTITY % top-level-atts '
\r
5772 extension-element-prefixes CDATA #IMPLIED
\r
5773 exclude-result-prefixes CDATA #IMPLIED
\r
5775 version NMTOKEN #REQUIRED
\r
5776 xmlns:xsl CDATA #FIXED "http://www.w3.org/1999/XSL/Transform"
\r
5780 <!-- This entity is defined for use in the ATTLIST declaration
\r
5781 for result elements. -->
\r
5783 <!ENTITY % result-element-atts '
\r
5784 xsl:extension-element-prefixes CDATA #IMPLIED
\r
5785 xsl:exclude-result-prefixes CDATA #IMPLIED
\r
5786 xsl:use-attribute-sets %qnames; #IMPLIED
\r
5787 xsl:version NMTOKEN #IMPLIED
\r
5790 <!ELEMENT xsl:stylesheet %top-level;>
\r
5791 <!ATTLIST xsl:stylesheet %top-level-atts;>
\r
5793 <!ELEMENT xsl:transform %top-level;>
\r
5794 <!ATTLIST xsl:transform %top-level-atts;>
\r
5796 <!ELEMENT xsl:import EMPTY>
\r
5797 <!ATTLIST xsl:import href %URI; #REQUIRED>
\r
5799 <!ELEMENT xsl:include EMPTY>
\r
5800 <!ATTLIST xsl:include href %URI; #REQUIRED>
\r
5802 <!ELEMENT xsl:strip-space EMPTY>
\r
5803 <!ATTLIST xsl:strip-space elements CDATA #REQUIRED>
\r
5805 <!ELEMENT xsl:preserve-space EMPTY>
\r
5806 <!ATTLIST xsl:preserve-space elements CDATA #REQUIRED>
\r
5808 <!ELEMENT xsl:output EMPTY>
\r
5809 <!ATTLIST xsl:output
\r
5810 method %qname; #IMPLIED
\r
5811 version NMTOKEN #IMPLIED
\r
5812 encoding CDATA #IMPLIED
\r
5813 omit-xml-declaration (yes|no) #IMPLIED
\r
5814 standalone (yes|no) #IMPLIED
\r
5815 doctype-public CDATA #IMPLIED
\r
5816 doctype-system CDATA #IMPLIED
\r
5817 cdata-section-elements %qnames; #IMPLIED
\r
5818 indent (yes|no) #IMPLIED
\r
5819 media-type CDATA #IMPLIED
\r
5822 <!ELEMENT xsl:key EMPTY>
\r
5823 <!ATTLIST xsl:key
\r
5824 name %qname; #REQUIRED
\r
5825 match %pattern; #REQUIRED
\r
5826 use %expr; #REQUIRED
\r
5829 <!ELEMENT xsl:decimal-format EMPTY>
\r
5830 <!ATTLIST xsl:decimal-format
\r
5831 name %qname; #IMPLIED
\r
5832 decimal-separator %char; "."
\r
5833 grouping-separator %char; ","
\r
5834 infinity CDATA "Infinity"
\r
5835 minus-sign %char; "-"
\r
5837 percent %char; "%"
\r
5838 per-mille %char; "&#x2030;"
\r
5839 zero-digit %char; "0"
\r
5841 pattern-separator %char; ";"
\r
5844 <!ELEMENT xsl:namespace-alias EMPTY>
\r
5845 <!ATTLIST xsl:namespace-alias
\r
5846 stylesheet-prefix CDATA #REQUIRED
\r
5847 result-prefix CDATA #REQUIRED
\r
5850 <!ELEMENT xsl:template
\r
5857 <!ATTLIST xsl:template
\r
5858 match %pattern; #IMPLIED
\r
5859 name %qname; #IMPLIED
\r
5860 priority %priority; #IMPLIED
\r
5861 mode %qname; #IMPLIED
\r
5865 <!ELEMENT xsl:value-of EMPTY>
\r
5866 <!ATTLIST xsl:value-of
\r
5867 select %expr; #REQUIRED
\r
5868 disable-output-escaping (yes|no) "no"
\r
5871 <!ELEMENT xsl:copy-of EMPTY>
\r
5872 <!ATTLIST xsl:copy-of select %expr; #REQUIRED>
\r
5874 <!ELEMENT xsl:number EMPTY>
\r
5875 <!ATTLIST xsl:number
\r
5876 level (single|multiple|any) "single"
\r
5877 count %pattern; #IMPLIED
\r
5878 from %pattern; #IMPLIED
\r
5879 value %expr; #IMPLIED
\r
5881 lang %avt; #IMPLIED
\r
5882 letter-value %avt; #IMPLIED
\r
5883 grouping-separator %avt; #IMPLIED
\r
5884 grouping-size %avt; #IMPLIED
\r
5887 <!ELEMENT xsl:apply-templates (xsl:sort|xsl:with-param)*>
\r
5888 <!ATTLIST xsl:apply-templates
\r
5889 select %expr; "node()"
\r
5890 mode %qname; #IMPLIED
\r
5893 <!ELEMENT xsl:apply-imports EMPTY>
\r
5895 <!-- xsl:sort cannot occur after any other elements or
\r
5896 any non-whitespace character -->
\r
5898 <!ELEMENT xsl:for-each
\r
5905 <!ATTLIST xsl:for-each
\r
5906 select %expr; #REQUIRED
\r
5910 <!ELEMENT xsl:sort EMPTY>
\r
5911 <!ATTLIST xsl:sort
\r
5913 lang %avt; #IMPLIED
\r
5914 data-type %avt; "text"
\r
5915 order %avt; "ascending"
\r
5916 case-order %avt; #IMPLIED
\r
5919 <!ELEMENT xsl:if %template;>
\r
5920 <!ATTLIST xsl:if
\r
5921 test %expr; #REQUIRED
\r
5925 <!ELEMENT xsl:choose (xsl:when+, xsl:otherwise?)>
\r
5926 <!ATTLIST xsl:choose %space-att;>
\r
5928 <!ELEMENT xsl:when %template;>
\r
5929 <!ATTLIST xsl:when
\r
5930 test %expr; #REQUIRED
\r
5934 <!ELEMENT xsl:otherwise %template;>
\r
5935 <!ATTLIST xsl:otherwise %space-att;>
\r
5937 <!ELEMENT xsl:attribute-set (xsl:attribute)*>
\r
5938 <!ATTLIST xsl:attribute-set
\r
5939 name %qname; #REQUIRED
\r
5940 use-attribute-sets %qnames; #IMPLIED
\r
5943 <!ELEMENT xsl:call-template (xsl:with-param)*>
\r
5944 <!ATTLIST xsl:call-template
\r
5945 name %qname; #REQUIRED
\r
5948 <!ELEMENT xsl:with-param %template;>
\r
5949 <!ATTLIST xsl:with-param
\r
5950 name %qname; #REQUIRED
\r
5951 select %expr; #IMPLIED
\r
5954 <!ELEMENT xsl:variable %template;>
\r
5955 <!ATTLIST xsl:variable
\r
5956 name %qname; #REQUIRED
\r
5957 select %expr; #IMPLIED
\r
5960 <!ELEMENT xsl:param %template;>
\r
5961 <!ATTLIST xsl:param
\r
5962 name %qname; #REQUIRED
\r
5963 select %expr; #IMPLIED
\r
5966 <!ELEMENT xsl:text (#PCDATA)>
\r
5967 <!ATTLIST xsl:text
\r
5968 disable-output-escaping (yes|no) "no"
\r
5971 <!ELEMENT xsl:processing-instruction %char-template;>
\r
5972 <!ATTLIST xsl:processing-instruction
\r
5973 name %avt; #REQUIRED
\r
5977 <!ELEMENT xsl:element %template;>
\r
5978 <!ATTLIST xsl:element
\r
5979 name %avt; #REQUIRED
\r
5980 namespace %avt; #IMPLIED
\r
5981 use-attribute-sets %qnames; #IMPLIED
\r
5985 <!ELEMENT xsl:attribute %char-template;>
\r
5986 <!ATTLIST xsl:attribute
\r
5987 name %avt; #REQUIRED
\r
5988 namespace %avt; #IMPLIED
\r
5992 <!ELEMENT xsl:comment %char-template;>
\r
5993 <!ATTLIST xsl:comment %space-att;>
\r
5995 <!ELEMENT xsl:copy %template;>
\r
5996 <!ATTLIST xsl:copy
\r
5998 use-attribute-sets %qnames; #IMPLIED
\r
6001 <!ELEMENT xsl:message %template;>
\r
6002 <!ATTLIST xsl:message
\r
6004 terminate (yes|no) "no"
\r
6007 <!ELEMENT xsl:fallback %template;>
\r
6008 <!ATTLIST xsl:fallback %space-att;></pre>
\r
6014 <a name="section-Examples"></a>D Examples (Non-Normative)</h2>
\r
6018 <a name="section-Document-Example"></a>D.1 Document Example</h3>
\r
6020 <p>This example is a stylesheet for transforming documents that
\r
6021 conform to a simple DTD into XHTML <a href="#XHTML">[XHTML]</a>. The DTD
\r
6024 <pre><!ELEMENT doc (title, chapter*)>
\r
6025 <!ELEMENT chapter (title, (para|note)*, section*)>
\r
6026 <!ELEMENT section (title, (para|note)*)>
\r
6027 <!ELEMENT title (#PCDATA|emph)*>
\r
6028 <!ELEMENT para (#PCDATA|emph)*>
\r
6029 <!ELEMENT note (#PCDATA|emph)*>
\r
6030 <!ELEMENT emph (#PCDATA|emph)*></pre>
\r
6032 <p>The stylesheet is:</p>
\r
6034 <pre><xsl:stylesheet version="1.0"
\r
6035 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
\r
6036 xmlns="http://www.w3.org/TR/xhtml1/strict">
\r
6038 <xsl:strip-space elements="doc chapter section"/>
\r
6042 encoding="iso-8859-1"
\r
6045 <xsl:template match="doc">
\r
6049 <xsl:value-of select="title"/>
\r
6053 <xsl:apply-templates/>
\r
6056 </xsl:template>
\r
6058 <xsl:template match="doc/title">
\r
6060 <xsl:apply-templates/>
\r
6062 </xsl:template>
\r
6064 <xsl:template match="chapter/title">
\r
6066 <xsl:apply-templates/>
\r
6068 </xsl:template>
\r
6070 <xsl:template match="section/title">
\r
6072 <xsl:apply-templates/>
\r
6074 </xsl:template>
\r
6076 <xsl:template match="para">
\r
6078 <xsl:apply-templates/>
\r
6080 </xsl:template>
\r
6082 <xsl:template match="note">
\r
6083 <p class="note">
\r
6084 <b>NOTE: </b>
\r
6085 <xsl:apply-templates/>
\r
6087 </xsl:template>
\r
6089 <xsl:template match="emph">
\r
6091 <xsl:apply-templates/>
\r
6093 </xsl:template>
\r
6095 </xsl:stylesheet></pre>
\r
6097 <p>With the following input document</p>
\r
6099 <pre><!DOCTYPE doc SYSTEM "doc.dtd">
\r
6101 <title>Document Title</title>
\r
6103 <title>Chapter Title</title>
\r
6105 <title>Section Title</title>
\r
6106 <para>This is a test.</para>
\r
6107 <note>This is a note.</note>
\r
6110 <title>Another Section Title</title>
\r
6111 <para>This is <emph>another</emph> test.</para>
\r
6112 <note>This is another note.</note>
\r
6115 </doc></pre>
\r
6117 <p>it would produce the following result</p>
\r
6119 <pre><?xml version="1.0" encoding="iso-8859-1"?>
\r
6120 <html xmlns="http://www.w3.org/TR/xhtml1/strict">
\r
6122 <title>Document Title</title>
\r
6125 <h1>Document Title</h1>
\r
6126 <h2>Chapter Title</h2>
\r
6127 <h3>Section Title</h3>
\r
6128 <p>This is a test.</p>
\r
6129 <p class="note">
\r
6130 <b>NOTE: </b>This is a note.</p>
\r
6131 <h3>Another Section Title</h3>
\r
6132 <p>This is <em>another</em> test.</p>
\r
6133 <p class="note">
\r
6134 <b>NOTE: </b>This is another note.</p>
\r
6136 </html></pre>
\r
6142 <a name="data-example"></a>D.2 Data Example</h3>
\r
6144 <p>This is an example of transforming some data represented in XML
\r
6145 using three different XSLT stylesheets to produce three different
\r
6146 representations of the data, HTML, SVG and VRML.</p>
\r
6148 <p>The input data is:</p>
\r
6150 <pre><sales>
\r
6152 <division id="North">
\r
6153 <revenue>10</revenue>
\r
6154 <growth>9</growth>
\r
6155 <bonus>7</bonus>
\r
6158 <division id="South">
\r
6159 <revenue>4</revenue>
\r
6160 <growth>3</growth>
\r
6161 <bonus>4</bonus>
\r
6164 <division id="West">
\r
6165 <revenue>6</revenue>
\r
6166 <growth>-1.5</growth>
\r
6167 <bonus>2</bonus>
\r
6170 </sales></pre>
\r
6172 <p>The following stylesheet, which uses the simplified syntax
\r
6173 described in <a href="#result-element-stylesheet">[<b>2.3 Literal Result Element as Stylesheet</b>]</a>, transforms
\r
6174 the data into HTML:</p>
\r
6176 <pre><html xsl:version="1.0"
\r
6177 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
\r
6180 <title>Sales Results By Division</title>
\r
6183 <table border="1">
\r
6185 <th>Division</th>
\r
6186 <th>Revenue</th>
\r
6187 <th>Growth</th>
\r
6188 <th>Bonus</th>
\r
6190 <xsl:for-each select="sales/division">
\r
6191 <!-- order the result by revenue -->
\r
6192 <xsl:sort select="revenue"
\r
6193 data-type="number"
\r
6194 order="descending"/>
\r
6197 <em><xsl:value-of select="@id"/></em>
\r
6200 <xsl:value-of select="revenue"/>
\r
6203 <!-- highlight negative growth in red -->
\r
6204 <xsl:if test="growth &lt; 0">
\r
6205 <xsl:attribute name="style">
\r
6206 <xsl:text>color:red</xsl:text>
\r
6207 </xsl:attribute>
\r
6209 <xsl:value-of select="growth"/>
\r
6212 <xsl:value-of select="bonus"/>
\r
6215 </xsl:for-each>
\r
6218 </html></pre>
\r
6220 <p>The HTML output is:</p>
\r
6222 <pre><html lang="en">
\r
6224 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
\r
6225 <title>Sales Results By Division</title>
\r
6228 <table border="1">
\r
6230 <th>Division</th><th>Revenue</th><th>Growth</th><th>Bonus</th>
\r
6233 <td><em>North</em></td><td>10</td><td>9</td><td>7</td>
\r
6236 <td><em>West</em></td><td>6</td><td style="color:red">-1.5</td><td>2</td>
\r
6239 <td><em>South</em></td><td>4</td><td>3</td><td>4</td>
\r
6243 </html></pre>
\r
6245 <p>The following stylesheet transforms the data into SVG:</p>
\r
6247 <pre><xsl:stylesheet version="1.0"
\r
6248 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
\r
6249 xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">
\r
6251 <xsl:output method="xml" indent="yes" media-type="image/svg"/>
\r
6253 <xsl:template match="/">
\r
6255 <svg width = "3in" height="3in">
\r
6256 <g style = "stroke: #000000">
\r
6257 <!-- draw the axes -->
\r
6258 <line x1="0" x2="150" y1="150" y2="150"/>
\r
6259 <line x1="0" x2="0" y1="0" y2="150"/>
\r
6260 <text x="0" y="10">Revenue</text>
\r
6261 <text x="150" y="165">Division</text>
\r
6262 <xsl:for-each select="sales/division">
\r
6263 <!-- define some useful variables -->
\r
6265 <!-- the bar's x position -->
\r
6266 <xsl:variable name="pos"
\r
6267 select="(position()*40)-30"/>
\r
6269 <!-- the bar's height -->
\r
6270 <xsl:variable name="height"
\r
6271 select="revenue*10"/>
\r
6273 <!-- the rectangle -->
\r
6274 <rect x="{$pos}" y="{150-$height}"
\r
6275 width="20" height="{$height}"/>
\r
6277 <!-- the text label -->
\r
6278 <text x="{$pos}" y="165">
\r
6279 <xsl:value-of select="@id"/>
\r
6282 <!-- the bar value -->
\r
6283 <text x="{$pos}" y="{145-$height}">
\r
6284 <xsl:value-of select="revenue"/>
\r
6286 </xsl:for-each>
\r
6290 </xsl:template>
\r
6291 </xsl:stylesheet></pre>
\r
6293 <p>The SVG output is:</p>
\r
6295 <pre><svg width="3in" height="3in"
\r
6296 xmlns="http://www.w3.org/Graphics/SVG/svg-19990412.dtd">
\r
6297 <g style="stroke: #000000">
\r
6298 <line x1="0" x2="150" y1="150" y2="150"/>
\r
6299 <line x1="0" x2="0" y1="0" y2="150"/>
\r
6300 <text x="0" y="10">Revenue</text>
\r
6301 <text x="150" y="165">Division</text>
\r
6302 <rect x="10" y="50" width="20" height="100"/>
\r
6303 <text x="10" y="165">North</text>
\r
6304 <text x="10" y="45">10</text>
\r
6305 <rect x="50" y="110" width="20" height="40"/>
\r
6306 <text x="50" y="165">South</text>
\r
6307 <text x="50" y="105">4</text>
\r
6308 <rect x="90" y="90" width="20" height="60"/>
\r
6309 <text x="90" y="165">West</text>
\r
6310 <text x="90" y="85">6</text>
\r
6312 </svg></pre>
\r
6314 <p>The following stylesheet transforms the data into VRML:</p>
\r
6316 <pre><xsl:stylesheet version="1.0"
\r
6317 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
\r
6319 <!-- generate text output as mime type model/vrml, using default charset -->
\r
6320 <xsl:output method="text" encoding="UTF-8" media-type="model/vrml"/>
\r
6322 <xsl:template match="/">#VRML V2.0 utf8
\r
6324 # externproto definition of a single bar element
\r
6325 EXTERNPROTO bar [
\r
6329 field SFString name
\r
6331 "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl"
\r
6333 # inline containing the graph axes
\r
6335 url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wrl"
\r
6338 <xsl:for-each select="sales/division">
\r
6340 x <xsl:value-of select="revenue"/>
\r
6341 y <xsl:value-of select="growth"/>
\r
6342 z <xsl:value-of select="bonus"/>
\r
6343 name "<xsl:value-of select="@id"/>"
\r
6345 </xsl:for-each>
\r
6347 </xsl:template>
\r
6349 </xsl:stylesheet></pre>
\r
6351 <p>The VRML output is:</p>
\r
6353 <pre>#VRML V2.0 utf8
\r
6355 # externproto definition of a single bar element
\r
6356 EXTERNPROTO bar [
\r
6360 field SFString name
\r
6362 "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl"
\r
6364 # inline containing the graph axes
\r
6366 url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wrl"
\r
6397 <a name="section-Acknowledgements"></a>E Acknowledgements (Non-Normative)</h2>
\r
6398 <p>The following have contributed to authoring this draft:</p>
\r
6400 <li>Daniel Lipkin, Saba</li>
\r
6401 <li>Jonathan Marsh, Microsoft</li>
\r
6402 <li>Henry Thompson, University of Edinburgh</li>
\r
6403 <li>Norman Walsh, Arbortext</li>
\r
6404 <li>Steve Zilles, Adobe</li>
\r
6407 <p>This specification was developed and approved for publication by the
\r
6408 W3C XSL Working Group (WG). WG approval of this specification does not
\r
6409 necessarily imply that all WG members voted for its approval. The
\r
6410 current members of the XSL WG are:</p>
\r
6412 Sharon Adler, IBM (Co-Chair); Anders Berglund, IBM; Perin Blanchard, Novell; Scott Boag, Lotus; Larry Cable, Sun; Jeff Caruso, Bitstream; James Clark; Peter Danielsen, Bell Labs; Don Day, IBM; Stephen Deach, Adobe; Dwayne Dicks, SoftQuad; Andrew Greene, Bitstream; Paul Grosso, Arbortext; Eduardo Gutentag, Sun; Juliane Harbarth, Software AG; Mickey Kimchi, Enigma; Chris Lilley, W3C; Chris Maden, Exemplary Technologies; Jonathan Marsh, Microsoft; Alex Milowski, Lexica; Steve Muench, Oracle; Scott Parnell, Xerox; Vincent Quint, W3C; Dan Rapp, Novell; Gregg Reynolds, Datalogics; Jonathan Robie, Software AG; Mark Scardina, Oracle; Henry Thompson, University of Edinburgh; Philip Wadler, Bell Labs; Norman Walsh, Arbortext; Sanjiva Weerawarana, IBM; Steve Zilles, Adobe (Co-Chair)
\r
6418 <a name="section-Changes-from-Proposed-Recommendation"></a>F Changes from Proposed Recommendation (Non-Normative)</h2>
\r
6420 <p>The following are the changes since the Proposed Recommendation:</p>
\r
6425 <p>The <code>xsl:version</code> attribute is required on a
\r
6426 literal result element used as a stylesheet (see <a href="#result-element-stylesheet">[<b>2.3 Literal Result Element as Stylesheet</b>]</a>).</p>
\r
6430 <p>The <code>data-type</code> attribute on <code>xsl:sort</code>
\r
6431 can use a prefixed name to specify a data-type not defined by
\r
6432 XSLT (see <a href="#sorting">[<b>10 Sorting</b>]</a>).</p>
\r
6441 <a name="section-Features-under-Consideration-for-Future-Versions-of-XSLT"></a>G Features under Consideration for Future Versions of XSLT (Non-Normative)</h2>
\r
6443 <p>The following features are under consideration for versions of XSLT
\r
6444 after XSLT 1.0:</p>
\r
6449 <p>a conditional expression;</p>
\r
6453 <p>support for XML Schema datatypes and archetypes;</p>
\r
6457 <p>support for something like style rules in the original XSL
\r
6462 <p>an attribute to control the default namespace for names
\r
6463 occurring in XSLT attributes;</p>
\r
6467 <p>support for entity references;</p>
\r
6471 <p>support for DTDs in the data model;</p>
\r
6475 <p>support for notations in the data model;</p>
\r
6479 <p>a way to get back from an element to the elements that
\r
6480 reference it (e.g. by IDREF attributes);</p>
\r
6484 <p>an easier way to get an ID or key in another document;</p>
\r
6488 <p>support for regular expressions for matching against any or
\r
6489 all of text nodes, attribute values, attribute names, element type
\r
6494 <p>case-insensitive comparisons;</p>
\r
6498 <p>normalization of strings before comparison, for example for
\r
6499 compatibility characters;</p>
\r
6503 <p>a function <code>string resolve(node-set)</code> function
\r
6504 that treats the value of the argument as a relative URI and turns it
\r
6505 into an absolute URI using the base URI of the node;</p>
\r
6509 <p>multiple result documents;</p>
\r
6513 <p>defaulting the <code>select</code> attribute on
\r
6514 <code>xsl:value-of</code> to the current node;</p>
\r
6518 <p>an attribute on <code>xsl:attribute</code> to control how the
\r
6519 attribute value is normalized;</p>
\r
6523 <p>additional attributes on <code>xsl:sort</code> to provide
\r
6524 further control over sorting, such as relative order of
\r
6529 <p>a way to put the text of a resource identified by a URI into
\r
6530 the result tree;</p>
\r
6534 <p>allow unions in steps (e.g. <code>foo/(bar|baz)</code>);</p>
\r
6538 <p>allow for result tree fragments all operations that are
\r
6539 allowed for node-sets;</p>
\r
6543 <p>a way to group together consecutive nodes having duplicate
\r
6544 subelements or attributes;</p>
\r
6548 <p>features to make handling of the HTML <code>style</code>
\r
6549 attribute more convenient.</p>
\r