xref: /aosp_15_r20/external/apache-xml/test/tests/contrib/xsltc/mk/mk056.xml (revision 1212f9a0ffdc28482b8821715d2222bf16dc14e2)
1<?xml version="1.0" encoding="iso-8859-1"?>
2
3<!-- $Id$ -->
4
5<!DOCTYPE spec SYSTEM "spec.dtd" [
6
7<!ENTITY XML "http://www.w3.org/TR/REC-xml">
8
9<!ENTITY XMLNames "http://www.w3.org/TR/REC-xml-names">
10
11<!ENTITY XSLT.ns "http://www.w3.org/1999/XSL/Transform">
12
13<!ENTITY XSLTA.ns "http://www.w3.org/1999/XSL/TransformAlias">
14
15<!ENTITY XSLFO.ns "http://www.w3.org/1999/XSL/Format">
16
17<!ENTITY XHTML.ns "http://www.w3.org/TR/xhtml1/strict">
18
19<!ENTITY year "1999">
20
21<!ENTITY month "November">
22
23<!ENTITY MM "11">
24
25<!ENTITY day "16">
26
27<!ENTITY DD "16">
28
29<!ENTITY YYYYMMDD "&year;&MM;&DD;">
30
31<!ENTITY LEV "REC">
32
33<!ENTITY XPath "http://www.w3.org/TR/xpath">
34
35<!ATTLIST xfunction href CDATA "&XPath;">
36
37<!-- DTD customizations -->
38
39<!ELEMENT proto (arg*)>
40
41<!ATTLIST proto
42
43  name NMTOKEN #REQUIRED
44
45  return-type (number|string|boolean|node-set|object) #REQUIRED
46
47>
48
49<!ELEMENT arg EMPTY>
50
51<!ATTLIST arg
52
53  type (number|string|boolean|node-set|object) #REQUIRED
54
55  occur (opt|rep) #IMPLIED
56
57>
58
59<!ELEMENT function (#PCDATA)>
60
61<!ELEMENT xfunction (#PCDATA)>
62
63<!ATTLIST xfunction href CDATA #REQUIRED>
64
65<!ELEMENT e:element-syntax
66
67  (e:in-category*, e:attribute*, (e:empty|e:text|e:element|e:model|e:sequence|e:choice))
68
69>
70
71<!ATTLIST e:element-syntax
72
73  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
74
75  name NMTOKEN #REQUIRED
76
77>
78
79<!ELEMENT e:in-category EMPTY>
80
81<!ATTLIST
82
83  e:in-category name NMTOKEN #REQUIRED
84
85  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
86
87>
88
89<!ELEMENT e:attribute (e:attribute-value-template|(e:constant|e:data-type)+)>
90
91<!ATTLIST e:attribute
92
93  name NMTOKEN #REQUIRED
94
95  required (yes) #IMPLIED
96
97  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
98
99>
100
101<!ELEMENT e:attribute-value-template (e:constant|e:data-type)+>
102
103<!ATTLIST e:attribute-value-template
104
105  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
106
107>
108
109<!ELEMENT e:constant EMPTY>
110
111<!ATTLIST
112
113  e:constant value CDATA #REQUIRED
114
115  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
116
117>
118
119<!ELEMENT e:data-type EMPTY>
120
121<!ATTLIST e:data-type
122
123  name NMTOKEN #REQUIRED
124
125  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
126
127>
128
129<!ELEMENT e:empty EMPTY>
130
131<!ATTLIST e:empty
132
133  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
134
135>
136
137<!ELEMENT e:text EMPTY>
138
139<!ATTLIST e:text
140
141  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
142
143>
144
145<!ELEMENT e:element EMPTY>
146
147<!ATTLIST e:element
148
149  name NMTOKEN #REQUIRED
150
151  repeat (zero-or-one|zero-or-more|one-or-more) #IMPLIED
152
153  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
154
155>
156
157<!ELEMENT e:model EMPTY>
158
159<!ATTLIST e:model
160
161  name NMTOKEN #REQUIRED
162
163  repeat (zero-or-one|zero-or-more|one-or-more) #IMPLIED
164
165  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
166
167>
168
169<!ELEMENT e:sequence (e:element|e:model|e:choice)+>
170
171<!ATTLIST e:sequence
172
173  repeat (zero-or-one|zero-or-more|one-or-more) #IMPLIED
174
175  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
176
177>
178
179<!ELEMENT e:choice (e:element|e:model|e:sequence)+>
180
181<!ATTLIST e:choice
182
183  repeat (zero-or-one|zero-or-more|one-or-more) #IMPLIED
184
185  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
186
187>
188
189<!ELEMENT e:element-syntax-summary EMPTY>
190
191<!ATTLIST e:element-syntax-summary
192
193  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
194
195>
196
197<!ENTITY % local.illus.class "|proto|e:element-syntax|e:element-syntax-summary">
198
199<!ENTITY % local.tech.class "|function|xfunction">
200
201<!ENTITY % local.loc.class "|var">
202
203<!ELEMENT var (#PCDATA)>
204
205<!ATTLIST spec
206
207  xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
208
209>
210
211]>
212
213<spec xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax">
214
215<header>
216
217<title>XSL Transformations (XSLT)</title>
218
219<version>Version 1.0</version>
220
221<w3c-designation>&LEV;-xslt-&YYYYMMDD;</w3c-designation>
222
223<w3c-doctype>W3C Recommendation</w3c-doctype>
224
225<pubdate><day>&day;</day><month>&month;</month><year>&year;</year></pubdate>
226
227<publoc>
228
229<loc href="http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;"
230
231          >http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;</loc>
232
233<loc role="available-format"
234
235href="http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;.xml">XML</loc>
236
237<loc role="available-format"
238
239href="http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;.html">HTML</loc>
240
241<!--
242
243<loc href="http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;.pdf"
244
245          >http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;.pdf</loc>
246
247-->
248
249</publoc>
250
251<latestloc>
252
253<loc href="http://www.w3.org/TR/xslt"
254
255          >http://www.w3.org/TR/xslt</loc>
256
257</latestloc>
258
259<prevlocs>
260
261<loc href="http://www.w3.org/TR/1999/PR-xslt-19991008"
262
263          >http://www.w3.org/TR/1999/PR-xslt-19991008</loc>
264
265<loc href="http://www.w3.org/1999/08/WD-xslt-19990813"
266
267          >http://www.w3.org/1999/08/WD-xslt-19990813</loc>
268
269<loc href="http://www.w3.org/1999/07/WD-xslt-19990709"
270
271          >http://www.w3.org/1999/07/WD-xslt-19990709</loc>
272
273<loc href="http://www.w3.org/TR/1999/WD-xslt-19990421"
274
275          >http://www.w3.org/TR/1999/WD-xslt-19990421</loc>
276
277<loc href="http://www.w3.org/TR/1998/WD-xsl-19981216"
278
279          >http://www.w3.org/TR/1998/WD-xsl-19981216</loc>
280
281<loc href="http://www.w3.org/TR/1998/WD-xsl-19980818"
282
283          >http://www.w3.org/TR/1998/WD-xsl-19980818</loc>
284
285</prevlocs>
286
287<authlist>
288
289<author>
290
291<name>James Clark</name>
292
293<email href="mailto:[email protected]">[email protected]</email>
294
295</author>
296
297</authlist>
298
299
300
301<status>
302
303
304
305<p>This document has been reviewed by W3C Members and other interested
306
307parties and has been endorsed by the Director as a W3C <loc
308
309href="http://www.w3.org/Consortium/Process/#RecsW3C">Recommendation</loc>. It
310
311is a stable document and may be used as reference material or cited as
312
313a normative reference from other documents. W3C's role in making the
314
315Recommendation is to draw attention to the specification and to
316
317promote its widespread deployment. This enhances the functionality and
318
319interoperability of the Web.</p>
320
321
322
323<p>The list of known errors in this specification is available at
324
325<loc href="http://www.w3.org/&year;/&MM;/&LEV;-xslt-&YYYYMMDD;-errata"
326
327>http://www.w3.org/&year;/&MM;/&LEV;-xslt-&YYYYMMDD;-errata</loc>.</p>
328
329
330
331<p>Comments on this specification may be sent to <loc
332
333href="mailto:[email protected]">[email protected]</loc>; <loc
334
335href="http://lists.w3.org/Archives/Public/xsl-editors">archives</loc>
336
337of the comments are available.  Public discussion of XSL, including
338
339XSL Transformations, takes place on the <loc
340
341href="http://www.mulberrytech.com/xsl/xsl-list/index.html">XSL-List</loc>
342
343mailing list.</p>
344
345
346
347<p>The English version of this specification is the only normative
348
349version. However, for translations of this document, see <loc
350
351href="http://www.w3.org/Style/XSL/translations.html"
352
353>http://www.w3.org/Style/XSL/translations.html</loc>.</p>
354
355
356
357<p>A list of current W3C Recommendations and other technical documents
358
359can be found at <loc
360
361href="http://www.w3.org/TR">http://www.w3.org/TR</loc>.</p>
362
363
364
365<p>This specification has been produced as part of the <loc
366
367href="http://www.w3.org/Style/Activity">W3C Style activity</loc>.</p>
368
369
370
371</status>
372
373
374
375<abstract>
376
377
378
379<p>This specification defines the syntax and semantics of XSLT, which
380
381is a language for transforming XML documents into other XML
382
383documents.</p>
384
385
386
387<p>XSLT is designed for use as part of XSL, which is a stylesheet
388
389language for XML. In addition to XSLT, XSL includes an XML vocabulary
390
391for specifying formatting.  XSL specifies the styling of an XML
392
393document by using XSLT to describe how the document is transformed
394
395into another XML document that uses the formatting vocabulary.</p>
396
397
398
399<p>XSLT is also designed to be used independently of XSL.  However,
400
401XSLT is not intended as a completely general-purpose XML
402
403transformation language.  Rather it is designed primarily for the
404
405kinds of transformations that are needed when XSLT is used as part of
406
407XSL.</p>
408
409
410
411</abstract>
412
413
414
415<langusage>
416
417<language id="EN">English</language>
418
419<language id="ebnf">EBNF</language>
420
421</langusage>
422
423<revisiondesc>
424
425<slist>
426
427<sitem>See RCS log for revision history.</sitem>
428
429</slist>
430
431</revisiondesc>
432
433</header>
434
435<body>
436
437<div1>
438
439<head>Introduction</head>
440
441
442
443<p>This specification defines the syntax and semantics of the XSLT
444
445language.  A transformation in the XSLT language is expressed as a
446
447well-formed XML document <bibref ref="XML"/> conforming to the
448
449Namespaces in XML Recommendation <bibref ref="XMLNAMES"/>, which may
450
451include both elements that are defined by XSLT and elements that are
452
453not defined by XSLT.  <termdef id="dt-xslt-namespace" term="XSLT
454
455Namespace">XSLT-defined elements are distinguished by belonging to a
456
457specific XML namespace (see <specref ref="xslt-namespace"/>), which is
458
459referred to in this specification as the <term>XSLT
460
461namespace</term>.</termdef> Thus this specification is a definition of
462
463the syntax and semantics of the XSLT namespace.</p>
464
465
466
467<p>A transformation expressed in XSLT describes rules for transforming
468
469a source tree into a result tree.  The transformation is achieved by
470
471associating patterns with templates.  A pattern is matched against
472
473elements in the source tree.  A template is instantiated to create
474
475part of the result tree.  The result tree is separate from the source
476
477tree.  The structure of the result tree can be completely different
478
479from the structure of the source tree. In constructing the result
480
481tree, elements from the source tree can be filtered and reordered, and
482
483arbitrary structure can be added.</p>
484
485
486
487<p>A transformation expressed in XSLT is called a stylesheet.  This is
488
489because, in the case when XSLT is transforming into the XSL formatting
490
491vocabulary, the transformation functions as a stylesheet.</p>
492
493
494
495<p>This document does not specify how an XSLT stylesheet is associated
496
497with an XML document.  It is recommended that XSL processors support
498
499the mechanism described in <bibref ref="XMLSTYLE"/>.  When this or any
500
501other mechanism yields a sequence of more than one XSLT stylesheet to
502
503be applied simultaneously to a XML document, then the effect
504
505should be the same as applying a single stylesheet that imports each
506
507member of the sequence in order (see <specref ref="import"/>).</p>
508
509
510
511<p>A stylesheet contains a set of template rules.  A template rule has
512
513two parts: a pattern which is matched against nodes in the source tree
514
515and a template which can be instantiated to form part of the result
516
517tree.  This allows a stylesheet to be applicable to a wide class of
518
519documents that have similar source tree structures.</p>
520
521
522
523<p>A template is instantiated for a particular source element
524
525to create part of the result tree. A template can contain elements
526
527that specify literal result element structure.  A template can also
528
529contain elements from the XSLT namespace
530
531that are instructions for creating result tree
532
533fragments.  When a template is instantiated, each instruction is
534
535executed and replaced by the result tree fragment that it creates.
536
537Instructions can select and process descendant source elements.  Processing a
538
539descendant element creates a result tree fragment by finding the
540
541applicable template rule and instantiating its template. Note
542
543that elements are only processed when they have been selected by the
544
545execution of an instruction.  The result tree is constructed by
546
547finding the template rule for the root node and instantiating
548
549its template.</p>
550
551
552
553<p>In the process of finding the applicable template rule, more
554
555than one template rule may have a pattern that matches a given
556
557element. However, only one template rule will be applied. The
558
559method for deciding which template rule to apply is described
560
561in <specref ref="conflict"/>.</p>
562
563
564
565<p>A single template by itself has considerable power: it can create
566
567structures of arbitrary complexity; it can pull string values out of
568
569arbitrary locations in the source tree; it can generate structures
570
571that are repeated according to the occurrence of elements in the
572
573source tree.  For simple transformations where the structure of the
574
575result tree is independent of the structure of the source tree, a
576
577stylesheet can often consist of only a single template, which
578
579functions as a template for the complete result tree.  Transformations
580
581on XML documents that represent data are often of this kind (see
582
583<specref ref="data-example"/>). XSLT allows a simplified syntax for
584
585such stylesheets (see <specref ref="result-element-stylesheet"/>).</p>
586
587
588
589<p>When a template is instantiated, it is always instantiated with
590
591respect to a <termdef id="dt-current-node" term="Current
592
593Node"><term>current node</term></termdef> and a <termdef
594
595id="dt-current-node-list" term="Current Node List"><term>current node
596
597list</term></termdef>. The current node is always a member of the
598
599current node list.  Many operations in XSLT are relative to the
600
601current node. Only a few instructions change the current node list or
602
603the current node (see <specref ref="rules"/> and <specref
604
605ref="for-each"/>); during the instantiation of one of these
606
607instructions, the current node list changes to a new list of nodes and
608
609each member of this new list becomes the current node in turn; after
610
611the instantiation of the instruction is complete, the current node and
612
613current node list revert to what they were before the instruction was
614
615instantiated.</p>
616
617
618
619<p>XSLT makes use of the expression language defined by <bibref
620
621ref="XPATH"/> for selecting elements for processing, for conditional
622
623processing and for generating text.</p>
624
625
626
627<p>XSLT provides two <quote>hooks</quote> for extending the language,
628
629one hook for extending the set of instruction elements used in
630
631templates and one hook for extending the set of functions used in
632
633XPath expressions.  These hooks are both based on XML namespaces.
634
635This version of XSLT does not define a mechanism for implementing the
636
637hooks. See <specref ref="extension"/>.</p>
638
639
640
641<note><p>The XSL WG intends to define such a mechanism in a future
642
643version of this specification or in a separate
644
645specification.</p></note>
646
647
648
649<p>The element syntax summary notation used to describe the syntax of
650
651XSLT-defined elements is described in <specref ref="notation"/>.</p>
652
653
654
655<p>The MIME media types <code>text/xml</code> and
656
657<code>application/xml</code> <bibref ref="RFC2376"/> should be used
658
659for XSLT stylesheets.  It is possible that a media type will be
660
661registered specifically for XSLT stylesheets; if and when it is, that
662
663media type may also be used.</p>
664
665
666
667</div1>
668
669
670
671<div1>
672
673<head>Stylesheet Structure</head>
674
675
676
677<div2 id="xslt-namespace">
678
679<head>XSLT Namespace</head>
680
681
682
683<p>The XSLT namespace has the URI <code>&XSLT.ns;</code>.</p>
684
685
686
687<note><p>The <code>1999</code> in the URI indicates the year in which
688
689the URI was allocated by the W3C.  It does not indicate the version of
690
691XSLT being used, which is specified by attributes (see <specref
692
693ref="stylesheet-element"/> and <specref
694
695ref="result-element-stylesheet"/>).</p></note>
696
697
698
699<p>XSLT processors must use the XML namespaces mechanism <bibref
700
701ref="XMLNAMES"/> to recognize elements and attributes from this
702
703namespace. Elements from the XSLT namespace are recognized only in the
704
705stylesheet not in the source document. The complete list of
706
707XSLT-defined elements is specified in <specref
708
709ref="element-syntax-summary"/>.  Vendors must not extend the XSLT
710
711namespace with additional elements or attributes. Instead, any
712
713extension must be in a separate namespace.  Any namespace that is used
714
715for additional instruction elements must be identified by means of the
716
717extension element mechanism specified in <specref
718
719ref="extension-element"/>.</p>
720
721
722
723<p>This specification uses a prefix of <code>xsl:</code> for referring
724
725to elements in the XSLT namespace. However, XSLT stylesheets are free
726
727to use any prefix, provided that there is a namespace declaration that
728
729binds the prefix to the URI of the XSLT namespace.</p>
730
731
732
733<p>An element from the XSLT namespace may have any attribute not from
734
735the XSLT namespace, provided that the <xtermref
736
737href="&XPath;#dt-expanded-name">expanded-name</xtermref> of the
738
739attribute has a non-null namespace URI.  The presence of such
740
741attributes must not change the behavior of XSLT elements and functions
742
743defined in this document. Thus, an XSLT processor is always free to
744
745ignore such attributes, and must ignore such attributes without giving
746
747an error if it does not recognize the namespace URI. Such attributes
748
749can provide, for example, unique identifiers, optimization hints, or
750
751documentation.</p>
752
753
754
755<p>It is an error for an element from the XSLT namespace to have
756
757attributes with expanded-names that have null namespace URIs
758
759(i.e. attributes with unprefixed names) other than attributes defined
760
761for the element in this document.</p>
762
763
764
765<note><p>The conventions used for the names of XSLT elements,
766
767attributes and functions are that names are all lower-case, use
768
769hyphens to separate words, and use abbreviations only if they already
770
771appear in the syntax of a related language such as XML or
772
773HTML.</p></note>
774
775
776
777
778
779</div2>
780
781
782
783<div2 id="stylesheet-element">
784
785<head>Stylesheet Element</head>
786
787
788
789<e:element-syntax name="stylesheet">
790
791  <e:attribute name="id">
792
793    <e:data-type name="id"/>
794
795  </e:attribute>
796
797  <e:attribute name="extension-element-prefixes">
798
799    <e:data-type name="tokens"/>
800
801  </e:attribute>
802
803  <e:attribute name="exclude-result-prefixes">
804
805    <e:data-type name="tokens"/>
806
807  </e:attribute>
808
809  <e:attribute name="version" required="yes">
810
811    <e:data-type name="number"/>
812
813  </e:attribute>
814
815  <e:sequence>
816
817    <e:element repeat="zero-or-more" name="import"/>
818
819    <e:model name="top-level-elements"/>
820
821  </e:sequence>
822
823</e:element-syntax>
824
825
826
827<e:element-syntax name="transform">
828
829  <e:attribute name="id">
830
831    <e:data-type name="id"/>
832
833  </e:attribute>
834
835  <e:attribute name="extension-element-prefixes">
836
837    <e:data-type name="tokens"/>
838
839  </e:attribute>
840
841  <e:attribute name="exclude-result-prefixes">
842
843    <e:data-type name="tokens"/>
844
845  </e:attribute>
846
847  <e:attribute name="version" required="yes">
848
849    <e:data-type name="number"/>
850
851  </e:attribute>
852
853  <e:sequence>
854
855    <e:element repeat="zero-or-more" name="import"/>
856
857    <e:model name="top-level-elements"/>
858
859  </e:sequence>
860
861</e:element-syntax>
862
863
864
865<p>A stylesheet is represented by an <code>xsl:stylesheet</code>
866
867element in an XML document.  <code>xsl:transform</code> is allowed as
868
869a synonym for <code>xsl:stylesheet</code>.</p>
870
871
872
873<p>An <code>xsl:stylesheet</code> element must have a
874
875<code>version</code> attribute, indicating the version of XSLT that
876
877the stylesheet requires.  For this version of XSLT, the value should
878
879be <code>1.0</code>.  When the value is not equal to <code>1.0</code>,
880
881forwards-compatible processing mode is enabled (see <specref
882
883ref="forwards"/>).</p>
884
885
886
887<p>The <code>xsl:stylesheet</code> element may contain the following types
888
889of elements:</p>
890
891<ulist>
892
893<item><p><code>xsl:import</code></p></item>
894
895<item><p><code>xsl:include</code></p></item>
896
897<item><p><code>xsl:strip-space</code></p></item>
898
899<item><p><code>xsl:preserve-space</code></p></item>
900
901<item><p><code>xsl:output</code></p></item>
902
903<item><p><code>xsl:key</code></p></item>
904
905<item><p><code>xsl:decimal-format</code></p></item>
906
907<item><p><code>xsl:namespace-alias</code></p></item>
908
909<item><p><code>xsl:attribute-set</code></p></item>
910
911<item><p><code>xsl:variable</code></p></item>
912
913<item><p><code>xsl:param</code></p></item>
914
915<item><p><code>xsl:template</code></p></item>
916
917</ulist>
918
919
920
921<p><termdef id="dt-top-level" term="Top-level">An element occurring as
922
923a child of an <code>xsl:stylesheet</code> element is called a
924
925<term>top-level</term> element.</termdef></p>
926
927
928
929<p>This example shows the structure of a stylesheet.  Ellipses
930
931(<code>...</code>) indicate where attribute values or content have
932
933been omitted.  Although this example shows one of each type of allowed
934
935element, stylesheets may contain zero or more of each of these
936
937elements.</p>
938
939
940
941<eg>&lt;xsl:stylesheet version="1.0"
942
943                xmlns:xsl="&XSLT.ns;"><![CDATA[
944
945  <xsl:import href="..."/>
946
947
948
949  <xsl:include href="..."/>
950
951
952
953  <xsl:strip-space elements="..."/>
954
955
956
957  <xsl:preserve-space elements="..."/>
958
959
960
961  <xsl:output method="..."/>
962
963
964
965  <xsl:key name="..." match="..." use="..."/>
966
967
968
969  <xsl:decimal-format name="..."/>
970
971
972
973  <xsl:namespace-alias stylesheet-prefix="..." result-prefix="..."/>
974
975
976
977  <xsl:attribute-set name="...">
978
979    ...
980
981  </xsl:attribute-set>
982
983
984
985  <xsl:variable name="...">...</xsl:variable>
986
987
988
989  <xsl:param name="...">...</xsl:param>
990
991
992
993  <xsl:template match="...">
994
995    ...
996
997  </xsl:template>
998
999
1000
1001  <xsl:template name="...">
1002
1003    ...
1004
1005  </xsl:template>
1006
1007
1008
1009</xsl:stylesheet>]]></eg>
1010
1011
1012
1013<p>The order in which the children of the <code>xsl:stylesheet</code>
1014
1015element occur is not significant except for <code>xsl:import</code>
1016
1017elements and for error recovery.  Users are free to order the elements
1018
1019as they prefer, and stylesheet creation tools need not provide control
1020
1021over the order in which the elements occur.</p>
1022
1023
1024
1025<p>In addition, the <code>xsl:stylesheet</code> element may contain
1026
1027any element not from the XSLT namespace, provided that the
1028
1029expanded-name of the element has a non-null namespace URI.  The presence of
1030
1031such top-level elements must not change the behavior of XSLT elements
1032
1033and functions defined in this document; for example, it would not be
1034
1035permitted for such a top-level element to specify that
1036
1037<code>xsl:apply-templates</code> was to use different rules to resolve
1038
1039conflicts. Thus, an XSLT processor is always free to ignore such
1040
1041top-level elements, and must ignore a top-level element without giving
1042
1043an error if it does not recognize the namespace URI. Such elements can
1044
1045provide, for example,</p>
1046
1047
1048
1049<ulist>
1050
1051
1052
1053<item><p>information used by extension elements or extension functions
1054
1055(see <specref ref="extension"/>),</p></item>
1056
1057
1058
1059<item><p>information about what to do with the result tree,</p></item>
1060
1061
1062
1063<item><p>information about how to obtain the source tree,</p></item>
1064
1065
1066
1067<item><p>metadata about the stylesheet,</p></item>
1068
1069
1070
1071<item><p>structured documentation for the stylesheet.</p></item>
1072
1073
1074
1075</ulist>
1076
1077
1078
1079</div2>
1080
1081
1082
1083<div2 id="result-element-stylesheet">
1084
1085<head>Literal Result Element as Stylesheet</head>
1086
1087
1088
1089<p>A simplified syntax is allowed for stylesheets that consist of only
1090
1091a single template for the root node.  The stylesheet may consist of
1092
1093just a literal result element (see <specref
1094
1095ref="literal-result-element"/>).  Such a stylesheet is equivalent to a
1096
1097stylesheet with an <code>xsl:stylesheet</code> element containing a
1098
1099template rule containing the literal result element; the template rule
1100
1101has a match pattern of <code>/</code>. For example</p>
1102
1103
1104
1105<eg>&lt;html xsl:version="1.0"
1106
1107      xmlns:xsl="&XSLT.ns;"
1108
1109      xmlns="&XHTML.ns;"><![CDATA[
1110
1111  <head>
1112
1113    <title>Expense Report Summary</title>
1114
1115  </head>
1116
1117  <body>
1118
1119    <p>Total Amount: <xsl:value-of select="expense-report/total"/></p>
1120
1121  </body>
1122
1123</html>]]></eg>
1124
1125
1126
1127<p>has the same meaning as</p>
1128
1129
1130
1131<eg>&lt;xsl:stylesheet version="1.0"
1132
1133                xmlns:xsl="&XSLT.ns;"
1134
1135                xmlns="&XHTML.ns;"><![CDATA[
1136
1137<xsl:template match="/">
1138
1139<html>
1140
1141  <head>
1142
1143    <title>Expense Report Summary</title>
1144
1145  </head>
1146
1147  <body>
1148
1149    <p>Total Amount: <xsl:value-of select="expense-report/total"/></p>
1150
1151  </body>
1152
1153</html>
1154
1155</xsl:template>
1156
1157</xsl:stylesheet>]]></eg>
1158
1159
1160
1161<p>A literal result element that is the document element of a
1162
1163stylesheet must have an <code>xsl:version</code> attribute, which
1164
1165indicates the version of XSLT that the stylesheet requires.  For this
1166
1167version of XSLT, the value should be <code>1.0</code>; the value must
1168
1169be a <xnt href="&XPath;#NT-Number">Number</xnt>.  Other literal result
1170
1171elements may also have an <code>xsl:version</code> attribute. When the
1172
1173<code>xsl:version</code> attribute is not equal to <code>1.0</code>,
1174
1175forwards-compatible processing mode is enabled (see <specref
1176
1177ref="forwards"/>).</p>
1178
1179
1180
1181<p>The allowed content of a literal result element when used as a
1182
1183stylesheet is no different from when it occurs within a
1184
1185stylesheet. Thus, a literal result element used as a stylesheet cannot
1186
1187contain <termref def="dt-top-level">top-level</termref> elements.</p>
1188
1189
1190
1191<p>In some situations, the only way that a system can recognize that an
1192
1193XML document needs to be processed by an XSLT processor as an XSLT
1194
1195stylesheet is by examining the XML document itself.  Using the
1196
1197simplified syntax makes this harder.</p>
1198
1199
1200
1201<note><p>For example, another XML language (AXL) might also use an
1202
1203<code>axl:version</code> on the document element to indicate that an
1204
1205XML document was an AXL document that required processing by an AXL
1206
1207processor; if a document had both an <code>axl:version</code>
1208
1209attribute and an <code>xsl:version</code> attribute, it would be
1210
1211unclear whether the document should be processed by an XSLT processor
1212
1213or an AXL processor.</p></note>
1214
1215
1216
1217<p>Therefore, the simplified syntax should not be used for XSLT
1218
1219stylesheets that may be used in such a situation.  This situation can,
1220
1221for example, arise when an XSLT stylesheet is transmitted as a message
1222
1223with a MIME media type of <code>text/xml</code> or
1224
1225<code>application/xml</code> to a recipient that will use the MIME
1226
1227media type to determine how the message is processed.</p>
1228
1229
1230
1231</div2>
1232
1233
1234
1235<div2 id="qname">
1236
1237<head>Qualified Names</head>
1238
1239
1240
1241<p>The name of an internal XSLT object, specifically a named template
1242
1243(see <specref ref="named-templates"/>), a mode (see <specref
1244
1245ref="modes"/>), an attribute set (see <specref
1246
1247ref="attribute-sets"/>), a key (see <specref ref="key"/>), a
1248
1249decimal-format (see <specref ref="format-number"/>), a variable or a
1250
1251parameter (see <specref ref="variables"/>) is specified as a <xnt
1252
1253href="&XMLNames;#NT-QName">QName</xnt>.  If it has a prefix, then the
1254
1255prefix is expanded into a URI reference using the namespace
1256
1257declarations in effect on the attribute in which the name occurs.  The
1258
1259<xtermref href="&XPath;#dt-expanded-name">expanded-name</xtermref>
1260
1261consisting of the local part of the name and the possibly null URI
1262
1263reference is used as the name of the object.  The default namespace is
1264
1265<emph>not</emph> used for unprefixed names.</p>
1266
1267
1268
1269</div2>
1270
1271
1272
1273<div2 id="forwards">
1274
1275<head>Forwards-Compatible Processing</head>
1276
1277
1278
1279<p>An element enables forwards-compatible mode for itself, its
1280
1281attributes, its descendants and their attributes if either it is an
1282
1283<code>xsl:stylesheet</code> element whose <code>version</code>
1284
1285attribute is not equal to <code>1.0</code>, or it is a literal result
1286
1287element that has an <code>xsl:version</code> attribute whose value is
1288
1289not equal to <code>1.0</code>, or it is a literal result element that
1290
1291does not have an <code>xsl:version</code> attribute and that is the
1292
1293document element of a stylesheet using the simplified syntax (see
1294
1295<specref ref="result-element-stylesheet"/>).  A literal result element
1296
1297that has an <code>xsl:version</code> attribute whose value is equal to
1298
1299<code>1.0</code> disables forwards-compatible mode for itself, its
1300
1301attributes, its descendants and their attributes.</p>
1302
1303
1304
1305<p>If an element is processed in forwards-compatible mode, then:</p>
1306
1307
1308
1309<ulist>
1310
1311
1312
1313<item><p>if it is a <termref def="dt-top-level">top-level</termref>
1314
1315element and XSLT 1.0 does not allow such elements as top-level
1316
1317elements, then the element must be ignored along with its
1318
1319content;</p></item>
1320
1321
1322
1323<item><p>if it is an element in a template and XSLT 1.0 does not allow
1324
1325such elements to occur in templates, then if the element is not
1326
1327instantiated, an error must not be signaled, and if the element is
1328
1329instantiated, the XSLT must perform fallback for the element as
1330
1331specified in <specref ref="fallback"/>;</p></item>
1332
1333
1334
1335<item><p>if the element has an attribute that XSLT 1.0 does not allow
1336
1337the element to have or if the element has an optional attribute with a
1338
1339value that the XSLT 1.0 does not allow the attribute to have, then the
1340
1341attribute must be ignored.</p></item>
1342
1343
1344
1345</ulist>
1346
1347
1348
1349<p>Thus, any XSLT 1.0 processor must be able to process the following
1350
1351stylesheet without error, although the stylesheet includes elements
1352
1353from the XSLT namespace that are not defined in this
1354
1355specification:</p>
1356
1357
1358
1359<eg>&lt;xsl:stylesheet version="1.1"
1360
1361                xmlns:xsl="&XSLT.ns;"><![CDATA[
1362
1363  <xsl:template match="/">
1364
1365    <xsl:choose>
1366
1367      <xsl:when test="system-property('xsl:version') >= 1.1">
1368
1369        <xsl:exciting-new-1.1-feature/>
1370
1371      </xsl:when>
1372
1373      <xsl:otherwise>
1374
1375        <html>
1376
1377        <head>
1378
1379          <title>XSLT 1.1 required</title>
1380
1381        </head>
1382
1383        <body>
1384
1385          <p>Sorry, this stylesheet requires XSLT 1.1.</p>
1386
1387        </body>
1388
1389        </html>
1390
1391      </xsl:otherwise>
1392
1393    </xsl:choose>
1394
1395  </xsl:template>
1396
1397</xsl:stylesheet>]]></eg>
1398
1399
1400
1401<note><p>If a stylesheet depends crucially on a top-level element
1402
1403introduced by a version of XSL after 1.0, then the stylesheet can use
1404
1405an <code>xsl:message</code> element with <code>terminate="yes"</code>
1406
1407(see <specref ref="message"/>) to ensure that XSLT processors
1408
1409implementing earlier versions of XSL will not silently ignore the
1410
1411top-level element. For example,</p>
1412
1413
1414
1415<eg>&lt;xsl:stylesheet version="1.5"
1416
1417                xmlns:xsl="&XSLT.ns;"><![CDATA[
1418
1419
1420
1421  <xsl:important-new-1.1-declaration/>
1422
1423
1424
1425  <xsl:template match="/">
1426
1427    <xsl:choose>
1428
1429      <xsl:when test="system-property('xsl:version') &lt; 1.1">
1430
1431        <xsl:message terminate="yes">
1432
1433          <xsl:text>Sorry, this stylesheet requires XSLT 1.1.</xsl:text>
1434
1435        </xsl:message>
1436
1437      </xsl:when>
1438
1439      <xsl:otherwise>
1440
1441        ...
1442
1443      </xsl:otherwise>
1444
1445    </xsl:choose>
1446
1447  </xsl:template>
1448
1449  ...
1450
1451</xsl:stylesheet>]]></eg>
1452
1453</note>
1454
1455
1456
1457<p>If an <termref def="dt-expression">expression</termref> occurs in
1458
1459an attribute that is processed in forwards-compatible mode, then an
1460
1461XSLT processor must recover from errors in the expression as
1462
1463follows:</p>
1464
1465
1466
1467<ulist>
1468
1469
1470
1471<item><p>if the expression does not match the syntax allowed by the
1472
1473XPath grammar, then an error must not be signaled unless the
1474
1475expression is actually evaluated;</p></item>
1476
1477
1478
1479<item><p>if the expression calls a function with an unprefixed name
1480
1481that is not part of the XSLT library, then an error must not be
1482
1483signaled unless the function is actually called;</p></item>
1484
1485
1486
1487<item><p>if the expression calls a function with a number of arguments
1488
1489that XSLT does not allow or with arguments of types that XSLT does not
1490
1491allow, then an error must not be signaled unless the function is
1492
1493actually called.</p></item>
1494
1495
1496
1497</ulist>
1498
1499
1500
1501
1502
1503</div2>
1504
1505
1506
1507<div2>
1508
1509<head>Combining Stylesheets</head>
1510
1511
1512
1513<p>XSLT provides two mechanisms to combine stylesheets:</p>
1514
1515
1516
1517<slist>
1518
1519
1520
1521<sitem>an inclusion mechanism that allows stylesheets to be combined
1522
1523without changing the semantics of the stylesheets being combined,
1524
1525and</sitem>
1526
1527
1528
1529<sitem>an import mechanism that allows stylesheets to override each
1530
1531other.</sitem>
1532
1533
1534
1535</slist>
1536
1537
1538
1539<div3 id="include">
1540
1541<head>Stylesheet Inclusion</head>
1542
1543
1544
1545<e:element-syntax name="include">
1546
1547  <e:in-category name="top-level-element"/>
1548
1549  <e:attribute name="href" required="yes">
1550
1551    <e:data-type name="uri-reference"/>
1552
1553  </e:attribute>
1554
1555  <e:empty/>
1556
1557</e:element-syntax>
1558
1559
1560
1561<p>An XSLT stylesheet may include another XSLT stylesheet using an
1562
1563<code>xsl:include</code> element. The <code>xsl:include</code> element
1564
1565has an <code>href</code> attribute whose value is a URI reference
1566
1567identifying the stylesheet to be included.  A relative URI is resolved
1568
1569relative to the base URI of the <code>xsl:include</code> element (see
1570
1571<specref ref="base-uri"/>).</p>
1572
1573
1574
1575<p>The <code>xsl:include</code> element is only allowed as a <termref
1576
1577def="dt-top-level">top-level</termref> element.</p>
1578
1579
1580
1581<p>The inclusion works at the XML tree level.  The resource located by
1582
1583the <code>href</code> attribute value is parsed as an XML document,
1584
1585and the children of the <code>xsl:stylesheet</code> element in this
1586
1587document replace the <code>xsl:include</code> element in the including
1588
1589document.  The fact that template rules or definitions are included
1590
1591does not affect the way they are processed.</p>
1592
1593
1594
1595<p>The included stylesheet may use the simplified syntax described in
1596
1597<specref ref="result-element-stylesheet"/>.  The included stylesheet
1598
1599is treated the same as the equivalent <code>xsl:stylesheet</code>
1600
1601element.</p>
1602
1603
1604
1605<p>It is an error if a stylesheet directly or indirectly includes
1606
1607itself.</p>
1608
1609
1610
1611<note><p>Including a stylesheet multiple times can cause errors
1612
1613because of duplicate definitions.  Such multiple inclusions are less
1614
1615obvious when they are indirect. For example, if stylesheet
1616
1617<var>B</var> includes stylesheet <var>A</var>, stylesheet <var>C</var>
1618
1619includes stylesheet <var>A</var>, and stylesheet <var>D</var> includes
1620
1621both stylesheet <var>B</var> and stylesheet <var>C</var>, then
1622
1623<var>A</var> will be included indirectly by <var>D</var> twice.  If
1624
1625all of <var>B</var>, <var>C</var> and <var>D</var> are used as
1626
1627independent stylesheets, then the error can be avoided by separating
1628
1629everything in <var>B</var> other than the inclusion of <var>A</var>
1630
1631into a separate stylesheet <var>B'</var> and changing <var>B</var> to
1632
1633contain just inclusions of <var>B'</var> and <var>A</var>, similarly
1634
1635for <var>C</var>, and then changing <var>D</var> to include
1636
1637<var>A</var>, <var>B'</var>, <var>C'</var>.</p></note>
1638
1639
1640
1641</div3>
1642
1643
1644
1645<div3 id="import">
1646
1647<head>Stylesheet Import</head>
1648
1649
1650
1651<e:element-syntax name="import">
1652
1653  <e:attribute name="href" required="yes">
1654
1655    <e:data-type name="uri-reference"/>
1656
1657  </e:attribute>
1658
1659  <e:empty/>
1660
1661</e:element-syntax>
1662
1663
1664
1665<p>An XSLT stylesheet may import another XSLT stylesheet using an
1666
1667<code>xsl:import</code> element.  Importing a stylesheet is the same
1668
1669as including it (see <specref ref="include"/>) except that definitions
1670
1671and template rules in the importing stylesheet take precedence over
1672
1673template rules and definitions in the imported stylesheet; this is
1674
1675described in more detail below.  The <code>xsl:import</code> element
1676
1677has an <code>href</code> attribute whose value is a URI reference
1678
1679identifying the stylesheet to be imported.  A relative URI is resolved
1680
1681relative to the base URI of the <code>xsl:import</code> element (see
1682
1683<specref ref="base-uri"/>).</p>
1684
1685
1686
1687<p>The <code>xsl:import</code> element is only allowed as a <termref
1688
1689def="dt-top-level">top-level</termref> element.  The
1690
1691<code>xsl:import</code> element children must precede all other
1692
1693element children of an <code>xsl:stylesheet</code> element, including
1694
1695any <code>xsl:include</code> element children.  When
1696
1697<code>xsl:include</code> is used to include a stylesheet, any
1698
1699<code>xsl:import</code> elements in the included document are moved up
1700
1701in the including document to after any existing
1702
1703<code>xsl:import</code> elements in the including document.</p>
1704
1705
1706
1707<p>For example,</p>
1708
1709
1710
1711<eg>&lt;xsl:stylesheet version="1.0"
1712
1713                xmlns:xsl="&XSLT.ns;"><![CDATA[
1714
1715  <xsl:import href="article.xsl"/>
1716
1717  <xsl:import href="bigfont.xsl"/>
1718
1719  <xsl:attribute-set name="note-style">
1720
1721    <xsl:attribute name="font-style">italic</xsl:attribute>
1722
1723  </xsl:attribute-set>
1724
1725</xsl:stylesheet>]]></eg>
1726
1727
1728
1729<p><termdef id="dt-import-tree" term="Import Tree">The
1730
1731<code>xsl:stylesheet</code> elements encountered during processing of
1732
1733a stylesheet that contains <code>xsl:import</code> elements are
1734
1735treated as forming an <term>import tree</term>.  In the import tree,
1736
1737each <code>xsl:stylesheet</code> element has one import child for each
1738
1739<code>xsl:import</code> element that it contains. Any
1740
1741<code>xsl:include</code> elements are resolved before constructing the
1742
1743import tree.</termdef> <termdef id="dt-import-precedence" term="Import
1744
1745Precedence">An <code>xsl:stylesheet</code> element in the import tree
1746
1747is defined to have lower <term>import precedence</term> than another
1748
1749<code>xsl:stylesheet</code> element in the import tree if it would be
1750
1751visited before that <code>xsl:stylesheet</code> element in a
1752
1753post-order traversal of the import tree (i.e. a traversal of the
1754
1755import tree in which an <code>xsl:stylesheet</code> element is visited
1756
1757after its import children).</termdef> Each definition and template
1758
1759rule has import precedence determined by the
1760
1761<code>xsl:stylesheet</code> element that contains it.</p>
1762
1763
1764
1765<p>For example, suppose</p>
1766
1767
1768
1769<ulist>
1770
1771
1772
1773<item><p>stylesheet <var>A</var> imports stylesheets <var>B</var>
1774
1775and <var>C</var> in that order;</p></item>
1776
1777
1778
1779<item><p>stylesheet <var>B</var> imports stylesheet
1780
1781<var>D</var>;</p></item>
1782
1783
1784
1785<item><p>stylesheet <var>C</var> imports stylesheet
1786
1787<var>E</var>.</p></item>
1788
1789
1790
1791</ulist>
1792
1793
1794
1795<p>Then the order of import precedence (lowest first) is
1796
1797<var>D</var>, <var>B</var>, <var>E</var>, <var>C</var>,
1798
1799<var>A</var>.</p>
1800
1801
1802
1803<note><p>Since <code>xsl:import</code> elements are required to occur
1804
1805before any definitions or template rules, an implementation that
1806
1807processes imported stylesheets at the point at which it encounters the
1808
1809<code>xsl:import</code> element will encounter definitions and
1810
1811template rules in increasing order of import precedence.</p></note>
1812
1813
1814
1815<p>In general, a definition or template rule with higher import
1816
1817precedence takes precedence over a definition or template rule with
1818
1819lower import precedence.  This is defined in detail for each kind of
1820
1821definition and for template rules.</p>
1822
1823
1824
1825<p>It is an error if a stylesheet directly or indirectly imports
1826
1827itself. Apart from this, the case where a stylesheet with a particular
1828
1829URI is imported in multiple places is not treated specially. The
1830
1831<termref def="dt-import-tree">import tree</termref> will have a
1832
1833separate <code>xsl:stylesheet</code> for each place that it is
1834
1835imported.</p>
1836
1837
1838
1839<note><p>If <code>xsl:apply-imports</code> is used (see <specref
1840
1841ref="apply-imports"/>), the behavior may be different from the
1842
1843behavior if the stylesheet had been imported only at the place with
1844
1845the highest <termref def="dt-import-precedence">import
1846
1847precedence</termref>.</p></note>
1848
1849
1850
1851</div3>
1852
1853
1854
1855</div2>
1856
1857
1858
1859<div2>
1860
1861<head>Embedding Stylesheets</head>
1862
1863
1864
1865<p>Normally an XSLT stylesheet is a complete XML document with the
1866
1867<code>xsl:stylesheet</code> element as the document element. However,
1868
1869an XSLT stylesheet may also be embedded in another resource. Two forms
1870
1871of embedding are possible:</p>
1872
1873
1874
1875<slist>
1876
1877
1878
1879<sitem>the XSLT stylesheet may be textually embedded in a non-XML
1880
1881resource, or</sitem>
1882
1883
1884
1885<sitem>the <code>xsl:stylesheet</code> element may occur in an XML
1886
1887document other than as the document element.</sitem>
1888
1889
1890
1891</slist>
1892
1893
1894
1895<p>To facilitate the second form of embedding, the
1896
1897<code>xsl:stylesheet</code> element is allowed to have an ID attribute
1898
1899that specifies a unique identifier.</p>
1900
1901
1902
1903<note><p>In order for such an attribute to be used with the XPath
1904
1905<xfunction>id</xfunction> function, it must actually be declared in
1906
1907the DTD as being an ID.</p></note>
1908
1909
1910
1911<p>The following example shows how the <code>xml-stylesheet</code>
1912
1913processing instruction <bibref ref="XMLSTYLE"/> can be used to allow a
1914
1915document to contain its own stylesheet.  The URI reference uses a
1916
1917relative URI with a fragment identifier to locate the
1918
1919<code>xsl:stylesheet</code> element:</p>
1920
1921
1922
1923<eg><![CDATA[<?xml-stylesheet type="text/xml" href="#style1"?>
1924
1925<!DOCTYPE doc SYSTEM "doc.dtd">
1926
1927<doc>
1928
1929<head>
1930
1931<xsl:stylesheet id="style1"
1932
1933                version="1.0"]]>
1934
1935                xmlns:xsl="&XSLT.ns;"
1936
1937                xmlns:fo="&XSLFO.ns;"><![CDATA[
1938
1939<xsl:import href="doc.xsl"/>
1940
1941<xsl:template match="id('foo')">
1942
1943  <fo:block font-weight="bold"><xsl:apply-templates/></fo:block>
1944
1945</xsl:template>
1946
1947<xsl:template match="xsl:stylesheet">
1948
1949  <!-- ignore -->
1950
1951</xsl:template>
1952
1953</xsl:stylesheet>
1954
1955</head>
1956
1957<body>
1958
1959<para id="foo">
1960
1961...
1962
1963</para>
1964
1965</body>
1966
1967</doc>
1968
1969]]></eg>
1970
1971
1972
1973<note><p>A stylesheet that is embedded in the document to which it is
1974
1975to be applied or that may be included or imported into an stylesheet
1976
1977that is so embedded typically needs to contain a template rule that
1978
1979specifies that <code>xsl:stylesheet</code> elements are to be
1980
1981ignored.</p></note>
1982
1983
1984
1985</div2>
1986
1987
1988
1989</div1>
1990
1991
1992
1993<div1 id="data-model">
1994
1995<head>Data Model</head>
1996
1997
1998
1999<p>The data model used by XSLT is the same as that used by <xspecref
2000
2001href="&XPath;#data-model">XPath</xspecref> with the additions
2002
2003described in this section.  XSLT operates on source, result and
2004
2005stylesheet documents using the same data model.  Any two XML documents
2006
2007that have the same tree will be treated the same by XSLT.</p>
2008
2009
2010
2011<p>Processing instructions and comments in the stylesheet are ignored:
2012
2013the stylesheet is treated as if neither processing instruction nodes
2014
2015nor comment nodes were included in the tree that represents the
2016
2017stylesheet.</p>
2018
2019
2020
2021<div2 id="root-node-children">
2022
2023<head>Root Node Children</head>
2024
2025
2026
2027<p>The normal restrictions on the children of the root node are
2028
2029relaxed for the result tree.  The result tree may have any sequence of
2030
2031nodes as children that would be possible for an element node. In
2032
2033particular, it may have text node children, and any number of element
2034
2035node children. When written out using the XML output method (see
2036
2037<specref ref="output"/>), it is possible that a result tree will not
2038
2039be a well-formed XML document; however, it will always be a
2040
2041well-formed external general parsed entity.</p>
2042
2043
2044
2045<p>When the source tree is created by parsing a well-formed XML
2046
2047document, the root node of the source tree will automatically satisfy
2048
2049the normal restrictions of having no text node children and exactly
2050
2051one element child.  When the source tree is created in some other way,
2052
2053for example by using the DOM, the usual restrictions are relaxed for
2054
2055the source tree as for the result tree.</p>
2056
2057
2058
2059</div2>
2060
2061
2062
2063<div2 id="base-uri">
2064
2065<head>Base URI</head>
2066
2067
2068
2069<p>Every node also has an associated URI called its base URI, which is
2070
2071used for resolving attribute values that represent relative URIs into
2072
2073absolute URIs.  If an element or processing instruction occurs in an
2074
2075external entity, the base URI of that element or processing
2076
2077instruction is the URI of the external entity; otherwise, the base URI
2078
2079is the base URI of the document.  The base URI of the document node is
2080
2081the URI of the document entity.  The base URI for a text node, a
2082
2083comment node, an attribute node or a namespace node is the base URI of
2084
2085the parent of the node.</p>
2086
2087
2088
2089</div2>
2090
2091
2092
2093<div2 id="unparsed-entities">
2094
2095<head>Unparsed Entities</head>
2096
2097
2098
2099<p>The root node has a mapping that gives the URI for each unparsed
2100
2101entity declared in the document's DTD.  The URI is generated from the
2102
2103system identifier and public identifier specified in the entity
2104
2105declaration. The XSLT processor may use the public identifier to
2106
2107generate a URI for the entity instead of the URI specified in the
2108
2109system identifier.  If the XSLT processor does not use the public
2110
2111identifier to generate the URI, it must use the system identifier; if
2112
2113the system identifier is a relative URI, it must be resolved into an
2114
2115absolute URI using the URI of the resource containing the entity
2116
2117declaration as the base URI <bibref ref="RFC2396"/>.</p>
2118
2119
2120
2121</div2>
2122
2123
2124
2125<div2 id="strip">
2126
2127<head>Whitespace Stripping</head>
2128
2129
2130
2131<p>After the tree for a source document or stylesheet document has
2132
2133been constructed, but before it is otherwise processed by XSLT,
2134
2135some text nodes are stripped.  A text node is never stripped
2136
2137unless it contains only whitespace characters.  Stripping the text
2138
2139node removes the text node from the tree.  The stripping process takes
2140
2141as input a set of element names for which whitespace must be
2142
2143preserved.  The stripping process is applied to both stylesheets and
2144
2145source documents, but the set of whitespace-preserving element names
2146
2147is determined differently for stylesheets and for source
2148
2149documents.</p>
2150
2151
2152
2153<p>A text node is preserved if any of the following apply:</p>
2154
2155
2156
2157<ulist>
2158
2159
2160
2161<item><p>The element name of the parent of the text node is in the set
2162
2163of whitespace-preserving element names.</p></item>
2164
2165
2166
2167<item><p>The text node contains at least one non-whitespace character.
2168
2169As in XML, a whitespace character is #x20, #x9, #xD or #xA.</p></item>
2170
2171
2172
2173<item><p>An ancestor element of the text node has an
2174
2175<code>xml:space</code> attribute with a value of
2176
2177<code>preserve</code>, and no closer ancestor element has
2178
2179<code>xml:space</code> with a value of
2180
2181<code>default</code>.</p></item>
2182
2183
2184
2185</ulist>
2186
2187
2188
2189<p>Otherwise, the text node is stripped.</p>
2190
2191
2192
2193<p>The <code>xml:space</code> attributes are not stripped from the
2194
2195tree.</p>
2196
2197
2198
2199<note><p>This implies that if an <code>xml:space</code> attribute is
2200
2201specified on a literal result element, it will be included in the
2202
2203result.</p></note>
2204
2205
2206
2207<p>For stylesheets, the set of whitespace-preserving element names
2208
2209consists of just <code>xsl:text</code>.</p>
2210
2211
2212
2213<e:element-syntax name="strip-space">
2214
2215  <e:in-category name="top-level-element"/>
2216
2217  <e:attribute name="elements" required="yes">
2218
2219    <e:data-type name="tokens"/>
2220
2221  </e:attribute>
2222
2223  <e:empty/>
2224
2225</e:element-syntax>
2226
2227
2228
2229<e:element-syntax name="preserve-space">
2230
2231  <e:in-category name="top-level-element"/>
2232
2233  <e:attribute name="elements" required="yes">
2234
2235    <e:data-type name="tokens"/>
2236
2237  </e:attribute>
2238
2239  <e:empty/>
2240
2241</e:element-syntax>
2242
2243
2244
2245<p>For source documents, the set of whitespace-preserving element
2246
2247names is specified by <code>xsl:strip-space</code> and
2248
2249<code>xsl:preserve-space</code> <termref
2250
2251def="dt-top-level">top-level</termref> elements.  These elements each
2252
2253have an <code>elements</code> attribute whose value is a
2254
2255whitespace-separated list of <xnt
2256
2257href="&XPath;#NT-NameTest">NameTest</xnt>s.  Initially, the
2258
2259set of whitespace-preserving element names contains all element names.
2260
2261If an element name matches a <xnt
2262
2263href="&XPath;#NT-NameTest">NameTest</xnt> in an
2264
2265<code>xsl:strip-space</code> element, then it is removed from the set
2266
2267of whitespace-preserving element names.  If an element name matches a
2268
2269<xnt href="&XPath;#NT-NameTest">NameTest</xnt> in an
2270
2271<code>xsl:preserve-space</code> element, then it is added to the set
2272
2273of whitespace-preserving element names.  An element matches a <xnt
2274
2275href="&XPath;#NT-NameTest">NameTest</xnt> if and only if the
2276
2277<xnt href="&XPath;#NT-NameTest">NameTest</xnt> would be true
2278
2279for the element as an <xspecref href="&XPath;#node-tests">XPath node
2280
2281test</xspecref>.  Conflicts between matches to
2282
2283<code>xsl:strip-space</code> and <code>xsl:preserve-space</code>
2284
2285elements are resolved the same way as conflicts between template rules
2286
2287(see <specref ref="conflict"/>).  Thus, the applicable match for a
2288
2289particular element name is determined as follows:</p>
2290
2291
2292
2293<ulist>
2294
2295
2296
2297<item><p>First, any match with lower <termref
2298
2299def="dt-import-precedence">import precedence</termref> than another
2300
2301match is ignored.</p></item>
2302
2303
2304
2305<item><p>Next, any match with a <xnt
2306
2307href="&XPath;#NT-NameTest">NameTest</xnt> that has a lower
2308
2309<termref def="dt-default-priority">default priority</termref> than the
2310
2311<termref def="dt-default-priority">default priority</termref> of the
2312
2313<xnt href="&XPath;#NT-NameTest">NameTest</xnt> of another
2314
2315match is ignored.</p></item>
2316
2317
2318
2319</ulist>
2320
2321
2322
2323<p>It is an error if this leaves more than one match.  An XSLT
2324
2325processor may signal the error; if it does not signal the error, it
2326
2327must recover by choosing, from amongst the matches that are left, the
2328
2329one that occurs last in the stylesheet.</p>
2330
2331
2332
2333</div2>
2334
2335
2336
2337</div1>
2338
2339
2340
2341<div1>
2342
2343<head>Expressions</head>
2344
2345
2346
2347<p>XSLT uses the expression language defined by XPath <bibref
2348
2349ref="XPATH"/>.  Expressions are used in XSLT for a variety of purposes
2350
2351including:</p>
2352
2353
2354
2355<slist>
2356
2357<sitem>selecting nodes for processing;</sitem>
2358
2359<sitem>specifying conditions for different ways of processing a node;</sitem>
2360
2361<sitem>generating text to be inserted in the result tree.</sitem>
2362
2363</slist>
2364
2365
2366
2367<p><termdef id="dt-expression" term="Expression">An
2368
2369<term>expression</term> must match the XPath production <xnt
2370
2371href="&XPath;#NT-Expr">Expr</xnt>.</termdef></p>
2372
2373
2374
2375<p>Expressions occur as the value of certain attributes on
2376
2377XSLT-defined elements and within curly braces in <termref
2378
2379def="dt-attribute-value-template">attribute value
2380
2381template</termref>s.</p>
2382
2383
2384
2385<p>In XSLT, an outermost expression (i.e. an expression that is not
2386
2387part of another expression) gets its context as follows:</p>
2388
2389
2390
2391<ulist>
2392
2393
2394
2395<item><p>the context node comes from the <termref
2396
2397def="dt-current-node">current node</termref></p></item>
2398
2399
2400
2401<item><p>the context position comes from the position of the <termref
2402
2403def="dt-current-node">current node</termref> in the <termref
2404
2405def="dt-current-node-list">current node list</termref>; the first
2406
2407position is 1</p></item>
2408
2409
2410
2411<item><p>the context size comes from the size of the <termref
2412
2413def="dt-current-node-list">current node list</termref></p></item>
2414
2415
2416
2417<item><p>the variable bindings are the bindings in scope on the
2418
2419element which has the attribute in which the expression occurs (see
2420
2421<specref ref="variables"/>)</p></item>
2422
2423
2424
2425<item><p>the set of namespace declarations are those in scope on the
2426
2427element which has the attribute in which the expression occurs;
2428
2429this includes the implicit declaration of the prefix <code>xml</code>
2430
2431required by the the XML Namespaces Recommendation <bibref ref="XMLNAMES"/>;
2432
2433the default
2434
2435namespace (as declared by <code>xmlns</code>) is not part of this
2436
2437set</p></item>
2438
2439
2440
2441<item><p>the function library consists of the core function library
2442
2443together with the additional functions defined in <specref
2444
2445ref="add-func"/> and extension functions as described in <specref
2446
2447ref="extension"/>; it is an error for an expression to include a call
2448
2449to any other function</p></item>
2450
2451
2452
2453</ulist>
2454
2455
2456
2457</div1>
2458
2459
2460
2461<div1 id="rules">
2462
2463<head>Template Rules</head>
2464
2465
2466
2467<div2>
2468
2469<head>Processing Model</head>
2470
2471
2472
2473<p>A list of source nodes is processed to create a result tree
2474
2475fragment.  The result tree is constructed by processing a list
2476
2477containing just the root node.  A list of source nodes is processed by
2478
2479appending the result tree structure created by processing each of the
2480
2481members of the list in order.  A node is processed by finding all the
2482
2483template rules with patterns that match the node, and choosing the
2484
2485best amongst them; the chosen rule's template is then instantiated
2486
2487with the node as the <termref def="dt-current-node">current
2488
2489node</termref> and with the list of source nodes as the <termref
2490
2491def="dt-current-node-list">current node list</termref>.  A template
2492
2493typically contains instructions that select an additional list of
2494
2495source nodes for processing.  The process of matching, instantiation
2496
2497and selection is continued recursively until no new source nodes are
2498
2499selected for processing.</p>
2500
2501
2502
2503<p>Implementations are free to process the source document in any way
2504
2505that produces the same result as if it were processed using this
2506
2507processing model.</p>
2508
2509
2510
2511</div2>
2512
2513
2514
2515<div2 id="patterns">
2516
2517<head>Patterns</head>
2518
2519
2520
2521<p><termdef id="dt-pattern" term="Pattern">Template rules identify the
2522
2523nodes to which they apply by using a <term>pattern</term>.  As well as
2524
2525being used in template rules, patterns are used for numbering (see
2526
2527<specref ref="number"/>) and for declaring keys (see <specref
2528
2529ref="key"/>).  A pattern specifies a set of conditions on a node.  A
2530
2531node that satisfies the conditions matches the pattern; a node that
2532
2533does not satisfy the conditions does not match the pattern.  The
2534
2535syntax for patterns is a subset of the syntax for expressions. In
2536
2537particular, location paths that meet certain restrictions can be used
2538
2539as patterns.  An expression that is also a pattern always evaluates to
2540
2541an object of type node-set.  A node matches a pattern if the node is a
2542
2543member of the result of evaluating the pattern as an expression with
2544
2545respect to some possible context; the possible contexts are those
2546
2547whose context node is the node being matched or one of its
2548
2549ancestors.</termdef></p>
2550
2551
2552
2553<p>Here are some examples of patterns:</p>
2554
2555
2556
2557<ulist>
2558
2559
2560
2561<item><p><code>para</code> matches any <code>para</code> element</p></item>
2562
2563
2564
2565<item><p><code>*</code> matches any element</p></item>
2566
2567
2568
2569<item><p><code>chapter|appendix</code> matches any
2570
2571<code>chapter</code> element and any <code>appendix</code>
2572
2573element</p></item>
2574
2575
2576
2577<item><p><code>olist/item</code> matches any <code>item</code> element with
2578
2579an <code>olist</code> parent</p></item>
2580
2581
2582
2583<item><p><code>appendix//para</code> matches any <code>para</code> element with
2584
2585an <code>appendix</code> ancestor element</p></item>
2586
2587
2588
2589<item><p><code>/</code> matches the root node</p></item>
2590
2591
2592
2593<item><p><code>text()</code> matches any text node</p></item>
2594
2595
2596
2597<item><p><code>processing-instruction()</code> matches any processing
2598
2599instruction</p></item>
2600
2601
2602
2603<item><p><code>node()</code> matches any node other than an attribute
2604
2605node and the root node</p></item>
2606
2607
2608
2609<item><p><code>id("W11")</code> matches the element with unique ID
2610
2611<code>W11</code></p></item>
2612
2613
2614
2615<item><p><code>para[1]</code> matches any <code>para</code> element
2616
2617that is the first <code>para</code> child element of its
2618
2619parent</p></item>
2620
2621
2622
2623<item><p><code>*[position()=1 and self::para]</code> matches any
2624
2625<code>para</code> element that is the first child element of its
2626
2627parent</p></item>
2628
2629
2630
2631<item><p><code>para[last()=1]</code> matches any <code>para</code>
2632
2633element that is the only <code>para</code> child element of its
2634
2635parent</p></item>
2636
2637
2638
2639<item><p><code>items/item[position()>1]</code> matches any
2640
2641<code>item</code> element that has a <code>items</code> parent and
2642
2643that is not the first <code>item</code> child of its parent</p></item>
2644
2645
2646
2647<item><p><code>item[position() mod 2 = 1]</code> would be true for any
2648
2649<code>item</code> element that is an odd-numbered <code>item</code>
2650
2651child of its parent.</p></item>
2652
2653
2654
2655<item><p><code>div[@class="appendix"]//p</code> matches any
2656
2657<code>p</code> element with a <code>div</code> ancestor element that
2658
2659has a <code>class</code> attribute with value
2660
2661<code>appendix</code></p></item>
2662
2663
2664
2665<item><p><code>@class</code> matches any <code>class</code> attribute
2666
2667(<emph>not</emph> any element that has a <code>class</code>
2668
2669attribute)</p></item>
2670
2671
2672
2673<item><p><code>@*</code> matches any attribute</p></item>
2674
2675
2676
2677</ulist>
2678
2679
2680
2681<p>A pattern must match the grammar for <nt
2682
2683def="NT-Pattern">Pattern</nt>.  A <nt def="NT-Pattern">Pattern</nt> is
2684
2685a set of location path patterns separated by <code>|</code>.  A
2686
2687location path pattern is a location path whose steps all use only the
2688
2689<code>child</code> or <code>attribute</code> axes.  Although patterns
2690
2691must not use the <code>descendant-or-self</code> axis, patterns may
2692
2693use the <code>//</code> operator as well as the <code>/</code>
2694
2695operator.  Location path patterns can also start with an
2696
2697<xfunction>id</xfunction> or <function>key</function> function call
2698
2699with a literal argument.  Predicates in a pattern can use arbitrary
2700
2701expressions just like predicates in a location path.</p>
2702
2703
2704
2705<scrap>
2706
2707<head>Patterns</head>
2708
2709<prodgroup pcw5="1" pcw2="10">
2710
2711<prod id="NT-Pattern">
2712
2713<lhs>Pattern</lhs>
2714
2715<rhs><nt def="NT-LocationPathPattern">LocationPathPattern</nt></rhs>
2716
2717<rhs>| <nt def="NT-Pattern">Pattern</nt> '|' <nt def="NT-LocationPathPattern">LocationPathPattern</nt></rhs>
2718
2719</prod>
2720
2721<prod id="NT-LocationPathPattern">
2722
2723<lhs>LocationPathPattern</lhs>
2724
2725<rhs>'/' <nt def="NT-RelativePathPattern">RelativePathPattern</nt>?</rhs>
2726
2727<rhs>| <nt def="NT-IdKeyPattern">IdKeyPattern</nt> (('/' | '//') <nt def="NT-RelativePathPattern">RelativePathPattern</nt>)?</rhs>
2728
2729<rhs>| '//'? <nt def="NT-RelativePathPattern">RelativePathPattern</nt></rhs>
2730
2731</prod>
2732
2733<prod id="NT-IdKeyPattern">
2734
2735<lhs>IdKeyPattern</lhs>
2736
2737<rhs>'id' '(' <xnt href="&XPath;#NT-Literal">Literal</xnt> ')'</rhs>
2738
2739<rhs>| 'key' '(' <xnt href="&XPath;#NT-Literal">Literal</xnt> ',' <xnt href="&XPath;#NT-Literal">Literal</xnt> ')'</rhs>
2740
2741</prod>
2742
2743<prod id="NT-RelativePathPattern">
2744
2745<lhs>RelativePathPattern</lhs>
2746
2747<rhs><nt def="NT-StepPattern">StepPattern</nt></rhs>
2748
2749<rhs>| <nt def="NT-RelativePathPattern">RelativePathPattern</nt> '/' <nt def="NT-StepPattern">StepPattern</nt></rhs>
2750
2751<rhs>| <nt def="NT-RelativePathPattern">RelativePathPattern</nt> '//' <nt def="NT-StepPattern">StepPattern</nt></rhs>
2752
2753</prod>
2754
2755<prod id="NT-StepPattern">
2756
2757<lhs>StepPattern</lhs>
2758
2759<rhs>
2760
2761<nt def="NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</nt>
2762
2763<xnt href="&XPath;#NT-NodeTest">NodeTest</xnt>
2764
2765<xnt href="&XPath;#NT-Predicate">Predicate</xnt>*
2766
2767</rhs>
2768
2769</prod>
2770
2771<prod id="NT-ChildOrAttributeAxisSpecifier">
2772
2773<lhs>ChildOrAttributeAxisSpecifier</lhs>
2774
2775<rhs><xnt href="&XPath;#NT-AbbreviatedAxisSpecifier">AbbreviatedAxisSpecifier</xnt></rhs>
2776
2777<rhs>| ('child' | 'attribute') '::'</rhs>
2778
2779</prod>
2780
2781</prodgroup>
2782
2783</scrap>
2784
2785
2786
2787<p>A pattern is defined to match a node if and only if there is
2788
2789possible context such that when the pattern is evaluated as an
2790
2791expression with that context, the node is a member of the resulting
2792
2793node-set.  When a node is being matched, the possible contexts have a
2794
2795context node that is the node being matched or any ancestor of that
2796
2797node, and a context node list containing just the context node.</p>
2798
2799
2800
2801<p>For example, <code>p</code> matches any <code>p</code> element,
2802
2803because for any <code>p</code> if the expression <code>p</code> is
2804
2805evaluated with the parent of the <code>p</code> element as context the
2806
2807resulting node-set will contain that <code>p</code> element as one of
2808
2809its members.</p>
2810
2811
2812
2813<note><p>This matches even a <code>p</code> element that is the
2814
2815document element, since the document root is the parent of the
2816
2817document element.</p></note>
2818
2819
2820
2821<p>Although the semantics of patterns are specified indirectly in
2822
2823terms of expression evaluation, it is easy to understand the meaning
2824
2825of a pattern directly without thinking in terms of expression
2826
2827evaluation.  In a pattern, <code>|</code> indicates alternatives; a
2828
2829pattern with one or more <code>|</code> separated alternatives matches
2830
2831if any one of the alternative matches.  A pattern that consists of a
2832
2833sequence of <nt def="NT-StepPattern">StepPattern</nt>s separated by
2834
2835<code>/</code> or <code>//</code> is matched from right to left.  The
2836
2837pattern only matches if the rightmost <nt
2838
2839def="NT-StepPattern">StepPattern</nt> matches and a suitable element
2840
2841matches the rest of the pattern; if the separator is <code>/</code>
2842
2843then only the parent is a suitable element; if the separator is
2844
2845<code>//</code>, then any ancestor is a suitable element.  A <nt
2846
2847def="NT-StepPattern">StepPattern</nt> that uses the child axis matches
2848
2849if the <xnt href="&XPath;#NT-NodeTest">NodeTest</xnt> is true for the
2850
2851node and the node is not an attribute node.  A <nt
2852
2853def="NT-StepPattern">StepPattern</nt> that uses the attribute axis
2854
2855matches if the <xnt href="&XPath;#NT-NodeTest">NodeTest</xnt> is true
2856
2857for the node and the node is an attribute node.  When <code>[]</code>
2858
2859is present, then the first <xnt
2860
2861href="&XPath;#NT-PredicateExpr">PredicateExpr</xnt> in a <nt
2862
2863def="NT-StepPattern">StepPattern</nt> is evaluated with the node being
2864
2865matched as the context node and the siblings of the context node that
2866
2867match the <xnt href="&XPath;#NT-NodeTest">NodeTest</xnt> as the
2868
2869context node list, unless the node being matched is an attribute node,
2870
2871in which case the context node list is all the attributes that have
2872
2873the same parent as the attribute being matched and that match the <xnt
2874
2875href="&XPath;#NT-NameTest">NameTest</xnt>.</p>
2876
2877
2878
2879<p>For example</p>
2880
2881
2882
2883<eg>appendix//ulist/item[position()=1]</eg>
2884
2885
2886
2887<p>matches a node if and only if all of the following are true:</p>
2888
2889
2890
2891<ulist>
2892
2893
2894
2895<item><p>the <xnt href="&XPath;#NT-NodeTest">NodeTest</xnt> <code>item</code> is
2896
2897true for the node and the node is not an attribute; in other words the
2898
2899node is an <code>item</code> element</p></item>
2900
2901
2902
2903<item><p>evaluating the <xnt href="&XPath;#NT-PredicateExpr">PredicateExpr</xnt>
2904
2905<code>position()=1</code> with the node as context node and the
2906
2907siblings of the node that are <code>item</code> elements as the
2908
2909context node list yields true</p></item>
2910
2911
2912
2913<item><p>the node has a parent that matches
2914
2915<code>appendix//ulist</code>; this will be true if the parent is a
2916
2917<code>ulist</code> element that has an <code>appendix</code> ancestor
2918
2919element.</p></item>
2920
2921
2922
2923</ulist>
2924
2925
2926
2927</div2>
2928
2929
2930
2931<div2>
2932
2933<head>Defining Template Rules</head>
2934
2935
2936
2937<e:element-syntax name="template">
2938
2939  <e:in-category name="top-level-element"/>
2940
2941  <e:attribute name="match">
2942
2943    <e:data-type name="pattern"/>
2944
2945  </e:attribute>
2946
2947  <e:attribute name="name">
2948
2949    <e:data-type name="qname"/>
2950
2951  </e:attribute>
2952
2953  <e:attribute name="priority">
2954
2955    <e:data-type name="number"/>
2956
2957  </e:attribute>
2958
2959  <e:attribute name="mode">
2960
2961    <e:data-type name="qname"/>
2962
2963  </e:attribute>
2964
2965  <e:sequence>
2966
2967    <e:element repeat="zero-or-more" name="param"/>
2968
2969    <e:model name="template"/>
2970
2971  </e:sequence>
2972
2973</e:element-syntax>
2974
2975
2976
2977<p>A template rule is specified with the <code>xsl:template</code>
2978
2979element. The <code>match</code> attribute is a <nt
2980
2981def="NT-Pattern">Pattern</nt> that identifies the source node or nodes
2982
2983to which the rule applies.  The <code>match</code> attribute is
2984
2985required unless the <code>xsl:template</code> element has a
2986
2987<code>name</code> attribute (see <specref ref="named-templates"/>).
2988
2989It is an error for the value of the <code>match</code> attribute to
2990
2991contain a <xnt
2992
2993href="&XPath;#NT-VariableReference">VariableReference</xnt>. The
2994
2995content of the <code>xsl:template</code> element is the template that
2996
2997is instantiated when the template rule is applied.</p>
2998
2999
3000
3001<p>For example, an XML document might contain:</p>
3002
3003
3004
3005<eg><![CDATA[This is an <emph>important</emph> point.]]></eg>
3006
3007
3008
3009<p>The following template rule matches <code>emph</code> elements and
3010
3011produces a <code>fo:inline-sequence</code> formatting object with a
3012
3013<code>font-weight</code> property of <code>bold</code>.</p>
3014
3015
3016
3017<eg><![CDATA[<xsl:template match="emph">
3018
3019  <fo:inline-sequence font-weight="bold">
3020
3021    <xsl:apply-templates/>
3022
3023  </fo:inline-sequence>
3024
3025</xsl:template>
3026
3027]]></eg>
3028
3029
3030
3031<note><p>Examples in this document use the <code>fo:</code> prefix for
3032
3033the namespace <code>&XSLFO.ns;</code>, which is
3034
3035the namespace of the formatting objects defined in <bibref
3036
3037ref="XSL"/>.</p></note>
3038
3039
3040
3041<p>As described next, the <code>xsl:apply-templates</code> element
3042
3043recursively processes the children of the source element.</p>
3044
3045
3046
3047</div2>
3048
3049
3050
3051<div2>
3052
3053<head>Applying Template Rules</head>
3054
3055
3056
3057<e:element-syntax name="apply-templates">
3058
3059  <e:in-category name="instruction"/>
3060
3061  <e:attribute name="select">
3062
3063    <e:data-type name="node-set-expression"/>
3064
3065  </e:attribute>
3066
3067  <e:attribute name="mode">
3068
3069    <e:data-type name="qname"/>
3070
3071  </e:attribute>
3072
3073  <e:choice repeat="zero-or-more">
3074
3075    <e:element name="sort"/>
3076
3077    <e:element name="with-param"/>
3078
3079  </e:choice>
3080
3081</e:element-syntax>
3082
3083
3084
3085<p>This example creates a block for a <code>chapter</code> element and
3086
3087then processes its immediate children.</p>
3088
3089
3090
3091<eg><![CDATA[<xsl:template match="chapter">
3092
3093  <fo:block>
3094
3095    <xsl:apply-templates/>
3096
3097  </fo:block>
3098
3099</xsl:template>]]></eg>
3100
3101
3102
3103<p>In the absence of a <code>select</code> attribute, the
3104
3105<code>xsl:apply-templates</code> instruction processes all of the
3106
3107children of the current node, including text nodes.  However, text
3108
3109nodes that have been stripped as specified in <specref ref="strip"/>
3110
3111will not be processed.  If stripping of whitespace nodes has not been
3112
3113enabled for an element, then all whitespace in the content of the
3114
3115element will be processed as text, and thus whitespace
3116
3117between child elements will count in determining the position of a
3118
3119child element as returned by the <xfunction>position</xfunction>
3120
3121function.</p>
3122
3123
3124
3125<p>A <code>select</code> attribute can be used to process nodes
3126
3127selected by an expression instead of processing all children.  The
3128
3129value of the <code>select</code> attribute is an <termref
3130
3131def="dt-expression">expression</termref>.  The expression must
3132
3133evaluate to a node-set.  The selected set of nodes is processed in
3134
3135document order, unless a sorting specification is present (see
3136
3137<specref ref="sorting"/>).  The following example processes all of the
3138
3139<code>author</code> children of the <code>author-group</code>:</p>
3140
3141
3142
3143<eg><![CDATA[<xsl:template match="author-group">
3144
3145  <fo:inline-sequence>
3146
3147    <xsl:apply-templates select="author"/>
3148
3149  </fo:inline-sequence>
3150
3151</xsl:template>]]></eg>
3152
3153
3154
3155<p>The following example processes all of the <code>given-name</code>s
3156
3157of the <code>author</code>s that are children of
3158
3159<code>author-group</code>:</p>
3160
3161
3162
3163<eg><![CDATA[<xsl:template match="author-group">
3164
3165  <fo:inline-sequence>
3166
3167    <xsl:apply-templates select="author/given-name"/>
3168
3169  </fo:inline-sequence>
3170
3171</xsl:template>]]></eg>
3172
3173
3174
3175<p>This example processes all of the <code>heading</code> descendant
3176
3177elements of the <code>book</code> element.</p>
3178
3179
3180
3181<eg><![CDATA[<xsl:template match="book">
3182
3183  <fo:block>
3184
3185    <xsl:apply-templates select=".//heading"/>
3186
3187  </fo:block>
3188
3189</xsl:template>]]></eg>
3190
3191
3192
3193<p>It is also possible to process elements that are not descendants of
3194
3195the current node.  This example assumes that a <code>department</code>
3196
3197element has <code>group</code> children and <code>employee</code>
3198
3199descendants. It finds an employee's department and then processes
3200
3201the <code>group</code> children of the <code>department</code>.</p>
3202
3203
3204
3205<eg><![CDATA[<xsl:template match="employee">
3206
3207  <fo:block>
3208
3209    Employee <xsl:apply-templates select="name"/> belongs to group
3210
3211    <xsl:apply-templates select="ancestor::department/group"/>
3212
3213  </fo:block>
3214
3215</xsl:template>]]></eg>
3216
3217
3218
3219<p>Multiple <code>xsl:apply-templates</code> elements can be used within a
3220
3221single template to do simple reordering.  The following example
3222
3223creates two HTML tables. The first table is filled with domestic sales
3224
3225while the second table is filled with foreign sales.</p>
3226
3227
3228
3229<eg><![CDATA[<xsl:template match="product">
3230
3231  <table>
3232
3233    <xsl:apply-templates select="sales/domestic"/>
3234
3235  </table>
3236
3237  <table>
3238
3239    <xsl:apply-templates select="sales/foreign"/>
3240
3241  </table>
3242
3243</xsl:template>]]></eg>
3244
3245
3246
3247<note>
3248
3249
3250
3251<p>It is possible for there to be two matching descendants where one
3252
3253is a descendant of the other.  This case is not treated specially:
3254
3255both descendants will be processed as usual. For example, given a
3256
3257source document</p>
3258
3259
3260
3261<eg><![CDATA[<doc><div><div></div></div></doc>]]></eg>
3262
3263
3264
3265<p>the rule</p>
3266
3267
3268
3269<eg><![CDATA[<xsl:template match="doc">
3270
3271  <xsl:apply-templates select=".//div"/>
3272
3273</xsl:template>]]></eg>
3274
3275
3276
3277<p>will process both the outer <code>div</code> and inner <code>div</code>
3278
3279elements.</p>
3280
3281
3282
3283</note>
3284
3285
3286
3287<note><p>Typically, <code>xsl:apply-templates</code> is used to
3288
3289process only nodes that are descendants of the current node.  Such use
3290
3291of <code>xsl:apply-templates</code> cannot result in non-terminating
3292
3293processing loops.  However, when <code>xsl:apply-templates</code> is
3294
3295used to process elements that are not descendants of the current node,
3296
3297the possibility arises of non-terminating loops. For example,</p>
3298
3299
3300
3301<eg role="error"><![CDATA[<xsl:template match="foo">
3302
3303  <xsl:apply-templates select="."/>
3304
3305</xsl:template>]]></eg>
3306
3307
3308
3309<p>Implementations may be able to detect such loops in some cases, but
3310
3311the possibility exists that a stylesheet may enter a non-terminating
3312
3313loop that an implementation is unable to detect. This may present a
3314
3315denial of service security risk.</p></note>
3316
3317
3318
3319</div2>
3320
3321
3322
3323<div2 id="conflict">
3324
3325<head>Conflict Resolution for Template Rules</head>
3326
3327
3328
3329<p>It is possible for a source node to match more than one template
3330
3331rule. The template rule to be used is determined as follows:</p>
3332
3333
3334
3335<olist>
3336
3337
3338
3339<item><p>First, all matching template rules that have lower <termref
3340
3341def="dt-import-precedence">import precedence</termref> than the
3342
3343matching template rule or rules with the highest import precedence are
3344
3345eliminated from consideration.</p></item>
3346
3347
3348
3349<item><p>Next, all matching template rules that have lower priority
3350
3351than the matching template rule or rules with the highest priority are
3352
3353eliminated from consideration.  The priority of a template rule is
3354
3355specified by the <code>priority</code> attribute on the template rule.
3356
3357The value of this must be a real number (positive or negative),
3358
3359matching the production <xnt href="&XPath;#NT-Number">Number</xnt>
3360
3361with an optional leading minus sign (<code>-</code>).  <termdef
3362
3363id="dt-default-priority" term="Default Priority">The <term>default
3364
3365priority</term> is computed as follows:</termdef></p>
3366
3367
3368
3369<ulist>
3370
3371
3372
3373<item><p>If the pattern contains multiple alternatives separated by
3374
3375<code>|</code>, then it is treated equivalently to a set of template
3376
3377rules, one for each alternative.</p></item>
3378
3379
3380
3381<item><p>If the pattern has the form of a <xnt
3382
3383href="&XMLNames;#NT-QName">QName</xnt> preceded by a <nt
3384
3385def="NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</nt>
3386
3387or has the form
3388
3389<code>processing-instruction(</code><xnt href="&XPath;#NT-Literal"
3390
3391>Literal</xnt><code>)</code> preceded by a <nt
3392
3393def="NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</nt>,
3394
3395then the priority is 0.</p></item>
3396
3397
3398
3399<item><p>If the pattern has the form <xnt
3400
3401href="&XMLNames;#NT-NCName">NCName</xnt><code>:*</code> preceded by a
3402
3403<nt
3404
3405def="NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</nt>,
3406
3407then the priority is -0.25.</p></item>
3408
3409
3410
3411<item><p>Otherwise, if the pattern consists of just a <xnt
3412
3413href="&XPath;#NT-NodeTest">NodeTest</xnt> preceded by a <nt
3414
3415def="NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</nt>,
3416
3417then the priority is -0.5.</p></item>
3418
3419
3420
3421<item><p>Otherwise, the priority is 0.5.</p></item>
3422
3423
3424
3425</ulist>
3426
3427
3428
3429<p>Thus, the most common kind of pattern (a pattern that tests for a
3430
3431node with a particular type and a particular expanded-name) has
3432
3433priority 0. The next less specific kind of pattern (a pattern that
3434
3435tests for a node with a particular type and an expanded-name with a
3436
3437particular namespace URI) has priority -0.25.  Patterns less specific
3438
3439than this (patterns that just tests for nodes with particular types)
3440
3441have priority -0.5.  Patterns more specific than the most common kind
3442
3443of pattern have priority 0.5.</p>
3444
3445
3446
3447</item>
3448
3449
3450
3451</olist>
3452
3453
3454
3455<p>It is an error if this leaves more than one matching template
3456
3457rule.  An XSLT processor may signal the error; if it does not signal
3458
3459the error, it must recover by choosing, from amongst the matching
3460
3461template rules that are left, the one that occurs last in the
3462
3463stylesheet.</p>
3464
3465
3466
3467</div2>
3468
3469
3470
3471<div2 id="apply-imports">
3472
3473<head>Overriding Template Rules</head>
3474
3475
3476
3477<e:element-syntax name="apply-imports">
3478
3479  <e:in-category name="instruction"/>
3480
3481  <e:empty/>
3482
3483</e:element-syntax>
3484
3485
3486
3487<p>A template rule that is being used to override a template rule in
3488
3489an imported stylesheet (see <specref ref="conflict"/>) can use the
3490
3491<code>xsl:apply-imports</code> element to invoke the overridden
3492
3493template rule.</p>
3494
3495
3496
3497<p><termdef id="dt-current-template-rule" term="Current Template
3498
3499Rule">At any point in the processing of a stylesheet, there is a
3500
3501<term>current template rule</term>.  Whenever a template rule is
3502
3503chosen by matching a pattern, the template rule becomes the current
3504
3505template rule for the instantiation of the rule's template. When an
3506
3507<code>xsl:for-each</code> element is instantiated, the current
3508
3509template rule becomes null for the instantiation of the content of the
3510
3511<code>xsl:for-each</code> element.</termdef></p>
3512
3513
3514
3515<p><code>xsl:apply-imports</code> processes the current node using
3516
3517only template rules that were imported into the stylesheet element
3518
3519containing the current template rule; the node is processed in the
3520
3521current template rule's mode.  It is an error if
3522
3523<code>xsl:apply-imports</code> is instantiated when the current
3524
3525template rule is null.</p>
3526
3527
3528
3529<p>For example, suppose the stylesheet <code>doc.xsl</code> contains a
3530
3531template rule for <code>example</code> elements:</p>
3532
3533
3534
3535<eg><![CDATA[<xsl:template match="example">
3536
3537  <pre><xsl:apply-templates/></pre>
3538
3539</xsl:template>]]></eg>
3540
3541
3542
3543<p>Another stylesheet could import <code>doc.xsl</code> and modify the
3544
3545treatment of <code>example</code> elements as follows:</p>
3546
3547
3548
3549<eg><![CDATA[<xsl:import href="doc.xsl"/>
3550
3551
3552
3553<xsl:template match="example">
3554
3555  <div style="border: solid red">
3556
3557     <xsl:apply-imports/>
3558
3559  </div>
3560
3561</xsl:template>]]></eg>
3562
3563
3564
3565<p>The combined effect would be to transform an <code>example</code>
3566
3567into an element of the form:</p>
3568
3569
3570
3571<eg><![CDATA[<div style="border: solid red"><pre>...</pre></div>]]></eg>
3572
3573
3574
3575</div2>
3576
3577
3578
3579<div2 id="modes">
3580
3581<head>Modes</head>
3582
3583
3584
3585<p>Modes allow an element to be processed multiple times, each time
3586
3587producing a different result.</p>
3588
3589
3590
3591<p>Both <code>xsl:template</code> and <code>xsl:apply-templates</code>
3592
3593have an optional <code>mode</code> attribute.  The value of the
3594
3595<code>mode</code> attribute is a <xnt
3596
3597href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
3598
3599in <specref ref="qname"/>. If <code>xsl:template</code> does not have
3600
3601a <code>match</code> attribute, it must not have a <code>mode</code>
3602
3603attribute.  If an <code>xsl:apply-templates</code> element has a
3604
3605<code>mode</code> attribute, then it applies only to those template
3606
3607rules from <code>xsl:template</code> elements that have a
3608
3609<code>mode</code> attribute with the same value; if an
3610
3611<code>xsl:apply-templates</code> element does not have a
3612
3613<code>mode</code> attribute, then it applies only to those template
3614
3615rules from <code>xsl:template</code> elements that do not have a
3616
3617<code>mode</code> attribute.</p>
3618
3619
3620
3621</div2>
3622
3623
3624
3625<div2 id="built-in-rule">
3626
3627<head>Built-in Template Rules</head>
3628
3629
3630
3631<p>There is a built-in template rule to allow recursive processing to
3632
3633continue in the absence of a successful pattern match by an explicit
3634
3635template rule in the stylesheet.  This template rule applies to both
3636
3637element nodes and the root node.  The following shows the equivalent
3638
3639of the built-in template rule:</p>
3640
3641
3642
3643<eg><![CDATA[<xsl:template match="*|/">
3644
3645  <xsl:apply-templates/>
3646
3647</xsl:template>]]></eg>
3648
3649
3650
3651<p>There is also a built-in template rule for each mode, which allows
3652
3653recursive processing to continue in the same mode in the absence of a
3654
3655successful pattern match by an explicit template rule in the
3656
3657stylesheet.  This template rule applies to both element nodes and the
3658
3659root node.  The following shows the equivalent of the built-in
3660
3661template rule for mode <code><var>m</var></code>.</p>
3662
3663
3664
3665<eg>&lt;xsl:template match="*|/" mode="<var>m</var>">
3666
3667  &lt;xsl:apply-templates mode="<var>m</var>"/>
3668
3669&lt;/xsl:template></eg>
3670
3671
3672
3673<p>There is also a built-in template rule for text and attribute nodes
3674
3675that copies text through:</p>
3676
3677
3678
3679<eg><![CDATA[<xsl:template match="text()|@*">
3680
3681  <xsl:value-of select="."/>
3682
3683</xsl:template>]]></eg>
3684
3685
3686
3687<p>The built-in template rule for processing instructions and comments
3688
3689is to do nothing.</p>
3690
3691
3692
3693<eg><![CDATA[<xsl:template match="processing-instruction()|comment()"/>]]></eg>
3694
3695
3696
3697<p>The built-in template rule for namespace nodes is also to do
3698
3699nothing. There is no pattern that can match a namespace node; so, the
3700
3701built-in template rule is the only template rule that is applied for
3702
3703namespace nodes.</p>
3704
3705
3706
3707<p>The built-in template rules are treated as if they were imported
3708
3709implicitly before the stylesheet and so have lower <termref
3710
3711def="dt-import-precedence">import precedence</termref> than all other
3712
3713template rules.  Thus, the author can override a built-in template
3714
3715rule by including an explicit template rule.</p>
3716
3717
3718
3719</div2>
3720
3721
3722
3723
3724
3725</div1>
3726
3727
3728
3729<div1 id="named-templates">
3730
3731<head>Named Templates</head>
3732
3733
3734
3735<e:element-syntax name="call-template">
3736
3737  <e:in-category name="instruction"/>
3738
3739  <e:attribute name="name" required="yes">
3740
3741    <e:data-type name="qname"/>
3742
3743  </e:attribute>
3744
3745  <e:element repeat="zero-or-more" name="with-param"/>
3746
3747</e:element-syntax>
3748
3749
3750
3751<p>Templates can be invoked by name.  An <code>xsl:template</code>
3752
3753element with a <code>name</code> attribute specifies a named template.
3754
3755The value of the <code>name</code> attribute is a <xnt
3756
3757href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
3758
3759in <specref ref="qname"/>. If an <code>xsl:template</code> element has
3760
3761a <code>name</code> attribute, it may, but need not, also have a
3762
3763<code>match</code> attribute.  An <code>xsl:call-template</code>
3764
3765element invokes a template by name; it has a required
3766
3767<code>name</code> attribute that identifies the template to be
3768
3769invoked.  Unlike <code>xsl:apply-templates</code>,
3770
3771<code>xsl:call-template</code> does not change the current node or the
3772
3773current node list.</p>
3774
3775
3776
3777<p>The <code>match</code>, <code>mode</code> and <code>priority</code> attributes on an
3778
3779<code>xsl:template</code> element do not affect whether the template
3780
3781is invoked by an <code>xsl:call-template</code> element.  Similarly,
3782
3783the <code>name</code> attribute on an <code>xsl:template</code>
3784
3785element does not affect whether the template is invoked by an
3786
3787<code>xsl:apply-templates</code> element.</p>
3788
3789
3790
3791<p>It is an error if a stylesheet contains more than one template with
3792
3793the same name and same <termref def="dt-import-precedence">import
3794
3795precedence</termref>.</p>
3796
3797
3798
3799</div1>
3800
3801
3802
3803
3804
3805<div1>
3806
3807<head>Creating the Result Tree</head>
3808
3809
3810
3811<p>This section describes instructions that directly create nodes in
3812
3813the result tree.</p>
3814
3815
3816
3817<div2>
3818
3819<head>Creating Elements and Attributes</head>
3820
3821
3822
3823<div3 id="literal-result-element">
3824
3825<head>Literal Result Elements</head>
3826
3827
3828
3829<p>In a template, an element in the stylesheet that does not belong to
3830
3831the XSLT namespace and that is not an extension element (see <specref
3832
3833ref="extension-element"/>) is instantiated to create an element node
3834
3835with the same <xtermref
3836
3837href="&XPath;#dt-expanded-name">expanded-name</xtermref>.  The content
3838
3839of the element is a template, which is instantiated to give the
3840
3841content of the created element node. The created element node will
3842
3843have the attribute nodes that were present on the element node in the
3844
3845stylesheet tree, other than attributes with names in the XSLT
3846
3847namespace.</p>
3848
3849
3850
3851<p>The created element node will also have a copy of the namespace
3852
3853nodes that were present on the element node in the stylesheet tree
3854
3855with the exception of any namespace node whose string-value is the
3856
3857XSLT namespace URI (<code>&XSLT.ns;</code>), a
3858
3859namespace URI declared as an extension namespace (see <specref
3860
3861ref="extension-element"/>), or a namespace URI designated as an
3862
3863excluded namespace.  A namespace URI is designated as an excluded
3864
3865namespace by using an <code>exclude-result-prefixes</code> attribute
3866
3867on an <code>xsl:stylesheet</code> element or an
3868
3869<code>xsl:exclude-result-prefixes</code> attribute on a literal result
3870
3871element.  The value of both these attributes is a whitespace-separated
3872
3873list of namespace prefixes. The namespace bound to each of the
3874
3875prefixes is designated as an excluded namespace.  It is an error if
3876
3877there is no namespace bound to the prefix on the element bearing the
3878
3879<code>exclude-result-prefixes</code> or
3880
3881<code>xsl:exclude-result-prefixes</code> attribute.  The default
3882
3883namespace (as declared by <code>xmlns</code>) may be designated as an
3884
3885excluded namespace by including <code>#default</code> in the list of
3886
3887namespace prefixes.  The designation of a namespace as an excluded
3888
3889namespace is effective within the subtree of the stylesheet rooted at
3890
3891the element bearing the <code>exclude-result-prefixes</code> or
3892
3893<code>xsl:exclude-result-prefixes</code> attribute;
3894
3895a subtree rooted at an <code>xsl:stylesheet</code> element
3896
3897does not include any stylesheets imported or included by children
3898
3899of that <code>xsl:stylesheet</code> element.</p>
3900
3901
3902
3903<note><p>When a stylesheet uses a namespace declaration only for the
3904
3905purposes of addressing the source tree, specifying the prefix in the
3906
3907<code>exclude-result-prefixes</code> attribute will avoid superfluous
3908
3909namespace declarations in the result tree.</p></note>
3910
3911
3912
3913<p>The value of an attribute of a literal result element is
3914
3915interpreted as an <termref def="dt-attribute-value-template">attribute
3916
3917value template</termref>: it can contain expressions contained
3918
3919in curly braces (<code>{}</code>).</p>
3920
3921
3922
3923<p><termdef id="dt-literal-namespace-uri" term="Literal Namespace
3924
3925URI">A namespace URI in the stylesheet tree that is being used to
3926
3927specify a namespace URI in the result tree is called a <term>literal
3928
3929namespace URI</term>.</termdef> This applies to:</p>
3930
3931
3932
3933<ulist>
3934
3935
3936
3937<item><p>the namespace URI in the expanded-name of a literal
3938
3939result element in the stylesheet</p></item>
3940
3941
3942
3943<item><p>the namespace URI in the expanded-name of an attribute
3944
3945specified on a literal result element in the stylesheet</p></item>
3946
3947
3948
3949<item><p>the string-value of a namespace node on a literal result
3950
3951element in the stylesheet</p></item>
3952
3953
3954
3955</ulist>
3956
3957
3958
3959<e:element-syntax name="namespace-alias">
3960
3961  <e:in-category name="top-level-element"/>
3962
3963  <e:attribute name="stylesheet-prefix" required="yes">
3964
3965    <e:data-type name="prefix"/>
3966
3967    <e:constant value="#default"/>
3968
3969  </e:attribute>
3970
3971  <e:attribute name="result-prefix" required="yes">
3972
3973    <e:data-type name="prefix"/>
3974
3975    <e:constant value="#default"/>
3976
3977  </e:attribute>
3978
3979  <e:empty/>
3980
3981</e:element-syntax>
3982
3983
3984
3985<p><termdef id="dt-alias" term="Alias">A stylesheet can use the
3986
3987<code>xsl:namespace-alias</code> element to declare that one namespace
3988
3989URI is an <term>alias</term> for another namespace URI.</termdef> When
3990
3991a <termref def="dt-literal-namespace-uri">literal namespace
3992
3993URI</termref> has been declared to be an alias for another namespace
3994
3995URI, then the namespace URI in the result tree will be the namespace
3996
3997URI that the literal namespace URI is an alias for, instead of the
3998
3999literal namespace URI itself.  The <code>xsl:namespace-alias</code>
4000
4001element declares that the namespace URI bound to the prefix specified
4002
4003by the <code>stylesheet-prefix</code> attribute is an alias for the
4004
4005namespace URI bound to the prefix specified by the
4006
4007<code>result-prefix</code> attribute.  Thus, the
4008
4009<code>stylesheet-prefix</code> attribute specifies the namespace URI
4010
4011that will appear in the stylesheet, and the
4012
4013<code>result-prefix</code> attribute specifies the corresponding
4014
4015namespace URI that will appear in the result tree.  The default
4016
4017namespace (as declared by <code>xmlns</code>) may be specified by
4018
4019using <code>#default</code> instead of a prefix.  If a namespace URI
4020
4021is declared to be an alias for multiple different namespace URIs, then
4022
4023the declaration with the highest <termref
4024
4025def="dt-import-precedence">import precedence</termref> is used. It is
4026
4027an error if there is more than one such declaration.  An XSLT
4028
4029processor may signal the error; if it does not signal the error, it
4030
4031must recover by choosing, from amongst the declarations with the
4032
4033highest import precedence, the one that occurs last in the
4034
4035stylesheet.</p>
4036
4037
4038
4039<p>When literal result elements are being used to create element,
4040
4041attribute, or namespace nodes that use the XSLT namespace URI, the
4042
4043stylesheet must use an alias.  For example, the stylesheet</p>
4044
4045
4046
4047<eg>&lt;xsl:stylesheet
4048
4049  version="1.0"
4050
4051  xmlns:xsl="&XSLT.ns;"
4052
4053  xmlns:fo="&XSLFO.ns;"
4054
4055  xmlns:axsl="&XSLTA.ns;"><![CDATA[
4056
4057
4058
4059<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
4060
4061
4062
4063<xsl:template match="/">
4064
4065  <axsl:stylesheet>
4066
4067    <xsl:apply-templates/>
4068
4069  </axsl:stylesheet>
4070
4071</xsl:template>
4072
4073
4074
4075<xsl:template match="block">
4076
4077  <axsl:template match="{.}">
4078
4079     <fo:block><axsl:apply-templates/></fo:block>
4080
4081  </axsl:template>
4082
4083</xsl:template>
4084
4085
4086
4087</xsl:stylesheet>]]></eg>
4088
4089
4090
4091<p>will generate an XSLT stylesheet from a document of the form:</p>
4092
4093
4094
4095<eg><![CDATA[<elements>
4096
4097<block>p</block>
4098
4099<block>h1</block>
4100
4101<block>h2</block>
4102
4103<block>h3</block>
4104
4105<block>h4</block>
4106
4107</elements>]]></eg>
4108
4109
4110
4111<note><p>It may be necessary also to use aliases for namespaces other
4112
4113than the XSLT namespace URI.  For example, literal result elements
4114
4115belonging to a namespace dealing with digital signatures might cause
4116
4117XSLT stylesheets to be mishandled by general-purpose security
4118
4119software; using an alias for the namespace would avoid the possibility
4120
4121of such mishandling.</p></note>
4122
4123
4124
4125</div3>
4126
4127
4128
4129<div3>
4130
4131<head>Creating Elements with <code>xsl:element</code></head>
4132
4133
4134
4135<e:element-syntax name="element">
4136
4137  <e:in-category name="instruction"/>
4138
4139  <e:attribute name="name" required="yes">
4140
4141    <e:attribute-value-template>
4142
4143      <e:data-type name="qname"/>
4144
4145    </e:attribute-value-template>
4146
4147  </e:attribute>
4148
4149  <e:attribute name="namespace">
4150
4151    <e:attribute-value-template>
4152
4153      <e:data-type name="uri-reference"/>
4154
4155    </e:attribute-value-template>
4156
4157  </e:attribute>
4158
4159  <e:attribute name="use-attribute-sets">
4160
4161    <e:data-type name="qnames"/>
4162
4163  </e:attribute>
4164
4165  <e:model name="template"/>
4166
4167</e:element-syntax>
4168
4169
4170
4171<p>The <code>xsl:element</code> element allows an element to be
4172
4173created with a computed name.  The <xtermref
4174
4175href="&XPath;#dt-expanded-name">expanded-name</xtermref> of the
4176
4177element to be created is specified by a required <code>name</code>
4178
4179attribute and an optional <code>namespace</code> attribute.  The
4180
4181content of the <code>xsl:element</code> element is a template for the
4182
4183attributes and children of the created element.</p>
4184
4185
4186
4187<p>The <code>name</code> attribute is interpreted as an <termref
4188
4189def="dt-attribute-value-template">attribute value template</termref>.
4190
4191It is an error if the string that results from instantiating the
4192
4193attribute value template is not a <xnt
4194
4195href="&XMLNames;#NT-QName">QName</xnt>.  An XSLT processor may signal
4196
4197the error; if it does not signal the error, then it must recover
4198
4199by making the the result of instantiating the <code>xsl:element</code>
4200
4201element be the sequence of nodes created by instantiating
4202
4203the content of the  <code>xsl:element</code> element, excluding
4204
4205any initial attribute nodes. If the <code>namespace</code> attribute is
4206
4207not present then the <xnt href="&XMLNames;#NT-QName">QName</xnt> is
4208
4209expanded into an expanded-name using the namespace declarations in
4210
4211effect for the <code>xsl:element</code> element, including any default
4212
4213namespace declaration.</p>
4214
4215
4216
4217<p>If the <code>namespace</code> attribute is present, then it also is
4218
4219interpreted as an <termref def="dt-attribute-value-template">attribute
4220
4221value template</termref>. The string that results from instantiating
4222
4223the attribute value template should be a URI reference.  It is not an
4224
4225error if the string is not a syntactically legal URI reference.  If
4226
4227the string is empty, then the expanded-name of the element has a null
4228
4229namespace URI.  Otherwise, the string is used as the namespace URI of
4230
4231the expanded-name of the element to be created. The local part of the
4232
4233<xnt href="&XMLNames;#NT-QName">QName</xnt> specified by the
4234
4235<code>name</code> attribute is used as the local part of the
4236
4237expanded-name of the element to be created.</p>
4238
4239
4240
4241<p>XSLT processors may make use of the prefix of the <xnt
4242
4243href="&XMLNames;#NT-QName">QName</xnt> specified in the
4244
4245<code>name</code> attribute when selecting the prefix used for
4246
4247outputting the created element as XML; however, they are not required
4248
4249to do so.</p>
4250
4251
4252
4253</div3>
4254
4255
4256
4257<div3 id="creating-attributes">
4258
4259<head>Creating Attributes with <code>xsl:attribute</code></head>
4260
4261
4262
4263<e:element-syntax name="attribute">
4264
4265  <e:in-category name="instruction"/>
4266
4267  <e:attribute name="name" required="yes">
4268
4269    <e:attribute-value-template>
4270
4271      <e:data-type name="qname"/>
4272
4273    </e:attribute-value-template>
4274
4275  </e:attribute>
4276
4277  <e:attribute name="namespace">
4278
4279    <e:attribute-value-template>
4280
4281      <e:data-type name="uri-reference"/>
4282
4283    </e:attribute-value-template>
4284
4285  </e:attribute>
4286
4287  <e:model name="template"/>
4288
4289</e:element-syntax>
4290
4291
4292
4293<p>The <code>xsl:attribute</code> element can be used to add
4294
4295attributes to result elements whether created by literal result
4296
4297elements in the stylesheet or by instructions such as
4298
4299<code>xsl:element</code>. The <xtermref
4300
4301href="&XPath;#dt-expanded-name">expanded-name</xtermref> of the
4302
4303attribute to be created is specified by a required <code>name</code>
4304
4305attribute and an optional <code>namespace</code> attribute.
4306
4307Instantiating an <code>xsl:attribute</code> element adds an attribute
4308
4309node to the containing result element node. The content of the
4310
4311<code>xsl:attribute</code> element is a template for the value of the
4312
4313created attribute.</p>
4314
4315
4316
4317<p>The <code>name</code> attribute is interpreted as an <termref
4318
4319def="dt-attribute-value-template">attribute value template</termref>.
4320
4321It is an error if the string that results from instantiating the
4322
4323attribute value template is not a <xnt
4324
4325href="&XMLNames;#NT-QName">QName</xnt> or is the string
4326
4327<code>xmlns</code>.  An XSLT processor may signal the error; if it
4328
4329does not signal the error, it must recover by not adding the attribute
4330
4331to the result tree. If the <code>namespace</code> attribute is not
4332
4333present, then the <xnt href="&XMLNames;#NT-QName">QName</xnt> is
4334
4335expanded into an expanded-name using the namespace declarations in
4336
4337effect for the <code>xsl:attribute</code> element, <emph>not</emph>
4338
4339including any default namespace declaration.</p>
4340
4341
4342
4343<p>If the <code>namespace</code> attribute is present, then it also is
4344
4345interpreted as an <termref def="dt-attribute-value-template">attribute
4346
4347value template</termref>. The string that results from instantiating
4348
4349it should be a URI reference.  It is not an error if the string is not
4350
4351a syntactically legal URI reference.  If the string is empty, then the
4352
4353expanded-name of the attribute has a null namespace URI.  Otherwise,
4354
4355the string is used as the namespace URI of the expanded-name of the
4356
4357attribute to be created. The local part of the <xnt
4358
4359href="&XMLNames;#NT-QName">QName</xnt> specified by the
4360
4361<code>name</code> attribute is used as the local part of the
4362
4363expanded-name of the attribute to be created.</p>
4364
4365
4366
4367<p>XSLT processors may make use of the prefix of the <xnt
4368
4369href="&XMLNames;#NT-QName">QName</xnt> specified in the
4370
4371<code>name</code> attribute when selecting the prefix used for
4372
4373outputting the created attribute as XML; however, they are not
4374
4375required to do so and, if the prefix is <code>xmlns</code>, they must
4376
4377not do so. Thus, although it is not an error to do:</p>
4378
4379
4380
4381<eg>&lt;xsl:attribute name="xmlns:xsl" namespace="whatever">&XSLT.ns;&lt;/xsl:attribute></eg>
4382
4383
4384
4385<p>it will not result in a namespace declaration being output.</p>
4386
4387
4388
4389<p>Adding an attribute to an element replaces any existing attribute
4390
4391of that element with the same expanded-name.</p>
4392
4393
4394
4395<p>The following are all errors:</p>
4396
4397
4398
4399<ulist>
4400
4401
4402
4403<item><p>Adding an attribute to an element after children have been
4404
4405added to it; implementations may either signal the error or ignore the
4406
4407attribute.</p></item>
4408
4409
4410
4411<item><p>Adding an attribute to a node that is not an element;
4412
4413implementations may either signal the error or ignore the
4414
4415attribute.</p></item>
4416
4417
4418
4419<item><p>Creating nodes other than text nodes during the
4420
4421instantiation of the content of the <code>xsl:attribute</code>
4422
4423element; implementations may either signal the error or ignore the
4424
4425offending nodes.</p></item>
4426
4427
4428
4429</ulist>
4430
4431
4432
4433<note><p>When an <code>xsl:attribute</code> contains a text node with
4434
4435a newline, then the XML output must contain a character reference.
4436
4437For example,</p>
4438
4439
4440
4441<eg><![CDATA[<xsl:attribute name="a">x
4442
4443y</xsl:attribute>]]></eg>
4444
4445
4446
4447<p>will result in the output</p>
4448
4449
4450
4451<eg><![CDATA[a="x&#xA;y"]]></eg>
4452
4453
4454
4455<p>(or with any equivalent character reference). The XML output cannot
4456
4457be</p>
4458
4459
4460
4461<eg><![CDATA[a="x
4462
4463y"]]></eg>
4464
4465
4466
4467<p>This is because XML 1.0 requires newline characters in attribute
4468
4469values to be normalized into spaces but requires character references
4470
4471to newline characters not to be normalized.  The attribute values in
4472
4473the data model represent the attribute value after normalization.  If
4474
4475a newline occurring in an attribute value in the tree were output as a
4476
4477newline character rather than as character reference, then the
4478
4479attribute value in the tree created by reparsing the XML would contain
4480
4481a space not a newline, which would mean that the tree had not been
4482
4483output correctly.</p></note>
4484
4485
4486
4487</div3>
4488
4489
4490
4491<div3 id="attribute-sets">
4492
4493
4494
4495<head>Named Attribute Sets</head>
4496
4497
4498
4499<e:element-syntax name="attribute-set">
4500
4501  <e:in-category name="top-level-element"/>
4502
4503  <e:attribute name="name" required="yes">
4504
4505    <e:data-type name="qname"/>
4506
4507  </e:attribute>
4508
4509  <e:attribute name="use-attribute-sets">
4510
4511    <e:data-type name="qnames"/>
4512
4513  </e:attribute>
4514
4515  <e:element repeat="zero-or-more" name="attribute"/>
4516
4517</e:element-syntax>
4518
4519
4520
4521<p>The <code>xsl:attribute-set</code> element defines a named set of
4522
4523attributes.  The <code>name</code> attribute specifies the name of the
4524
4525attribute set.  The value of the <code>name</code> attribute is a <xnt
4526
4527href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
4528
4529in <specref ref="qname"/>. The content of the <code>xsl:attribute-set</code>
4530
4531element consists of zero or more <code>xsl:attribute</code> elements
4532
4533that specify the attributes in the set.</p>
4534
4535
4536
4537<p>Attribute sets are used by specifying a
4538
4539<code>use-attribute-sets</code> attribute on <code>xsl:element</code>,
4540
4541<code>xsl:copy</code> (see <specref ref="copying"/>) or
4542
4543<code>xsl:attribute-set</code> elements.  The value of the
4544
4545<code>use-attribute-sets</code> attribute is a whitespace-separated
4546
4547list of names of attribute sets.  Each name is specified as a <xnt
4548
4549href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
4550
4551in <specref ref="qname"/>.  Specifying a
4552
4553<code>use-attribute-sets</code> attribute is equivalent to adding
4554
4555<code>xsl:attribute</code> elements for each of the attributes in each
4556
4557of the named attribute sets to the beginning of the content of the
4558
4559element with the <code>use-attribute-sets</code> attribute, in the
4560
4561same order in which the names of the attribute sets are specified in
4562
4563the <code>use-attribute-sets</code> attribute.  It is an error if use
4564
4565of <code>use-attribute-sets</code> attributes on
4566
4567<code>xsl:attribute-set</code> elements causes an attribute set to
4568
4569directly or indirectly use itself.</p>
4570
4571
4572
4573<p>Attribute sets can also be used by specifying an
4574
4575<code>xsl:use-attribute-sets</code> attribute on a literal result
4576
4577element.  The value of the <code>xsl:use-attribute-sets</code>
4578
4579attribute is a whitespace-separated list of names of attribute sets.
4580
4581The <code>xsl:use-attribute-sets</code> attribute has the same effect
4582
4583as the <code>use-attribute-sets</code> attribute on
4584
4585<code>xsl:element</code> with the additional rule that attributes
4586
4587specified on the literal result element itself are treated as if they
4588
4589were specified by <code>xsl:attribute</code> elements before any
4590
4591actual <code>xsl:attribute</code> elements but after any
4592
4593<code>xsl:attribute</code> elements implied by the
4594
4595<code>xsl:use-attribute-sets</code> attribute.  Thus, for a literal
4596
4597result element, attributes from attribute sets named in an
4598
4599<code>xsl:use-attribute-sets</code> attribute will be added first, in
4600
4601the order listed in the attribute; next, attributes specified on the
4602
4603literal result element will be added; finally, any attributes
4604
4605specified by <code>xsl:attribute</code> elements will be added.  Since
4606
4607adding an attribute to an element replaces any existing attribute of
4608
4609that element with the same name, this means that attributes specified
4610
4611in attribute sets can be overridden by attributes specified on the
4612
4613literal result element itself.</p>
4614
4615
4616
4617<p>The template within each <code>xsl:attribute</code> element in an
4618
4619<code>xsl:attribute-set</code> element is instantiated each time the
4620
4621attribute set is used; it is instantiated using the same current node
4622
4623and current node list as is used for instantiating the element bearing
4624
4625the <code>use-attribute-sets</code> or
4626
4627<code>xsl:use-attribute-sets</code> attribute. However, it is the
4628
4629position in the stylesheet of the <code>xsl:attribute</code> element
4630
4631rather than of the element bearing the <code>use-attribute-sets</code>
4632
4633or <code>xsl:use-attribute-sets</code> attribute that determines which
4634
4635variable bindings are visible (see <specref ref="variables"/>); thus,
4636
4637only variables and parameters declared by <termref
4638
4639def="dt-top-level">top-level</termref> <code>xsl:variable</code> and
4640
4641<code>xsl:param</code> elements are visible.</p>
4642
4643
4644
4645<p>The following example creates a named attribute set
4646
4647<code>title-style</code> and uses it in a template rule.</p>
4648
4649
4650
4651<eg><![CDATA[<xsl:template match="chapter/heading">
4652
4653  <fo:block quadding="start" xsl:use-attribute-sets="title-style">
4654
4655    <xsl:apply-templates/>
4656
4657  </fo:block>
4658
4659</xsl:template>
4660
4661
4662
4663<xsl:attribute-set name="title-style">
4664
4665  <xsl:attribute name="font-size">12pt</xsl:attribute>
4666
4667  <xsl:attribute name="font-weight">bold</xsl:attribute>
4668
4669</xsl:attribute-set>]]></eg>
4670
4671
4672
4673<p>Multiple definitions of an attribute set with the same
4674
4675expanded-name are merged.  An attribute from a definition that has
4676
4677higher <termref def="dt-import-precedence">import precedence</termref>
4678
4679takes precedence over an attribute from a definition that has lower
4680
4681<termref def="dt-import-precedence">import precedence</termref>.  It
4682
4683is an error if there are two attribute sets that have the same
4684
4685expanded-name and equal import precedence and that both contain
4686
4687the same attribute, unless there is a definition of the attribute set
4688
4689with higher <termref def="dt-import-precedence">import
4690
4691precedence</termref> that also contains the attribute.  An XSLT
4692
4693processor may signal the error; if it does not signal the error, it
4694
4695must recover by choosing from amongst the definitions that specify the
4696
4697attribute that have the highest import precedence the one that was
4698
4699specified last in the stylesheet.  Where the attributes in an
4700
4701attribute set were specified is relevant only in merging the
4702
4703attributes into the attribute set; it makes no difference when the
4704
4705attribute set is used.</p>
4706
4707
4708
4709</div3>
4710
4711
4712
4713</div2>
4714
4715
4716
4717<div2>
4718
4719
4720
4721<head>Creating Text</head>
4722
4723
4724
4725<p>A template can also contain text nodes.  Each text node in a
4726
4727template remaining after whitespace has been stripped as specified in
4728
4729<specref ref="strip"/> will create a text node with the same
4730
4731string-value in the result tree.  Adjacent text nodes in the result
4732
4733tree are automatically merged.</p>
4734
4735
4736
4737<p>Note that text is processed at the tree level. Thus, markup of
4738
4739<code>&amp;lt;</code> in a template will be represented in the
4740
4741stylesheet tree by a text node that includes the character
4742
4743<code>&lt;</code>. This will create a text node in the result tree
4744
4745that contains a <code>&lt;</code> character, which will be represented
4746
4747by the markup <code>&amp;lt;</code> (or an equivalent character
4748
4749reference) when the result tree is externalized as an XML document
4750
4751(unless output escaping is disabled as described in <specref
4752
4753ref="disable-output-escaping"/>).</p>
4754
4755
4756
4757<e:element-syntax name="text">
4758
4759  <e:in-category name="instruction"/>
4760
4761  <e:attribute name="disable-output-escaping">
4762
4763    <e:constant value="yes"/>
4764
4765    <e:constant value="no"/>
4766
4767  </e:attribute>
4768
4769  <e:text/>
4770
4771</e:element-syntax>
4772
4773
4774
4775<p>Literal data characters may also be wrapped in an
4776
4777<code>xsl:text</code> element.  This wrapping may change what
4778
4779whitespace characters are stripped (see <specref ref="strip"/>) but
4780
4781does not affect how the characters are handled by the XSLT processor
4782
4783thereafter.</p>
4784
4785
4786
4787<note><p>The <code>xml:lang</code> and <code>xml:space</code>
4788
4789attributes are not treated specially by XSLT. In particular,</p>
4790
4791
4792
4793<ulist>
4794
4795<item><p>it is the responsibility of the stylesheet author explicitly
4796
4797to generate any <code>xml:lang</code> or <code>xml:space</code>
4798
4799attributes that are needed in the result;</p></item>
4800
4801
4802
4803<item><p>specifying an <code>xml:lang</code> or <code>xml:space</code>
4804
4805attribute on an element in the XSLT namespace will not cause any
4806
4807<code>xml:lang</code> or <code>xml:space</code> attributes to appear
4808
4809in the result.</p></item>
4810
4811</ulist>
4812
4813</note>
4814
4815
4816
4817</div2>
4818
4819
4820
4821
4822
4823<div2>
4824
4825<head>Creating Processing Instructions</head>
4826
4827
4828
4829
4830
4831<e:element-syntax name="processing-instruction">
4832
4833  <e:in-category name="instruction"/>
4834
4835  <e:attribute name="name" required="yes">
4836
4837    <e:attribute-value-template>
4838
4839      <e:data-type name="ncname"/>
4840
4841    </e:attribute-value-template>
4842
4843  </e:attribute>
4844
4845  <e:model name="template"/>
4846
4847</e:element-syntax>
4848
4849
4850
4851<p>The <code>xsl:processing-instruction</code> element is instantiated
4852
4853to create a processing instruction node.  The content of the
4854
4855<code>xsl:processing-instruction</code> element is a template for the
4856
4857string-value of the processing instruction node.  The
4858
4859<code>xsl:processing-instruction</code> element has a required
4860
4861<code>name</code> attribute that specifies the name of the processing
4862
4863instruction node.  The value of the <code>name</code> attribute is
4864
4865interpreted as an <termref def="dt-attribute-value-template">attribute
4866
4867value template</termref>.</p>
4868
4869
4870
4871<p>For example, this</p>
4872
4873
4874
4875<eg><![CDATA[<xsl:processing-instruction name="xml-stylesheet">href="book.css" type="text/css"</xsl:processing-instruction>]]></eg>
4876
4877
4878
4879<p>would create the processing instruction</p>
4880
4881
4882
4883<eg><![CDATA[<?xml-stylesheet href="book.css" type="text/css"?>]]></eg>
4884
4885
4886
4887<p>It is an error if the string that results from instantiating the
4888
4889<code>name</code> attribute is not both an <xnt
4890
4891href="&XMLNames;#NT-NCName">NCName</xnt> and a <xnt
4892
4893href="&XML;#NT-PITarget">PITarget</xnt>.  An XSLT processor may signal
4894
4895the error; if it does not signal the error, it must recover by not
4896
4897adding the processing instruction to the result tree.</p>
4898
4899
4900
4901<note><p>This means that <code>xsl:processing-instruction</code>
4902
4903cannot be used to output an XML declaration.  The
4904
4905<code>xsl:output</code> element should be used instead (see <specref
4906
4907ref="output"/>).</p></note>
4908
4909
4910
4911<p>It is an error if instantiating the content of
4912
4913<code>xsl:processing-instruction</code> creates nodes other than
4914
4915text nodes.  An XSLT processor may signal the error; if it does not
4916
4917signal the error, it must recover by ignoring the offending nodes
4918
4919together with their content.</p>
4920
4921
4922
4923<p>It is an error if the result of instantiating the content of the
4924
4925<code>xsl:processing-instruction</code> contains the string
4926
4927<code>?&gt;</code>.  An XSLT processor may signal the error; if it does
4928
4929not signal the error, it must recover by inserting a space after any
4930
4931occurrence of <code>?</code> that is followed by a <code>&gt;</code>.</p>
4932
4933
4934
4935</div2>
4936
4937
4938
4939<div2>
4940
4941<head>Creating Comments</head>
4942
4943
4944
4945<e:element-syntax name="comment">
4946
4947  <e:in-category name="instruction"/>
4948
4949  <e:model name="template"/>
4950
4951</e:element-syntax>
4952
4953
4954
4955<p>The <code>xsl:comment</code> element is instantiated to create a
4956
4957comment node in the result tree.  The content of the
4958
4959<code>xsl:comment</code> element is a template for the string-value of
4960
4961the comment node.</p>
4962
4963
4964
4965<p>For example, this</p>
4966
4967
4968
4969<eg><![CDATA[<xsl:comment>This file is automatically generated. Do not edit!</xsl:comment>]]></eg>
4970
4971
4972
4973<p>would create the comment</p>
4974
4975
4976
4977<eg><![CDATA[<!--This file is automatically generated. Do not edit!-->]]></eg>
4978
4979
4980
4981<p>It is an error if instantiating the content of
4982
4983<code>xsl:comment</code> creates nodes other than text nodes.  An
4984
4985XSLT processor may signal the error; if it does not signal the error,
4986
4987it must recover by ignoring the offending nodes together with their
4988
4989content.</p>
4990
4991
4992
4993<p>It is an error if the result of instantiating the content of the
4994
4995<code>xsl:comment</code> contains the string <code>--</code> or ends
4996
4997with <code>-</code>.  An XSLT processor may signal the error; if it
4998
4999does not signal the error, it must recover by inserting a space after
5000
5001any occurrence of <code>-</code> that is followed by another
5002
5003<code>-</code> or that ends the comment.</p>
5004
5005
5006
5007</div2>
5008
5009
5010
5011<div2 id="copying">
5012
5013<head>Copying</head>
5014
5015
5016
5017<e:element-syntax name="copy">
5018
5019  <e:in-category name="instruction"/>
5020
5021  <e:attribute name="use-attribute-sets">
5022
5023    <e:data-type name="qnames"/>
5024
5025  </e:attribute>
5026
5027  <e:model name="template"/>
5028
5029</e:element-syntax>
5030
5031
5032
5033<p>The <code>xsl:copy</code> element provides an easy way of copying
5034
5035the current node. Instantiating the <code>xsl:copy</code> element
5036
5037creates a copy of the current node.  The namespace nodes of the
5038
5039current node are automatically copied as well, but the attributes and
5040
5041children of the node are not automatically copied.  The content of the
5042
5043<code>xsl:copy</code> element is a template for the attributes and
5044
5045children of the created node; the content is instantiated only for
5046
5047nodes of types that can have attributes or children (i.e. root
5048
5049nodes and element nodes).</p>
5050
5051
5052
5053<p>The <code>xsl:copy</code> element may have a
5054
5055<code>use-attribute-sets</code> attribute (see <specref
5056
5057ref="attribute-sets"/>). This is used only when copying element
5058
5059nodes.</p>
5060
5061
5062
5063<p>The root node is treated specially because the root node of the
5064
5065result tree is created implicitly.  When the current node is the root
5066
5067node, <code>xsl:copy</code> will not create a root node, but will just
5068
5069use the content template.</p>
5070
5071
5072
5073<p>For example, the identity transformation can be written using
5074
5075<code>xsl:copy</code> as follows:</p>
5076
5077
5078
5079<eg><![CDATA[<xsl:template match="@*|node()">
5080
5081  <xsl:copy>
5082
5083    <xsl:apply-templates select="@*|node()"/>
5084
5085  </xsl:copy>
5086
5087</xsl:template>]]></eg>
5088
5089
5090
5091<p>When the current node is an attribute, then if it would be an error
5092
5093to use <code>xsl:attribute</code> to create an attribute with the same
5094
5095name as the current node, then it is also an error to use
5096
5097<code>xsl:copy</code> (see <specref ref="creating-attributes"/>).</p>
5098
5099
5100
5101<p>The following example shows how <code>xml:lang</code> attributes
5102
5103can be easily copied through from source to result. If a stylesheet
5104
5105defines the following named template:</p>
5106
5107
5108
5109<eg><![CDATA[<xsl:template name="apply-templates-copy-lang">
5110
5111 <xsl:for-each select="@xml:lang">
5112
5113   <xsl:copy/>
5114
5115 </xsl:for-each>
5116
5117 <xsl:apply-templates/>
5118
5119</xsl:template>]]></eg>
5120
5121
5122
5123<p>then it can simply do</p>
5124
5125
5126
5127<eg><![CDATA[<xsl:call-template name="apply-templates-copy-lang"/>]]></eg>
5128
5129
5130
5131<p>instead of</p>
5132
5133
5134
5135<eg><![CDATA[<xsl:apply-templates/>]]></eg>
5136
5137
5138
5139<p>when it wants to copy the <code>xml:lang</code> attribute.</p>
5140
5141
5142
5143</div2>
5144
5145
5146
5147<div2>
5148
5149<head>Computing Generated Text</head>
5150
5151
5152
5153<p>Within a template, the <code>xsl:value-of</code> element can be
5154
5155used to compute generated text, for example by extracting text from
5156
5157the source tree or by inserting the value of a variable.  The
5158
5159<code>xsl:value-of</code> element does this with an <termref
5160
5161def="dt-expression">expression</termref> that is specified as the
5162
5163value of the <code>select</code> attribute.  Expressions can
5164
5165also be used inside attribute values of literal result elements by
5166
5167enclosing the expression in curly braces (<code>{}</code>).</p>
5168
5169
5170
5171<div3 id="value-of">
5172
5173<head>Generating Text with <code>xsl:value-of</code></head>
5174
5175
5176
5177<e:element-syntax name="value-of">
5178
5179  <e:in-category name="instruction"/>
5180
5181  <e:attribute name="select" required="yes">
5182
5183    <e:data-type name="string-expression"/>
5184
5185  </e:attribute>
5186
5187  <e:attribute name="disable-output-escaping">
5188
5189    <e:constant value="yes"/>
5190
5191    <e:constant value="no"/>
5192
5193  </e:attribute>
5194
5195  <e:empty/>
5196
5197</e:element-syntax>
5198
5199
5200
5201<p>The <code>xsl:value-of</code> element is instantiated to create a
5202
5203text node in the result tree.  The required <code>select</code>
5204
5205attribute is an <termref def="dt-expression">expression</termref>;
5206
5207this expression is evaluated and the resulting object is converted to
5208
5209a string as if by a call to the <xfunction>string</xfunction>
5210
5211function. The string specifies the string-value of the created text
5212
5213node.  If the string is empty, no text node will be created.  The
5214
5215created text node will be merged with any adjacent text nodes.</p>
5216
5217
5218
5219<p>The <code>xsl:copy-of</code> element can be used to copy a node-set
5220
5221over to the result tree without converting it to a string. See <specref
5222
5223ref="copy-of"/>.</p>
5224
5225
5226
5227<p>For example, the following creates an HTML paragraph from a
5228
5229<code>person</code> element with <code>given-name</code> and
5230
5231<code>family-name</code> attributes.  The paragraph will contain the value
5232
5233of the <code>given-name</code> attribute of the current node followed
5234
5235by a space and the value of the <code>family-name</code> attribute of the
5236
5237current node.</p>
5238
5239
5240
5241<eg><![CDATA[<xsl:template match="person">
5242
5243  <p>
5244
5245   <xsl:value-of select="@given-name"/>
5246
5247   <xsl:text> </xsl:text>
5248
5249   <xsl:value-of select="@family-name"/>
5250
5251  </p>
5252
5253</xsl:template>]]></eg>
5254
5255
5256
5257<p>For another example, the following creates an HTML paragraph from a
5258
5259<code>person</code> element with <code>given-name</code> and
5260
5261<code>family-name</code> children elements.  The paragraph will
5262
5263contain the string-value of the first <code>given-name</code> child
5264
5265element of the current node followed by a space and the string-value
5266
5267of the first <code>family-name</code> child element of the current
5268
5269node.</p>
5270
5271
5272
5273<eg><![CDATA[<xsl:template match="person">
5274
5275  <p>
5276
5277   <xsl:value-of select="given-name"/>
5278
5279   <xsl:text> </xsl:text>
5280
5281   <xsl:value-of select="family-name"/>
5282
5283  </p>
5284
5285</xsl:template>]]></eg>
5286
5287
5288
5289<p>The following precedes each <code>procedure</code> element with a
5290
5291paragraph containing the security level of the procedure.  It assumes
5292
5293that the security level that applies to a procedure is determined by a
5294
5295<code>security</code> attribute on the procedure element or on an
5296
5297ancestor element of the procedure. It also assumes that if more than
5298
5299one such element has a <code>security</code> attribute then the
5300
5301security level is determined by the element that is closest to the
5302
5303procedure.</p>
5304
5305
5306
5307<eg><![CDATA[<xsl:template match="procedure">
5308
5309  <fo:block>
5310
5311    <xsl:value-of select="ancestor-or-self::*[@security][1]/@security"/>
5312
5313  </fo:block>
5314
5315  <xsl:apply-templates/>
5316
5317</xsl:template>]]></eg>
5318
5319
5320
5321</div3>
5322
5323
5324
5325<div3 id="attribute-value-templates">
5326
5327<head>Attribute Value Templates</head>
5328
5329
5330
5331<p><termdef id="dt-attribute-value-template" term="Attribute Value
5332
5333Template">In an attribute value that is interpreted as an
5334
5335<term>attribute value template</term>, such as an attribute of a
5336
5337literal result element, an <termref
5338
5339def="dt-expression">expression</termref> can be used by surrounding
5340
5341the expression with curly braces (<code>{}</code>)</termdef>.  The
5342
5343attribute value template is instantiated by replacing the expression
5344
5345together with surrounding curly braces by the result of evaluating the
5346
5347expression and converting the resulting object to a string as if by a
5348
5349call to the <xfunction>string</xfunction> function.  Curly braces are
5350
5351not recognized in an attribute value in an XSLT stylesheet unless the
5352
5353attribute is specifically stated to be one that is interpreted as an
5354
5355attribute value template; in an element syntax summary, the value
5356
5357of such attributes is surrounded by curly braces.</p>
5358
5359
5360
5361<note><p>Not all attributes are interpreted as attribute value
5362
5363templates.  Attributes whose value is an expression or pattern,
5364
5365attributes of <termref def="dt-top-level">top-level</termref> elements
5366
5367and attributes that refer to named XSLT objects are not interpreted as
5368
5369attribute value templates. In addition, <code>xmlns</code> attributes
5370
5371are not interpreted as attribute value templates; it would not be
5372
5373conformant with the XML Namespaces Recommendation to do
5374
5375this.</p></note>
5376
5377
5378
5379<p>The following example creates an <code>img</code> result element
5380
5381from a <code>photograph</code> element in the source; the value of the
5382
5383<code>src</code> attribute of the <code>img</code> element is computed
5384
5385from the value of the <code>image-dir</code> variable and the
5386
5387string-value of the <code>href</code> child of the
5388
5389<code>photograph</code> element; the value of the <code>width</code>
5390
5391attribute of the <code>img</code> element is computed from the value
5392
5393of the <code>width</code> attribute of the <code>size</code> child of
5394
5395the <code>photograph</code> element:</p>
5396
5397
5398
5399<eg><![CDATA[<xsl:variable name="image-dir">/images</xsl:variable>
5400
5401
5402
5403<xsl:template match="photograph">
5404
5405<img src="{$image-dir}/{href}" width="{size/@width}"/>
5406
5407</xsl:template>]]></eg>
5408
5409
5410
5411<p>With this source</p>
5412
5413
5414
5415<eg><![CDATA[<photograph>
5416
5417  <href>headquarters.jpg</href>
5418
5419  <size width="300"/>
5420
5421</photograph>]]></eg>
5422
5423
5424
5425<p>the result would be</p>
5426
5427
5428
5429<eg><![CDATA[<img src="/images/headquarters.jpg" width="300"/>]]></eg>
5430
5431
5432
5433<p>When an attribute value template is instantiated, a double left or
5434
5435right curly brace outside an expression will be replaced by a single
5436
5437curly brace.  It is an error if a right curly brace occurs in an
5438
5439attribute value template outside an expression without being followed
5440
5441by a second right curly brace.  A right curly brace inside a <xnt
5442
5443href="&XPath;#NT-Literal">Literal</xnt> in an expression is not
5444
5445recognized as terminating the expression.</p>
5446
5447
5448
5449<p>Curly braces are <emph>not</emph> recognized recursively inside
5450
5451expressions.  For example:</p>
5452
5453
5454
5455<eg role="error"><![CDATA[<a href="#{id({@ref})/title}">]]></eg>
5456
5457
5458
5459<p>is <emph>not</emph> allowed.  Instead, use simply:</p>
5460
5461
5462
5463<eg><![CDATA[<a href="#{id(@ref)/title}">]]></eg>
5464
5465
5466
5467</div3>
5468
5469
5470
5471</div2>
5472
5473
5474
5475<div2 id="number">
5476
5477<head>Numbering</head>
5478
5479
5480
5481<e:element-syntax name="number">
5482
5483  <e:in-category name="instruction"/>
5484
5485  <e:attribute name="level">
5486
5487    <e:constant value="single"/>
5488
5489    <e:constant value="multiple"/>
5490
5491    <e:constant value="any"/>
5492
5493  </e:attribute>
5494
5495  <e:attribute name="count">
5496
5497    <e:data-type name="pattern"/>
5498
5499  </e:attribute>
5500
5501  <e:attribute name="from">
5502
5503    <e:data-type name="pattern"/>
5504
5505  </e:attribute>
5506
5507  <e:attribute name="value">
5508
5509    <e:data-type name="number-expression"/>
5510
5511  </e:attribute>
5512
5513  <e:attribute name="format">
5514
5515    <e:attribute-value-template>
5516
5517      <e:data-type name="string"/>
5518
5519    </e:attribute-value-template>
5520
5521  </e:attribute>
5522
5523  <e:attribute name="lang">
5524
5525    <e:attribute-value-template>
5526
5527      <e:data-type name="nmtoken"/>
5528
5529    </e:attribute-value-template>
5530
5531  </e:attribute>
5532
5533  <e:attribute name="letter-value">
5534
5535    <e:attribute-value-template>
5536
5537      <e:constant value="alphabetic"/>
5538
5539      <e:constant value="traditional"/>
5540
5541    </e:attribute-value-template>
5542
5543  </e:attribute>
5544
5545  <e:attribute name="grouping-separator">
5546
5547    <e:attribute-value-template>
5548
5549      <e:data-type name="char"/>
5550
5551    </e:attribute-value-template>
5552
5553  </e:attribute>
5554
5555  <e:attribute name="grouping-size">
5556
5557    <e:attribute-value-template>
5558
5559      <e:data-type name="number"/>
5560
5561    </e:attribute-value-template>
5562
5563  </e:attribute>
5564
5565  <e:empty/>
5566
5567</e:element-syntax>
5568
5569
5570
5571<p>The <code>xsl:number</code> element is used to insert a formatted
5572
5573number into the result tree.  The number to be inserted may be
5574
5575specified by an expression. The <code>value</code> attribute contains
5576
5577an <termref def="dt-expression">expression</termref>.  The expression
5578
5579is evaluated and the resulting object is converted to a number as if
5580
5581by a call to the <xfunction>number</xfunction> function.  The number is
5582
5583rounded to an integer and then converted to a string using the
5584
5585attributes specified in <specref ref="convert"/>; in this
5586
5587context, the value of each of these attributes is
5588
5589interpreted as an <termref def="dt-attribute-value-template">attribute
5590
5591value template</termref>.  After conversion, the resulting string is
5592
5593inserted in the result tree. For example, the following example
5594
5595numbers a sorted list:</p>
5596
5597
5598
5599<eg><![CDATA[<xsl:template match="items">
5600
5601  <xsl:for-each select="item">
5602
5603    <xsl:sort select="."/>
5604
5605    <p>
5606
5607      <xsl:number value="position()" format="1. "/>
5608
5609      <xsl:value-of select="."/>
5610
5611    </p>
5612
5613  </xsl:for-each>
5614
5615</xsl:template>]]></eg>
5616
5617
5618
5619<p>If no <code>value</code> attribute is specified, then the
5620
5621<code>xsl:number</code> element inserts a number based on the position
5622
5623of the current node in the source tree. The following attributes
5624
5625control how the current node is to be numbered:</p>
5626
5627
5628
5629<ulist>
5630
5631
5632
5633<item><p>The <code>level</code> attribute specifies what levels of the
5634
5635source tree should be considered; it has the values
5636
5637<code>single</code>, <code>multiple</code> or <code>any</code>. The
5638
5639default is <code>single</code>.</p></item>
5640
5641
5642
5643<item><p>The <code>count</code> attribute is a pattern that specifies
5644
5645what nodes should be counted at those levels.  If <code>count</code>
5646
5647attribute is not specified, then it defaults to the pattern that
5648
5649matches any node with the same node type as the current node and, if
5650
5651the current node has an expanded-name, with the same expanded-name as
5652
5653the current node.</p></item>
5654
5655
5656
5657<item><p>The <code>from</code> attribute is a pattern that specifies
5658
5659where counting starts.</p></item>
5660
5661
5662
5663</ulist>
5664
5665
5666
5667<p>In addition, the attributes specified in <specref ref="convert"/>
5668
5669are used for number to string conversion, as in the case when the
5670
5671<code>value</code> attribute is specified.</p>
5672
5673
5674
5675<p>The <code>xsl:number</code> element first constructs a list of
5676
5677positive integers using the <code>level</code>, <code>count</code> and
5678
5679<code>from</code> attributes:</p>
5680
5681
5682
5683<ulist>
5684
5685
5686
5687<item><p>When <code>level="single"</code>, it goes up to the first
5688
5689node in the ancestor-or-self axis that matches
5690
5691the <code>count</code> pattern, and constructs a list of length one
5692
5693containing one plus the number of preceding siblings of that ancestor
5694
5695that match the <code>count</code> pattern. If there is no such
5696
5697ancestor, it constructs an empty list.  If the <code>from</code>
5698
5699attribute is specified, then the only ancestors that are searched are
5700
5701those that are descendants of the nearest ancestor that matches the
5702
5703<code>from</code> pattern. Preceding siblings has the same meaning
5704
5705here as with the <code>preceding-sibling</code> axis.</p></item>
5706
5707
5708
5709<item><p>When <code>level="multiple"</code>, it constructs a list of all
5710
5711ancestors of the current node in document order followed by the
5712
5713element itself; it then selects from the list those nodes that match
5714
5715the <code>count</code> pattern; it then maps each node in the list to
5716
5717one plus the number of preceding siblings of that node that match the
5718
5719<code>count</code> pattern.  If the <code>from</code> attribute is
5720
5721specified, then the only ancestors that are searched are those that
5722
5723are descendants of the nearest ancestor that matches the
5724
5725<code>from</code> pattern. Preceding siblings has the same meaning
5726
5727here as with the <code>preceding-sibling</code> axis.</p></item>
5728
5729
5730
5731<item><p>When <code>level="any"</code>, it constructs a list of length
5732
5733one containing the number of nodes that match the <code>count</code>
5734
5735pattern and belong to the set containing the current node and all
5736
5737nodes at any level of the document that are before the current node in
5738
5739document order, excluding any namespace and attribute nodes (in other
5740
5741words the union of the members of the <code>preceding</code> and
5742
5743<code>ancestor-or-self</code> axes). If the <code>from</code>
5744
5745attribute is specified, then only nodes after the first node before
5746
5747the current node that match the <code>from</code> pattern are
5748
5749considered.</p></item>
5750
5751
5752
5753</ulist>
5754
5755
5756
5757<p>The list of numbers is then converted into a string using the
5758
5759attributes specified in <specref ref="convert"/>; in this
5760
5761context, the value of each of these attributes is
5762
5763interpreted as an <termref def="dt-attribute-value-template">attribute
5764
5765value template</termref>.  After conversion, the resulting string is
5766
5767inserted in the result tree.</p>
5768
5769
5770
5771<p>The following would number the items in an ordered list:</p>
5772
5773
5774
5775<eg><![CDATA[<xsl:template match="ol/item">
5776
5777  <fo:block>
5778
5779    <xsl:number/><xsl:text>. </xsl:text><xsl:apply-templates/>
5780
5781  </fo:block>
5782
5783<xsl:template>]]></eg>
5784
5785
5786
5787<p>The following two rules would number <code>title</code> elements.
5788
5789This is intended for a document that contains a sequence of chapters
5790
5791followed by a sequence of appendices, where both chapters and
5792
5793appendices contain sections, which in turn contain subsections.
5794
5795Chapters are numbered 1, 2, 3; appendices are numbered A, B, C;
5796
5797sections in chapters are numbered 1.1, 1.2, 1.3; sections in
5798
5799appendices are numbered A.1, A.2, A.3.</p>
5800
5801
5802
5803<eg><![CDATA[<xsl:template match="title">
5804
5805  <fo:block>
5806
5807     <xsl:number level="multiple"
5808
5809                 count="chapter|section|subsection"
5810
5811                 format="1.1 "/>
5812
5813     <xsl:apply-templates/>
5814
5815  </fo:block>
5816
5817</xsl:template>
5818
5819
5820
5821<xsl:template match="appendix//title" priority="1">
5822
5823  <fo:block>
5824
5825     <xsl:number level="multiple"
5826
5827                 count="appendix|section|subsection"
5828
5829                 format="A.1 "/>
5830
5831     <xsl:apply-templates/>
5832
5833  </fo:block>
5834
5835</xsl:template>]]></eg>
5836
5837
5838
5839<p>The following example numbers notes sequentially within a
5840
5841chapter:</p>
5842
5843
5844
5845<eg><![CDATA[<xsl:template match="note">
5846
5847  <fo:block>
5848
5849     <xsl:number level="any" from="chapter" format="(1) "/>
5850
5851     <xsl:apply-templates/>
5852
5853  </fo:block>
5854
5855</xsl:template>]]></eg>
5856
5857
5858
5859<p>The following example would number <code>H4</code> elements in HTML
5860
5861with a three-part label:</p>
5862
5863
5864
5865<eg><![CDATA[<xsl:template match="H4">
5866
5867 <fo:block>
5868
5869   <xsl:number level="any" from="H1" count="H2"/>
5870
5871   <xsl:text>.</xsl:text>
5872
5873   <xsl:number level="any" from="H2" count="H3"/>
5874
5875   <xsl:text>.</xsl:text>
5876
5877   <xsl:number level="any" from="H3" count="H4"/>
5878
5879   <xsl:text> </xsl:text>
5880
5881   <xsl:apply-templates/>
5882
5883 </fo:block>
5884
5885</xsl:template>]]></eg>
5886
5887
5888
5889<div3 id="convert">
5890
5891<head>Number to String Conversion Attributes</head>
5892
5893
5894
5895<p>The following attributes are used to control conversion of a list
5896
5897of numbers into a string. The numbers are integers greater than
5898
58990. The attributes are all optional.</p>
5900
5901
5902
5903<p>The main attribute is <code>format</code>.  The default value for
5904
5905the <code>format</code> attribute is <code>1</code>.  The
5906
5907<code>format</code> attribute is split into a sequence of tokens where
5908
5909each token is a maximal sequence of alphanumeric characters or a
5910
5911maximal sequence of non-alphanumeric characters.  Alphanumeric means
5912
5913any character that has a Unicode category of Nd, Nl, No, Lu, Ll, Lt,
5914
5915Lm or Lo.  The alphanumeric tokens (format tokens) specify the format
5916
5917to be used for each number in the list.  If the first token is a
5918
5919non-alphanumeric token, then the constructed string will start with
5920
5921that token; if the last token is non-alphanumeric token, then the
5922
5923constructed string will end with that token.  Non-alphanumeric tokens
5924
5925that occur between two format tokens are separator tokens that are
5926
5927used to join numbers in the list.  The <var>n</var>th format token
5928
5929will be used to format the <var>n</var>th number in the list.  If
5930
5931there are more numbers than format tokens, then the last format token
5932
5933will be used to format remaining numbers.  If there are no format
5934
5935tokens, then a format token of <code>1</code> is used to format all
5936
5937numbers.  The format token specifies the string to be used to
5938
5939represent the number 1.  Each number after the first will be separated
5940
5941from the preceding number by the separator token preceding the format
5942
5943token used to format that number, or, if there are no separator
5944
5945tokens, then by <code>.</code> (a period character).</p>
5946
5947
5948
5949<p>Format tokens are a superset of the allowed values for the
5950
5951<code>type</code> attribute for the <code>OL</code> element in HTML
5952
59534.0 and are interpreted as follows:</p>
5954
5955
5956
5957<ulist>
5958
5959
5960
5961<item><p>Any token where the last character has a decimal digit value
5962
5963of 1 (as specified in the Unicode character property database),
5964
5965and the Unicode value of preceding characters is one less than the
5966
5967Unicode value of the last character generates a decimal
5968
5969representation of the number where each number is at least as long as
5970
5971the format token.  Thus, a format token <code>1</code> generates the
5972
5973sequence <code>1 2 ... 10 11 12 ...</code>, and a format token
5974
5975<code>01</code> generates the sequence <code>01 02 ... 09 10 11 12
5976
5977... 99 100 101</code>.</p></item>
5978
5979
5980
5981<item><p>A format token <code>A</code> generates the sequence <code>A
5982
5983B C ... Z AA AB AC...</code>.</p></item>
5984
5985
5986
5987<item><p>A format token <code>a</code> generates the sequence <code>a
5988
5989b c ... z aa ab ac...</code>.</p></item>
5990
5991
5992
5993<item><p>A format token <code>i</code> generates the sequence <code>i
5994
5995ii iii iv v vi vii viii ix x ...</code>.</p></item>
5996
5997
5998
5999<item><p>A format token <code>I</code> generates the sequence <code>I
6000
6001II III IV V VI VII VIII IX X ...</code>.</p></item>
6002
6003
6004
6005<item><p>Any other format token indicates a numbering sequence that
6006
6007starts with that token.  If an implementation does not support a
6008
6009numbering sequence that starts with that token, it must use a format
6010
6011token of <code>1</code>.</p></item>
6012
6013
6014
6015</ulist>
6016
6017
6018
6019<p>When numbering with an alphabetic sequence, the <code>lang</code>
6020
6021attribute specifies which language's alphabet is to be used; it has
6022
6023the same range of values as <code>xml:lang</code> <bibref ref="XML"/>;
6024
6025if no <code>lang</code> value is specified, the language should be
6026
6027determined from the system environment.  Implementers should document
6028
6029for which languages they support numbering.</p>
6030
6031
6032
6033<note><p>Implementers should not make any assumptions about how
6034
6035numbering works in particular languages and should properly research
6036
6037the languages that they wish to support.  The numbering conventions of
6038
6039many languages are very different from English.</p></note>
6040
6041
6042
6043<p>The <code>letter-value</code> attribute disambiguates between
6044
6045numbering sequences that use letters.  In many languages there are two
6046
6047commonly used numbering sequences that use letters.  One numbering
6048
6049sequence assigns numeric values to letters in alphabetic sequence, and
6050
6051the other assigns numeric values to each letter in some other manner
6052
6053traditional in that language.  In English, these would correspond to
6054
6055the numbering sequences specified by the format tokens <code>a</code>
6056
6057and <code>i</code>.  In some languages, the first member of each
6058
6059sequence is the same, and so the format token alone would be
6060
6061ambiguous.  A value of <code>alphabetic</code> specifies the
6062
6063alphabetic sequence; a value of <code>traditional</code> specifies the
6064
6065other sequence.  If the <code>letter-value</code> attribute is not
6066
6067specified, then it is implementation-dependent how any ambiguity is
6068
6069resolved.</p>
6070
6071
6072
6073<note><p>It is possible for two conforming XSLT processors not to
6074
6075convert a number to exactly the same string.  Some XSLT processors may not
6076
6077support some languages.  Furthermore, there may be variations possible
6078
6079in the way conversions are performed for any particular language that
6080
6081are not specifiable by the attributes on <code>xsl:number</code>.
6082
6083Future versions of XSLT may provide additional attributes to provide
6084
6085control over these variations.  Implementations may also use
6086
6087implementation-specific namespaced attributes on
6088
6089<code>xsl:number</code> for this.</p></note>
6090
6091
6092
6093<p>The <code>grouping-separator</code> attribute gives the separator
6094
6095used as a grouping (e.g. thousands) separator in decimal numbering
6096
6097sequences, and the optional <code>grouping-size</code> specifies the
6098
6099size (normally 3) of the grouping.  For example,
6100
6101<code>grouping-separator=","</code> and <code>grouping-size="3"</code>
6102
6103would produce numbers of the form <code>1,000,000</code>.  If only one
6104
6105of the <code>grouping-separator</code> and <code>grouping-size</code>
6106
6107attributes is specified, then it is ignored.</p>
6108
6109
6110
6111<p>Here are some examples of conversion specifications:</p>
6112
6113
6114
6115<ulist>
6116
6117
6118
6119<item><p><code>format="&amp;#x30A2;"</code> specifies Katakana
6120
6121numbering</p></item>
6122
6123
6124
6125<item><p><code>format="&amp;#x30A4;"</code> specifies Katakana
6126
6127numbering in the <quote>iroha</quote> order</p></item>
6128
6129
6130
6131<item><p><code>format="&amp;#x0E51;"</code> specifies numbering with
6132
6133Thai digits</p></item>
6134
6135
6136
6137<item><p><code>format="&amp;#x05D0;" letter-value="traditional"</code>
6138
6139specifies <quote>traditional</quote> Hebrew numbering</p></item>
6140
6141
6142
6143<item><p><code>format="&amp;#x10D0;" letter-value="traditional"</code>
6144
6145specifies Georgian numbering</p></item>
6146
6147
6148
6149<item><p><code>format="&amp;#x03B1;" letter-value="traditional"</code>
6150
6151specifies <quote>classical</quote> Greek numbering</p></item>
6152
6153
6154
6155<item><p><code>format="&amp;#x0430;" letter-value="traditional"</code>
6156
6157specifies Old Slavic numbering</p></item>
6158
6159
6160
6161</ulist>
6162
6163
6164
6165</div3>
6166
6167</div2>
6168
6169</div1>
6170
6171
6172
6173<div1 id="for-each">
6174
6175
6176
6177<head>Repetition</head>
6178
6179
6180
6181<e:element-syntax name="for-each">
6182
6183  <e:in-category name="instruction"/>
6184
6185  <e:attribute name="select" required="yes">
6186
6187    <e:data-type name="node-set-expression"/>
6188
6189  </e:attribute>
6190
6191  <e:sequence>
6192
6193    <e:element repeat="zero-or-more" name="sort"/>
6194
6195    <e:model name="template"/>
6196
6197  </e:sequence>
6198
6199</e:element-syntax>
6200
6201
6202
6203<p>When the result has a known regular structure, it is useful to be
6204
6205able to specify directly the template for selected nodes.  The
6206
6207<code>xsl:for-each</code> instruction contains a template, which is
6208
6209instantiated for each node selected by the <termref
6210
6211def="dt-expression">expression</termref> specified by the
6212
6213<code>select</code> attribute. The <code>select</code> attribute is
6214
6215required.  The expression must evaluate to a node-set.  The template
6216
6217is instantiated with the selected node as the <termref
6218
6219def="dt-current-node">current node</termref>, and with a list of all
6220
6221of the selected nodes as the <termref
6222
6223def="dt-current-node-list">current node list</termref>.  The nodes are
6224
6225processed in document order, unless a sorting specification is present
6226
6227(see <specref ref="sorting"/>).</p>
6228
6229
6230
6231<p>For example, given an XML document with this structure</p>
6232
6233
6234
6235<eg><![CDATA[<customers>
6236
6237  <customer>
6238
6239    <name>...</name>
6240
6241    <order>...</order>
6242
6243    <order>...</order>
6244
6245  </customer>
6246
6247  <customer>
6248
6249    <name>...</name>
6250
6251    <order>...</order>
6252
6253    <order>...</order>
6254
6255  </customer>
6256
6257</customers>]]></eg>
6258
6259
6260
6261<p>the following would create an HTML document containing a table with
6262
6263a row for each <code>customer</code> element</p>
6264
6265
6266
6267<eg><![CDATA[<xsl:template match="/">
6268
6269  <html>
6270
6271    <head>
6272
6273      <title>Customers</title>
6274
6275    </head>
6276
6277    <body>
6278
6279      <table>
6280
6281	<tbody>
6282
6283	  <xsl:for-each select="customers/customer">
6284
6285	    <tr>
6286
6287	      <th>
6288
6289		<xsl:apply-templates select="name"/>
6290
6291	      </th>
6292
6293	      <xsl:for-each select="order">
6294
6295		<td>
6296
6297		  <xsl:apply-templates/>
6298
6299		</td>
6300
6301	      </xsl:for-each>
6302
6303	    </tr>
6304
6305	  </xsl:for-each>
6306
6307	</tbody>
6308
6309      </table>
6310
6311    </body>
6312
6313  </html>
6314
6315</xsl:template>]]></eg>
6316
6317
6318
6319</div1>
6320
6321
6322
6323<div1>
6324
6325<head>Conditional Processing</head>
6326
6327
6328
6329<p>There are two instructions in XSLT that support conditional
6330
6331processing in a template: <code>xsl:if</code> and
6332
6333<code>xsl:choose</code>. The <code>xsl:if</code> instruction provides
6334
6335simple if-then conditionality; the <code>xsl:choose</code> instruction
6336
6337supports selection of one choice when there are several
6338
6339possibilities.</p>
6340
6341
6342
6343<div2>
6344
6345<head>Conditional Processing with <code>xsl:if</code></head>
6346
6347
6348
6349<e:element-syntax name="if">
6350
6351  <e:in-category name="instruction"/>
6352
6353  <e:attribute name="test" required="yes">
6354
6355    <e:data-type name="boolean-expression"/>
6356
6357  </e:attribute>
6358
6359  <e:model name="template"/>
6360
6361</e:element-syntax>
6362
6363
6364
6365<p>The <code>xsl:if</code> element has a <code>test</code> attribute,
6366
6367which specifies an <termref def="dt-expression">expression</termref>.
6368
6369The content is a template.  The expression is evaluated and the
6370
6371resulting object is converted to a boolean as if by a call to the
6372
6373<xfunction>boolean</xfunction> function.  If the result is true, then
6374
6375the content template is instantiated; otherwise, nothing is created.
6376
6377In the following example, the names in a group of names are formatted
6378
6379as a comma separated list:</p>
6380
6381
6382
6383<eg><![CDATA[<xsl:template match="namelist/name">
6384
6385  <xsl:apply-templates/>
6386
6387  <xsl:if test="not(position()=last())">, </xsl:if>
6388
6389</xsl:template>]]></eg>
6390
6391
6392
6393<p>The following colors every other table row yellow:</p>
6394
6395
6396
6397<eg><![CDATA[<xsl:template match="item">
6398
6399  <tr>
6400
6401    <xsl:if test="position() mod 2 = 0">
6402
6403       <xsl:attribute name="bgcolor">yellow</xsl:attribute>
6404
6405    </xsl:if>
6406
6407    <xsl:apply-templates/>
6408
6409  </tr>
6410
6411</xsl:template>]]></eg>
6412
6413
6414
6415</div2>
6416
6417
6418
6419
6420
6421<div2>
6422
6423<head>Conditional Processing with <code>xsl:choose</code></head>
6424
6425
6426
6427<e:element-syntax name="choose">
6428
6429  <e:in-category name="instruction"/>
6430
6431  <e:sequence>
6432
6433    <e:element repeat="one-or-more" name="when"/>
6434
6435    <e:element repeat="zero-or-one" name="otherwise"/>
6436
6437  </e:sequence>
6438
6439</e:element-syntax>
6440
6441
6442
6443<e:element-syntax name="when">
6444
6445  <e:attribute name="test" required="yes">
6446
6447    <e:data-type name="boolean-expression"/>
6448
6449  </e:attribute>
6450
6451  <e:model name="template"/>
6452
6453</e:element-syntax>
6454
6455
6456
6457<e:element-syntax name="otherwise">
6458
6459  <e:model name="template"/>
6460
6461</e:element-syntax>
6462
6463
6464
6465<p>The <code>xsl:choose</code> element selects one among a number of
6466
6467possible alternatives. It consists of a sequence of
6468
6469<code>xsl:when</code> elements followed by an optional
6470
6471<code>xsl:otherwise</code> element.  Each <code>xsl:when</code>
6472
6473element has a single attribute, <code>test</code>, which specifies an
6474
6475<termref def="dt-expression">expression</termref>. The content of the
6476
6477<code>xsl:when</code> and <code>xsl:otherwise</code> elements is a
6478
6479template.  When an <code>xsl:choose</code> element is processed, each
6480
6481of the <code>xsl:when</code> elements is tested in turn, by evaluating
6482
6483the expression and converting the resulting object to a boolean as if
6484
6485by a call to the <xfunction>boolean</xfunction> function.  The content
6486
6487of the first, and only the first, <code>xsl:when</code> element whose
6488
6489test is true is instantiated.  If no <code>xsl:when</code> is true,
6490
6491the content of the <code>xsl:otherwise</code> element is
6492
6493instantiated. If no <code>xsl:when</code> element is true, and no
6494
6495<code>xsl:otherwise</code> element is present, nothing is created.</p>
6496
6497
6498
6499<p>The following example enumerates items in an ordered list using
6500
6501arabic numerals, letters, or roman numerals depending on the depth to
6502
6503which the ordered lists are nested.</p>
6504
6505
6506
6507<eg><![CDATA[<xsl:template match="orderedlist/listitem">
6508
6509  <fo:list-item indent-start='2pi'>
6510
6511    <fo:list-item-label>
6512
6513      <xsl:variable name="level"
6514
6515                    select="count(ancestor::orderedlist) mod 3"/>
6516
6517      <xsl:choose>
6518
6519        <xsl:when test='$level=1'>
6520
6521          <xsl:number format="i"/>
6522
6523        </xsl:when>
6524
6525        <xsl:when test='$level=2'>
6526
6527          <xsl:number format="a"/>
6528
6529        </xsl:when>
6530
6531        <xsl:otherwise>
6532
6533          <xsl:number format="1"/>
6534
6535        </xsl:otherwise>
6536
6537      </xsl:choose>
6538
6539      <xsl:text>. </xsl:text>
6540
6541    </fo:list-item-label>
6542
6543    <fo:list-item-body>
6544
6545      <xsl:apply-templates/>
6546
6547    </fo:list-item-body>
6548
6549  </fo:list-item>
6550
6551</xsl:template>]]></eg>
6552
6553
6554
6555</div2>
6556
6557</div1>
6558
6559
6560
6561<div1 id="sorting">
6562
6563<head>Sorting</head>
6564
6565
6566
6567<e:element-syntax name="sort">
6568
6569  <e:attribute name="select">
6570
6571    <e:data-type name="string-expression"/>
6572
6573  </e:attribute>
6574
6575  <e:attribute name="lang">
6576
6577    <e:attribute-value-template>
6578
6579      <e:data-type name="nmtoken"/>
6580
6581    </e:attribute-value-template>
6582
6583  </e:attribute>
6584
6585  <e:attribute name="data-type">
6586
6587    <e:attribute-value-template>
6588
6589       <e:constant value="text"/>
6590
6591       <e:constant value="number"/>
6592
6593       <e:data-type name="qname-but-not-ncname"/>
6594
6595    </e:attribute-value-template>
6596
6597  </e:attribute>
6598
6599  <e:attribute name="order">
6600
6601    <e:attribute-value-template>
6602
6603       <e:constant value="ascending"/>
6604
6605       <e:constant value="descending"/>
6606
6607    </e:attribute-value-template>
6608
6609  </e:attribute>
6610
6611  <e:attribute name="case-order">
6612
6613    <e:attribute-value-template>
6614
6615       <e:constant value="upper-first"/>
6616
6617       <e:constant value="lower-first"/>
6618
6619    </e:attribute-value-template>
6620
6621  </e:attribute>
6622
6623  <e:empty/>
6624
6625</e:element-syntax>
6626
6627
6628
6629<p>Sorting is specified by adding <code>xsl:sort</code> elements as
6630
6631children of an <code>xsl:apply-templates</code> or
6632
6633<code>xsl:for-each</code> element.  The first <code>xsl:sort</code>
6634
6635child specifies the primary sort key, the second <code>xsl:sort</code>
6636
6637child specifies the secondary sort key and so on.  When an
6638
6639<code>xsl:apply-templates</code> or <code>xsl:for-each</code> element
6640
6641has one or more <code>xsl:sort</code> children, then instead of
6642
6643processing the selected nodes in document order, it sorts the nodes
6644
6645according to the specified sort keys and then processes them in sorted
6646
6647order.  When used in <code>xsl:for-each</code>, <code>xsl:sort</code>
6648
6649elements must occur first.  When a template is instantiated by
6650
6651<code>xsl:apply-templates</code> and <code>xsl:for-each</code>, the
6652
6653<termref def="dt-current-node-list">current node list</termref> list
6654
6655consists of the complete list of nodes being processed in sorted
6656
6657order.</p>
6658
6659
6660
6661<p><code>xsl:sort</code> has a <code>select</code> attribute whose
6662
6663value is an <termref def="dt-expression">expression</termref>. For
6664
6665each node to be processed, the expression is evaluated with that node
6666
6667as the current node and with the complete list of nodes being
6668
6669processed in unsorted order as the current node list.
6670
6671The resulting object is converted to a string as
6672
6673if by a call to the <xfunction>string</xfunction> function; this string
6674
6675is used as the sort key for that node. The default value of the
6676
6677<code>select</code> attribute is <code>.</code>, which will cause the
6678
6679string-value of the current node to be used as the sort key.</p>
6680
6681
6682
6683<p>This string serves as a sort key for the node.  The following
6684
6685optional attributes on <code>xsl:sort</code> control how the list of
6686
6687sort keys are sorted; the values of all of these attributes are
6688
6689interpreted as <termref def="dt-attribute-value-template">attribute
6690
6691value templates</termref>.</p>
6692
6693
6694
6695<ulist>
6696
6697
6698
6699<item><p><code>order</code> specifies whether the strings should be
6700
6701sorted in ascending or descending order; <code>ascending</code>
6702
6703specifies ascending order; <code>descending</code> specifies
6704
6705descending order; the default is <code>ascending</code></p></item>
6706
6707
6708
6709<item><p><code>lang</code> specifies the language of the sort keys; it
6710
6711has the same range of values as <code>xml:lang</code> <bibref
6712
6713ref="XML"/>; if no <code>lang</code> value is specified, the language
6714
6715should be determined from the system environment</p></item>
6716
6717
6718
6719<item><p><code>data-type</code> specifies the data type of the
6720
6721strings; the following values are allowed:</p>
6722
6723
6724
6725<ulist>
6726
6727
6728
6729<item><p><code>text</code> specifies that the sort keys should be
6730
6731sorted lexicographically in the culturally correct manner for the
6732
6733language specified by <code>lang</code></p></item>
6734
6735
6736
6737<item><p><code>number</code> specifies that the sort keys should be
6738
6739converted to numbers and then sorted according to the numeric value;
6740
6741the sort key is converted to a number as if by a call to the
6742
6743<xfunction>number</xfunction> function; the <code>lang</code>
6744
6745attribute is ignored</p></item>
6746
6747
6748
6749<item><p>a <xnt href="&XMLNames;#NT-QName">QName</xnt> with a prefix
6750
6751is expanded into an <xtermref
6752
6753href="&XPath;#dt-expanded-name">expanded-name</xtermref> as described
6754
6755in <specref ref="qname"/>; the expanded-name identifies the data-type;
6756
6757the behavior in this case is not specified by this document</p></item>
6758
6759
6760
6761</ulist>
6762
6763
6764
6765<p>The default value is <code>text</code>.</p>
6766
6767
6768
6769<note><p>The XSL Working Group plans that future versions of XSLT will
6770
6771leverage XML Schemas to define further values for this
6772
6773attribute.</p></note>
6774
6775
6776
6777</item>
6778
6779
6780
6781<item><p><code>case-order</code> has the value
6782
6783<code>upper-first</code> or <code>lower-first</code>; this applies
6784
6785when <code>data-type="text"</code>, and specifies that upper-case
6786
6787letters should sort before lower-case letters or vice-versa
6788
6789respectively. For example, if <code>lang="en"</code>, then <code>A a B
6790
6791b</code> are sorted with <code>case-order="upper-first"</code> and
6792
6793<code>a A b B</code> are sorted with
6794
6795<code>case-order="lower-first"</code>. The default value is language
6796
6797dependent.</p></item>
6798
6799
6800
6801</ulist>
6802
6803
6804
6805<note><p>It is possible for two conforming XSLT processors not to sort
6806
6807exactly the same.  Some XSLT processors may not support some
6808
6809languages.  Furthermore, there may be variations possible in the
6810
6811sorting of any particular language that are not specified by the
6812
6813attributes on <code>xsl:sort</code>, for example, whether Hiragana or
6814
6815Katakana is sorted first in Japanese.  Future versions of XSLT may
6816
6817provide additional attributes to provide control over these
6818
6819variations.  Implementations may also use implementation-specific
6820
6821namespaced attributes on <code>xsl:sort</code> for this.</p></note>
6822
6823
6824
6825<note><p>It is recommended that implementers consult <bibref
6826
6827ref="UNICODE-TR10"/> for information on internationalized
6828
6829sorting.</p></note>
6830
6831
6832
6833<p>The sort must be stable: in the sorted list of nodes, any sub list
6834
6835that has sort keys that all compare equal must be in document
6836
6837order.</p>
6838
6839
6840
6841<p>For example, suppose an employee database has the form</p>
6842
6843
6844
6845<eg><![CDATA[<employees>
6846
6847  <employee>
6848
6849    <name>
6850
6851      <given>James</given>
6852
6853      <family>Clark</family>
6854
6855    </name>
6856
6857    ...
6858
6859  </employee>
6860
6861</employees>
6862
6863]]></eg>
6864
6865
6866
6867<p>Then a list of employees sorted by name could be generated
6868
6869using:</p>
6870
6871
6872
6873<eg><![CDATA[<xsl:template match="employees">
6874
6875  <ul>
6876
6877    <xsl:apply-templates select="employee">
6878
6879      <xsl:sort select="name/family"/>
6880
6881      <xsl:sort select="name/given"/>
6882
6883    </xsl:apply-templates>
6884
6885  </ul>
6886
6887</xsl:template>
6888
6889
6890
6891<xsl:template match="employee">
6892
6893  <li>
6894
6895    <xsl:value-of select="name/given"/>
6896
6897    <xsl:text> </xsl:text>
6898
6899    <xsl:value-of select="name/family"/>
6900
6901  </li>
6902
6903</xsl:template>]]></eg>
6904
6905
6906
6907</div1>
6908
6909
6910
6911<div1 id="variables">
6912
6913<head>Variables and Parameters</head>
6914
6915
6916
6917<e:element-syntax name="variable">
6918
6919  <e:in-category name="top-level-element"/>
6920
6921  <e:in-category name="instruction"/>
6922
6923  <e:attribute name="name" required="yes">
6924
6925    <e:data-type name="qname"/>
6926
6927  </e:attribute>
6928
6929  <e:attribute name="select">
6930
6931    <e:data-type name="expression"/>
6932
6933  </e:attribute>
6934
6935  <e:model name="template"/>
6936
6937</e:element-syntax>
6938
6939
6940
6941<e:element-syntax name="param">
6942
6943  <e:in-category name="top-level-element"/>
6944
6945  <e:attribute name="name" required="yes">
6946
6947    <e:data-type name="qname"/>
6948
6949  </e:attribute>
6950
6951  <e:attribute name="select">
6952
6953    <e:data-type name="expression"/>
6954
6955  </e:attribute>
6956
6957  <e:model name="template"/>
6958
6959</e:element-syntax>
6960
6961
6962
6963<p>A variable is a name that may be bound to a value.  The value to
6964
6965which a variable is bound (the <term>value</term> of the variable) can
6966
6967be an object of any of the types that can be returned by expressions.
6968
6969There are two elements that can be used to bind variables:
6970
6971<code>xsl:variable</code> and <code>xsl:param</code>. The difference
6972
6973is that the value specified on the <code>xsl:param</code> variable is
6974
6975only a default value for the binding; when the template or stylesheet
6976
6977within which the <code>xsl:param</code> element occurs is invoked,
6978
6979parameters may be passed that are used in place of the default
6980
6981values.</p>
6982
6983
6984
6985<p>Both <code>xsl:variable</code> and <code>xsl:param</code> have a
6986
6987required <code>name</code> attribute, which specifies the name of the
6988
6989variable.  The value of the <code>name</code> attribute is a <xnt
6990
6991href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
6992
6993in <specref ref="qname"/>.</p>
6994
6995
6996
6997<p>For any use of these variable-binding elements, there is a region
6998
6999of the stylesheet tree within which the binding is visible; within
7000
7001this region, any binding of the variable that was visible on the
7002
7003variable-binding element itself is hidden.  Thus, only the innermost
7004
7005binding of a variable is visible.  The set of variable bindings in
7006
7007scope for an expression consists of those bindings that are visible at
7008
7009the point in the stylesheet where the expression occurs.</p>
7010
7011
7012
7013<div2>
7014
7015<head>Result Tree Fragments</head>
7016
7017
7018
7019<p>Variables introduce an additional data-type into the expression
7020
7021language.  <termdef id="dt-result-tree-fragment" term="Result Tree
7022
7023Fragment">This additional data type is called <term>result tree
7024
7025fragment</term>.  A variable may be bound to a result tree fragment
7026
7027instead of one of the four basic XPath data-types (string, number,
7028
7029boolean, node-set).  A result tree fragment represents a fragment of
7030
7031the result tree. A result tree fragment is treated equivalently to a
7032
7033node-set that contains just a single root node.</termdef> However, the
7034
7035operations permitted on a result tree fragment are a subset of those
7036
7037permitted on a node-set.  An operation is permitted on a result tree
7038
7039fragment only if that operation would be permitted on a string (the
7040
7041operation on the string may involve first converting the string to a
7042
7043number or boolean). In particular, it is not permitted to use the
7044
7045<code>/</code>, <code>//</code>, and <code>[]</code> operators on
7046
7047result tree fragments.  When a permitted operation is performed on a
7048
7049result tree fragment, it is performed exactly as it would be on the
7050
7051equivalent node-set.</p>
7052
7053
7054
7055<p>When a result tree fragment is copied into the result tree (see
7056
7057<specref ref="copy-of"/>), then all the nodes that are children of the
7058
7059root node in the equivalent node-set are added in sequence to the
7060
7061result tree.</p>
7062
7063
7064
7065<p>Expressions can only return values of type result tree fragment by
7066
7067referencing variables of type result tree fragment or calling
7068
7069extension functions that return a result tree fragment or getting a
7070
7071system property whose value is a result tree fragment.</p>
7072
7073
7074
7075</div2>
7076
7077
7078
7079<div2 id="variable-values">
7080
7081<head>Values of Variables and Parameters</head>
7082
7083
7084
7085<p>A variable-binding element can specify the value of the variable in
7086
7087three alternative ways.</p>
7088
7089
7090
7091<ulist>
7092
7093
7094
7095<item><p>If the variable-binding element has a <code>select</code>
7096
7097attribute, then the value of the attribute must be an <termref
7098
7099def="dt-expression">expression</termref> and the value of the variable
7100
7101is the object that results from evaluating the expression.  In this
7102
7103case, the content must be empty.</p></item>
7104
7105
7106
7107<item>
7108
7109
7110
7111<p>If the variable-binding element does not have a <code>select</code>
7112
7113attribute and has non-empty content (i.e. the variable-binding element
7114
7115has one or more child nodes), then the content of the
7116
7117variable-binding element specifies the value. The content of the
7118
7119variable-binding element is a template, which is instantiated to give
7120
7121the value of the variable. The value is a result tree fragment
7122
7123equivalent to a node-set containing just a single root node having as
7124
7125children the sequence of nodes produced by instantiating the template.
7126
7127The base URI of the nodes in the result tree fragment is the base URI
7128
7129of the variable-binding element.</p>
7130
7131
7132
7133<p>It is an error if a member of the sequence of nodes created by
7134
7135instantiating the template is an attribute node or a namespace node,
7136
7137since a root node cannot have an attribute node or a namespace node as
7138
7139a child. An XSLT processor may signal the error; if it does not signal
7140
7141the error, it must recover by not adding the attribute node or
7142
7143namespace node.</p>
7144
7145
7146
7147</item>
7148
7149
7150
7151<item>
7152
7153
7154
7155<p>If the variable-binding element has empty content and does not have
7156
7157a <code>select</code> attribute, then the value of the variable is an
7158
7159empty string. Thus</p>
7160
7161
7162
7163<eg><![CDATA[<xsl:variable name="x"/>]]></eg>
7164
7165
7166
7167<p>is equivalent to</p>
7168
7169
7170
7171<eg><![CDATA[<xsl:variable name="x" select="''"/>]]></eg>
7172
7173
7174
7175</item>
7176
7177
7178
7179</ulist>
7180
7181
7182
7183<note><p>When a variable is used to select nodes by position, be careful
7184
7185not to do:</p>
7186
7187
7188
7189<eg><![CDATA[<xsl:variable name="n">2</xsl:variable>
7190
7191...
7192
7193<xsl:value-of select="item[$n]"/>]]></eg>
7194
7195
7196
7197<p>This will output the value of the first item element, because the
7198
7199variable <code>n</code> will be bound to a result tree fragment, not a
7200
7201number. Instead, do either</p>
7202
7203
7204
7205<eg><![CDATA[<xsl:variable name="n" select="2"/>
7206
7207...
7208
7209<xsl:value-of select="item[$n]"/>]]></eg>
7210
7211
7212
7213<p>or</p>
7214
7215
7216
7217<eg><![CDATA[<xsl:variable name="n">2</xsl:variable>
7218
7219...
7220
7221<xsl:value-of select="item[position()=$n]"/>]]></eg>
7222
7223</note>
7224
7225
7226
7227<note><p>One convenient way to specify the empty node-set as the default
7228
7229value of a parameter is:</p>
7230
7231
7232
7233<eg><![CDATA[<xsl:param name="x" select="/.."/>]]></eg>
7234
7235</note>
7236
7237
7238
7239</div2>
7240
7241
7242
7243<div2 id="copy-of">
7244
7245<head>Using Values of Variables and Parameters with
7246
7247<code>xsl:copy-of</code></head>
7248
7249
7250
7251<e:element-syntax name="copy-of">
7252
7253  <e:in-category name="instruction"/>
7254
7255  <e:attribute name="select" required="yes">
7256
7257    <e:data-type name="expression"/>
7258
7259  </e:attribute>
7260
7261  <e:empty/>
7262
7263</e:element-syntax>
7264
7265
7266
7267<p>The <code>xsl:copy-of</code> element can be used to insert a result
7268
7269tree fragment into the result tree, without first converting it to a
7270
7271string as <code>xsl:value-of</code> does (see <specref
7272
7273ref="value-of"/>).  The required <code>select</code> attribute
7274
7275contains an <termref def="dt-expression">expression</termref>.  When
7276
7277the result of evaluating the expression is a result tree fragment, the
7278
7279complete fragment is copied into the result tree.  When the result is
7280
7281a node-set, all the nodes in the set are copied in document order into
7282
7283the result tree; copying an element node copies the attribute nodes,
7284
7285namespace nodes and children of the element node as well as the
7286
7287element node itself; a root node is copied by copying its children.
7288
7289When the result is neither a node-set nor a result tree fragment, the
7290
7291result is converted to a string and then inserted into the result
7292
7293tree, as with <code>xsl:value-of</code>.</p>
7294
7295
7296
7297</div2>
7298
7299
7300
7301<div2 id="top-level-variables">
7302
7303<head>Top-level Variables and Parameters</head>
7304
7305
7306
7307<p>Both <code>xsl:variable</code> and <code>xsl:param</code> are
7308
7309allowed as <termref def="dt-top-level">top-level</termref> elements.
7310
7311A top-level variable-binding element declares a global variable that
7312
7313is visible everywhere.  A top-level <code>xsl:param</code> element
7314
7315declares a parameter to the stylesheet; XSLT does not define the
7316
7317mechanism by which parameters are passed to the stylesheet.  It is an
7318
7319error if a stylesheet contains more than one binding of a top-level
7320
7321variable with the same name and same <termref
7322
7323def="dt-import-precedence">import precedence</termref>. At the
7324
7325top-level, the expression or template specifying the variable value is
7326
7327evaluated with the same context as that used to process the root node
7328
7329of the source document: the current node is the root node of the
7330
7331source document and the current node list is a list containing just
7332
7333the root node of the source document.  If the template or expression
7334
7335specifying the value of a global variable <var>x</var> references a
7336
7337global variable <var>y</var>, then the value for <var>y</var> must
7338
7339be computed before the value of <var>x</var>.  It is an error if it
7340
7341is impossible to do this for all global variable definitions; in other
7342
7343words, it is an error if the definitions are circular.</p>
7344
7345
7346
7347<p>This example declares a global variable <code>para-font-size</code>,
7348
7349which it references in an attribute value template.</p>
7350
7351
7352
7353<eg><![CDATA[<xsl:variable name="para-font-size">12pt</xsl:variable>
7354
7355
7356
7357<xsl:template match="para">
7358
7359 <fo:block font-size="{$para-font-size}">
7360
7361   <xsl:apply-templates/>
7362
7363 </fo:block>
7364
7365</xsl:template>
7366
7367]]></eg>
7368
7369
7370
7371</div2>
7372
7373
7374
7375<div2 id="local-variables">
7376
7377<head>Variables and Parameters within Templates</head>
7378
7379
7380
7381<p>As well as being allowed at the top-level, both
7382
7383<code>xsl:variable</code> and <code>xsl:param</code> are also
7384
7385allowed in templates.  <code>xsl:variable</code> is allowed anywhere
7386
7387within a template that an instruction is allowed.  In this case, the
7388
7389binding is visible for all following siblings and their descendants.
7390
7391Note that the binding is not visible for the <code>xsl:variable</code>
7392
7393element itself.  <code>xsl:param</code> is allowed as a child
7394
7395at the beginning of an <code>xsl:template</code> element.  In this
7396
7397context, the binding is visible for all following siblings and their
7398
7399descendants.  Note that the binding is not visible for the
7400
7401<code>xsl:param</code> element itself.</p>
7402
7403
7404
7405<p><termdef id="dt-shadows" term="Shadows">A binding
7406
7407<term>shadows</term> another binding if the binding occurs at a point
7408
7409where the other binding is visible, and the bindings have the same
7410
7411name.</termdef> It is an error if a binding established by an
7412
7413<code>xsl:variable</code> or <code>xsl:param</code> element within a
7414
7415template <termref def="dt-shadows">shadows</termref> another binding
7416
7417established by an <code>xsl:variable</code> or <code>xsl:param</code>
7418
7419element also within the template.  It is not an error if a binding
7420
7421established by an <code>xsl:variable</code> or <code>xsl:param</code>
7422
7423element in a template <termref def="dt-shadows">shadows</termref>
7424
7425another binding established by an <code>xsl:variable</code> or
7426
7427<code>xsl:param</code> <termref def="dt-top-level">top-level</termref>
7428
7429element.  Thus, the following is an error:</p>
7430
7431
7432
7433<eg role="error"><![CDATA[<xsl:template name="foo">
7434
7435<xsl:param name="x" select="1"/>
7436
7437<xsl:variable name="x" select="2"/>
7438
7439</xsl:template>]]></eg>
7440
7441
7442
7443<p>However, the following is allowed:</p>
7444
7445
7446
7447<eg><![CDATA[<xsl:param name="x" select="1"/>
7448
7449<xsl:template name="foo">
7450
7451<xsl:variable name="x" select="2"/>
7452
7453</xsl:template>]]></eg>
7454
7455
7456
7457<note><p>The nearest equivalent in Java to an <code>xsl:variable</code>
7458
7459element in a template is a final local variable declaration with an
7460
7461initializer.  For example,</p>
7462
7463
7464
7465<eg><![CDATA[<xsl:variable name="x" select="'value'"/>]]></eg>
7466
7467
7468
7469<p>has similar semantics to</p>
7470
7471
7472
7473<eg>final Object x = "value";</eg>
7474
7475
7476
7477<p>XSLT does not provide an equivalent to the Java assignment operator</p>
7478
7479
7480
7481<eg>x = "value";</eg>
7482
7483
7484
7485<p>because this would make it harder to create an implementation that
7486
7487processes a document other than in a batch-like way, starting at the
7488
7489beginning and continuing through to the end.</p></note>
7490
7491
7492
7493</div2>
7494
7495
7496
7497<div2>
7498
7499<head>Passing Parameters to Templates</head>
7500
7501
7502
7503<e:element-syntax name="with-param">
7504
7505  <e:attribute name="name" required="yes">
7506
7507    <e:data-type name="qname"/>
7508
7509  </e:attribute>
7510
7511  <e:attribute name="select">
7512
7513    <e:data-type name="expression"/>
7514
7515  </e:attribute>
7516
7517  <e:model name="template"/>
7518
7519</e:element-syntax>
7520
7521
7522
7523<p>Parameters are passed to templates using the
7524
7525<code>xsl:with-param</code> element.  The required <code>name</code>
7526
7527attribute specifies the name of the parameter (the variable the value
7528
7529of whose binding is to be replaced).  The value of the
7530
7531<code>name</code> attribute is a <xnt
7532
7533href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
7534
7535in <specref ref="qname"/>.  <code>xsl:with-param</code> is allowed
7536
7537within both <code>xsl:call-template</code> and
7538
7539<code>xsl:apply-templates</code>.  The value of the parameter is
7540
7541specified in the same way as for <code>xsl:variable</code> and
7542
7543<code>xsl:param</code>.  The current node and current node list used
7544
7545for computing the value specified by <code>xsl:with-param</code>
7546
7547element is the same as that used for the
7548
7549<code>xsl:apply-templates</code> or <code>xsl:call-template</code>
7550
7551element within which it occurs.  It is not an error to pass a
7552
7553parameter <var>x</var> to a template that does not have an
7554
7555<code>xsl:param</code> element for <var>x</var>; the parameter is
7556
7557simply ignored.</p>
7558
7559
7560
7561<p>This example defines a named template for a
7562
7563<code>numbered-block</code> with an argument to control the format of
7564
7565the number.</p>
7566
7567
7568
7569<eg><![CDATA[<xsl:template name="numbered-block">
7570
7571  <xsl:param name="format">1. </xsl:param>
7572
7573  <fo:block>
7574
7575    <xsl:number format="{$format}"/>
7576
7577    <xsl:apply-templates/>
7578
7579  </fo:block>
7580
7581</xsl:template>
7582
7583
7584
7585<xsl:template match="ol//ol/li">
7586
7587  <xsl:call-template name="numbered-block">
7588
7589    <xsl:with-param name="format">a. </xsl:with-param>
7590
7591  </xsl:call-template>
7592
7593</xsl:template>]]></eg>
7594
7595
7596
7597</div2>
7598
7599
7600
7601</div1>
7602
7603
7604
7605<div1 id="add-func">
7606
7607<head>Additional Functions</head>
7608
7609
7610
7611<p>This section describes XSLT-specific additions to the core XPath
7612
7613function library.  Some of these additional functions also make use of
7614
7615information specified by <termref def="dt-top-level">top-level</termref>
7616
7617elements in the stylesheet; this section also describes these
7618
7619elements.</p>
7620
7621
7622
7623<div2 id="document">
7624
7625
7626
7627<head>Multiple Source Documents</head>
7628
7629
7630
7631<proto name="document" return-type="node-set"><arg type="object"/>
7632
7633<arg type="node-set" occur="opt"/></proto>
7634
7635
7636
7637<p>The <function>document</function> function allows
7638
7639access to XML documents other than the main source document.</p>
7640
7641
7642
7643<p>When the <function>document</function> function has exactly one
7644
7645argument and the argument is a node-set, then the result is the union,
7646
7647for each node in the argument node-set, of the result of calling the
7648
7649<function>document</function> function with the first argument being
7650
7651the <xtermref href="&XPath;#dt-string-value">string-value</xtermref>
7652
7653of the node, and the second argument being a node-set with the node as
7654
7655its only member. When the <function>document</function> function has
7656
7657two arguments and the first argument is a node-set, then the result is
7658
7659the union, for each node in the argument node-set, of the result of
7660
7661calling the <function>document</function> function with the first
7662
7663argument being the <xtermref
7664
7665href="&XPath;#dt-string-value">string-value</xtermref> of the node,
7666
7667and with the second argument being the second argument passed to the
7668
7669<function>document</function> function.</p>
7670
7671
7672
7673<p>When the first argument to the <function>document</function>
7674
7675function is not a node-set, the first argument is converted to a
7676
7677string as if by a call to the <xfunction>string</xfunction> function.
7678
7679This string is treated as a URI reference; the resource identified by
7680
7681the URI is retrieved. The data resulting from the retrieval action is
7682
7683parsed as an XML document and a tree is constructed in accordance with
7684
7685the data model (see <specref ref="data-model"/>).  If there is an
7686
7687error retrieving the resource, then the XSLT processor may signal an
7688
7689error; if it does not signal an error, it must recover by returning an
7690
7691empty node-set.  One possible kind of retrieval error is that the XSLT
7692
7693processor does not support the URI scheme used by the URI.  An XSLT
7694
7695processor is not required to support any particular URI schemes.  The
7696
7697documentation for an XSLT processor should specify which URI schemes
7698
7699the XSLT processor supports.</p>
7700
7701
7702
7703<p>If the URI reference does not contain a fragment identifier, then a
7704
7705node-set containing just the root node of the document is returned.
7706
7707If the URI reference does contain a fragment identifier, the function
7708
7709returns a node-set containing the nodes in the tree identified by the
7710
7711fragment identifier of the URI reference. The semantics of the
7712
7713fragment identifier is dependent on the media type of the result of
7714
7715retrieving the URI.  If there is an error in processing the fragment
7716
7717identifier, the XSLT processor may signal the error; if it does not
7718
7719signal the error, it must recover by returning an empty node-set.
7720
7721Possible errors include:</p>
7722
7723
7724
7725<ulist>
7726
7727
7728
7729<item><p>The fragment identifier identifies something that cannot be
7730
7731represented by an XSLT node-set (such as a range of characters within
7732
7733a text node).</p></item>
7734
7735
7736
7737<item><p>The XSLT processor does not support fragment identifiers for
7738
7739the media-type of the retrieval result.  An XSLT processor is not
7740
7741required to support any particular media types.  The documentation for
7742
7743an XSLT processor should specify for which media types the XSLT
7744
7745processor supports fragment identifiers.</p></item>
7746
7747
7748
7749</ulist>
7750
7751
7752
7753<p>The data resulting from the retrieval action is parsed as an XML
7754
7755document regardless of the media type of the retrieval result; if the
7756
7757top-level media type is <code>text</code>, then it is parsed in the
7758
7759same way as if the media type were <code>text/xml</code>; otherwise,
7760
7761it is parsed in the same way as if the media type were
7762
7763<code>application/xml</code>.</p>
7764
7765
7766
7767<note><p>Since there is no top-level <code>xml</code> media type, data
7768
7769with a media type other than <code>text/xml</code> or
7770
7771<code>application/xml</code> may in fact be XML.</p></note>
7772
7773
7774
7775<p>The URI reference may be relative. The base URI (see <specref
7776
7777ref="base-uri"/>) of the node in the second argument node-set that is
7778
7779first in document order is used as the base URI for resolving the
7780
7781relative URI into an absolute URI.  If the second argument is omitted,
7782
7783then it defaults to the node in the stylesheet that contains the
7784
7785expression that includes the call to the <function>document</function>
7786
7787function.  Note that a zero-length URI reference is a reference to the
7788
7789document relative to which the URI reference is being resolved; thus
7790
7791<code>document("")</code> refers to the root node of the stylesheet;
7792
7793the tree representation of the stylesheet is exactly the same as if
7794
7795the XML document containing the stylesheet was the initial source
7796
7797document.</p>
7798
7799
7800
7801<p>Two documents are treated as the same document if they are
7802
7803identified by the same URI. The URI used for the comparison is the
7804
7805absolute URI into which any relative URI was resolved and does not
7806
7807include any fragment identifier.  One root node is treated as the same
7808
7809node as another root node if the two nodes are from the same document.
7810
7811Thus, the following expression will always be true:</p>
7812
7813
7814
7815<eg>generate-id(document("foo.xml"))=generate-id(document("foo.xml"))</eg>
7816
7817
7818
7819<p>The <function>document</function> function gives rise to the
7820
7821possibility that a node-set may contain nodes from more than one
7822
7823document.  With such a node-set, the relative document order of two
7824
7825nodes in the same document is the normal <xtermref
7826
7827href="&XPath;#dt-document-order">document order</xtermref> defined by
7828
7829XPath <bibref ref="XPATH"/>.  The relative document order of two nodes
7830
7831in different documents is determined by an implementation-dependent
7832
7833ordering of the documents containing the two nodes.  There are no
7834
7835constraints on how the implementation orders documents other than that
7836
7837it must do so consistently: an implementation must always use the same
7838
7839order for the same set of documents.</p>
7840
7841
7842
7843</div2>
7844
7845
7846
7847<div2 id="key">
7848
7849<head>Keys</head>
7850
7851
7852
7853<p>Keys provide a way to work with documents that contain an implicit
7854
7855cross-reference structure.  The <code>ID</code>, <code>IDREF</code>
7856
7857and <code>IDREFS</code> attribute types in XML provide a mechanism to
7858
7859allow XML documents to make their cross-reference explicit.  XSLT
7860
7861supports this through the XPath <xfunction>id</xfunction> function.
7862
7863However, this mechanism has a number of limitations:</p>
7864
7865
7866
7867<ulist>
7868
7869
7870
7871<item><p>ID attributes must be declared as such in the DTD.  If an ID
7872
7873attribute is declared as an ID attribute only in the external DTD
7874
7875subset, then it will be recognized as an ID attribute only if the XML
7876
7877processor reads the external DTD subset.  However, XML does not require
7878
7879XML processors to read the external DTD, and they may well choose not
7880
7881to do so, especially if the document is declared
7882
7883<code>standalone="yes"</code>.</p></item>
7884
7885
7886
7887<item><p>A document can contain only a single set of unique IDs.
7888
7889There cannot be separate independent sets of unique IDs.</p></item>
7890
7891
7892
7893<item><p>The ID of an element can only be specified in an attribute;
7894
7895it cannot be specified by the content of the element, or by a child
7896
7897element.</p></item>
7898
7899
7900
7901<item><p>An ID is constrained to be an XML name.  For example, it
7902
7903cannot contain spaces.</p></item>
7904
7905
7906
7907<item><p>An element can have at most one ID.</p></item>
7908
7909
7910
7911<item><p>At most one element can have a particular ID.</p></item>
7912
7913
7914
7915</ulist>
7916
7917
7918
7919<p>Because of these limitations XML documents sometimes contain a
7920
7921cross-reference structure that is not explicitly declared by
7922
7923ID/IDREF/IDREFS attributes.</p>
7924
7925
7926
7927<p>A key is a triple containing:</p>
7928
7929
7930
7931<olist>
7932
7933
7934
7935<item><p>the node which has the key</p></item>
7936
7937
7938
7939<item><p>the name of the key (an <xtermref
7940
7941href="&XPath;#dt-expanded-name">expanded-name</xtermref>)</p></item>
7942
7943
7944
7945<item><p>the value of the key (a string)</p></item>
7946
7947
7948
7949</olist>
7950
7951
7952
7953<p>A stylesheet declares a set of keys for each document using the
7954
7955<code>xsl:key</code> element.  When this set of keys contains a member
7956
7957with node <var>x</var>, name <var>y</var> and value
7958
7959<var>z</var>, we say that node <var>x</var> has a key with name
7960
7961<var>y</var> and value <var>z</var>.</p>
7962
7963
7964
7965<p>Thus, a key is a kind of generalized ID, which is not subject to the
7966
7967same limitations as an XML ID:</p>
7968
7969
7970
7971<ulist>
7972
7973
7974
7975<item><p>Keys are declared in the stylesheet using
7976
7977<code>xsl:key</code> elements.</p></item>
7978
7979
7980
7981<item><p>A key has a name as well as a value; each key name may be
7982
7983thought of as distinguishing a separate, independent space of
7984
7985identifiers.</p></item>
7986
7987
7988
7989<item><p>The value of a named key for an element may be specified in
7990
7991any convenient place; for example, in an attribute, in a child element
7992
7993or in content.  An XPath expression is used to specify where to find
7994
7995the value for a particular named key.</p></item>
7996
7997
7998
7999<item><p>The value of a key can be an arbitrary string; it is not
8000
8001constrained to be a name.</p></item>
8002
8003
8004
8005<item><p>There can be multiple keys in a document with the same node,
8006
8007same key name, but different key values.</p></item>
8008
8009
8010
8011<item><p>There can be multiple keys in a document with the same key
8012
8013name, same key value, but different nodes.</p></item>
8014
8015
8016
8017</ulist>
8018
8019
8020
8021<e:element-syntax name="key">
8022
8023  <e:in-category name="top-level-element"/>
8024
8025  <e:attribute name="name" required="yes">
8026
8027    <e:data-type name="qname"/>
8028
8029  </e:attribute>
8030
8031  <e:attribute name="match" required="yes">
8032
8033    <e:data-type name="pattern"/>
8034
8035  </e:attribute>
8036
8037  <e:attribute name="use" required="yes">
8038
8039    <e:data-type name="expression"/>
8040
8041  </e:attribute>
8042
8043  <e:empty/>
8044
8045</e:element-syntax>
8046
8047
8048
8049<p>The <code>xsl:key</code> element is used to declare keys.  The
8050
8051<code>name</code> attribute specifies the name of the key.  The value
8052
8053of the <code>name</code> attribute is a <xnt
8054
8055href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
8056
8057in <specref ref="qname"/>. The <code>match</code> attribute is a <nt
8058
8059def="NT-Pattern">Pattern</nt>; an <code>xsl:key</code> element gives
8060
8061information about the keys of any node that matches the pattern
8062
8063specified in the match attribute.  The <code>use</code> attribute is
8064
8065an <termref def="dt-expression">expression</termref> specifying the
8066
8067values of the key; the expression is evaluated once for each node that
8068
8069matches the pattern.  If the result is a node-set, then for each node
8070
8071in the node-set, the node that matches the pattern has a key of the
8072
8073specified name whose value is the string-value of the node in the
8074
8075node-set; otherwise, the result is converted to a string, and the node
8076
8077that matches the pattern has a key of the specified name with value
8078
8079equal to that string.  Thus, a node <var>x</var> has a key with name
8080
8081<var>y</var> and value <var>z</var> if and only if there is an
8082
8083<code>xsl:key</code> element such that:</p>
8084
8085
8086
8087<ulist>
8088
8089
8090
8091<item><p><var>x</var> matches the pattern specified in the
8092
8093<code>match</code> attribute of the <code>xsl:key</code> element;</p></item>
8094
8095
8096
8097<item><p>the value of the <code>name</code> attribute of the
8098
8099<code>xsl:key</code> element is equal to <var>y</var>;
8100
8101and</p></item>
8102
8103
8104
8105<item><p>when the expression specified in the <code>use</code>
8106
8107attribute of the <code>xsl:key</code> element is evaluated with
8108
8109<var>x</var> as the current node and with a node list containing
8110
8111just <var>x</var> as the current node list resulting in an object
8112
8113<var>u</var>, then either <var>z</var> is equal to the result of
8114
8115converting <var>u</var> to a string as if by a call to the
8116
8117<xfunction>string</xfunction> function, or <var>u</var> is a
8118
8119node-set and <var>z</var> is equal to the string-value of one or
8120
8121more of the nodes in <var>u</var>.</p></item>
8122
8123
8124
8125</ulist>
8126
8127
8128
8129<p>Note also that there may be more than one <code>xsl:key</code>
8130
8131element that matches a given node; all of the matching
8132
8133<code>xsl:key</code> elements are used, even if they do not have the
8134
8135same <termref def="dt-import-precedence">import
8136
8137precedence</termref>.</p>
8138
8139
8140
8141<p>It is an error for the value of either the <code>use</code>
8142
8143attribute or the <code>match</code> attribute to contain a <xnt
8144
8145href="&XPath;#NT-VariableReference">VariableReference</xnt>.</p>
8146
8147
8148
8149<proto name="key" return-type="node-set"><arg type="string"/><arg type="object"/></proto>
8150
8151
8152
8153<p>The <function>key</function> function does for keys what the
8154
8155<xfunction>id</xfunction> function does for IDs.  The first argument
8156
8157specifies the name of the key. The value of the argument must be a
8158
8159<xnt href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as
8160
8161described in <specref ref="qname"/>. When the second argument to the
8162
8163<function>key</function> function is of type node-set, then the result
8164
8165is the union of the result of applying the <function>key</function>
8166
8167function to the string <xtermref
8168
8169href="&XPath;#dt-value">value</xtermref> of each of the nodes in the
8170
8171argument node-set.  When the second argument to
8172
8173<function>key</function> is of any other type, the argument is
8174
8175converted to a string as if by a call to the
8176
8177<xfunction>string</xfunction> function; it returns a node-set
8178
8179containing the nodes in the same document as the context node that
8180
8181have a value for the named key equal to this string.</p>
8182
8183
8184
8185<p>For example, given a declaration</p>
8186
8187
8188
8189<eg><![CDATA[<xsl:key name="idkey" match="div" use="@id"/>]]></eg>
8190
8191
8192
8193<p>an expression <code>key("idkey",@ref)</code> will return the same
8194
8195node-set as <code>id(@ref)</code>, assuming that the only ID attribute
8196
8197declared in the XML source document is:</p>
8198
8199
8200
8201<eg><![CDATA[<!ATTLIST div id ID #IMPLIED>]]></eg>
8202
8203
8204
8205<p>and that the <code>ref</code> attribute of the current node
8206
8207contains no whitespace.</p>
8208
8209
8210
8211<p>Suppose a document describing a function library uses a
8212
8213<code>prototype</code> element to define functions</p>
8214
8215
8216
8217<eg><![CDATA[<prototype name="key" return-type="node-set">
8218
8219<arg type="string"/>
8220
8221<arg type="object"/>
8222
8223</prototype>]]></eg>
8224
8225
8226
8227<p>and a <code>function</code> element to refer to function names</p>
8228
8229
8230
8231<eg><![CDATA[<function>key</function>]]></eg>
8232
8233
8234
8235<p>Then the stylesheet could generate hyperlinks between the
8236
8237references and definitions as follows:</p>
8238
8239
8240
8241<eg><![CDATA[<xsl:key name="func" match="prototype" use="@name"/>
8242
8243
8244
8245<xsl:template match="function">
8246
8247<b>
8248
8249  <a href="#{generate-id(key('func',.))}">
8250
8251    <xsl:apply-templates/>
8252
8253  </a>
8254
8255</b>
8256
8257</xsl:template>
8258
8259
8260
8261<xsl:template match="prototype">
8262
8263<p><a name="{generate-id()}">
8264
8265<b>Function: </b>
8266
8267...
8268
8269</a></p>
8270
8271</xsl:template>]]></eg>
8272
8273
8274
8275<p>The <function>key</function> can be used to retrieve a key from a
8276
8277document other than the document containing the context node.  For
8278
8279example, suppose a document contains bibliographic references in the
8280
8281form <code><![CDATA[<bibref>XSLT</bibref>]]></code>, and there is a
8282
8283separate XML document <code>bib.xml</code> containing a bibliographic
8284
8285database with entries in the form:</p>
8286
8287
8288
8289<eg><![CDATA[<entry name="XSLT">...</entry>]]></eg>
8290
8291
8292
8293<p>Then the stylesheet could use the following to transform the
8294
8295<code>bibref</code> elements:</p>
8296
8297
8298
8299<eg><![CDATA[<xsl:key name="bib" match="entry" use="@name"/>
8300
8301
8302
8303<xsl:template match="bibref">
8304
8305  <xsl:variable name="name" select="."/>
8306
8307  <xsl:for-each select="document('bib.xml')">
8308
8309    <xsl:apply-templates select="key('bib',$name)"/>
8310
8311  </xsl:for-each>
8312
8313</xsl:template>]]></eg>
8314
8315
8316
8317</div2>
8318
8319
8320
8321<div2 id="format-number">
8322
8323<head>Number Formatting</head>
8324
8325
8326
8327<proto name="format-number" return-type="string"><arg type="number"/><arg type="string"/><arg occur="opt" type="string"/></proto>
8328
8329
8330
8331<p>The <function>format-number</function> function converts its first
8332
8333argument to a string using the format pattern string specified by the
8334
8335second argument and the decimal-format named by the third argument, or
8336
8337the default decimal-format, if there is no third argument.  The format
8338
8339pattern string is in the syntax specified by the JDK 1.1 <loc href=
8340
8341"http://java.sun.com/products/jdk/1.1/docs/api/java.text.DecimalFormat.html"
8342
8343>DecimalFormat</loc> class. The format pattern string is in a
8344
8345localized notation: the decimal-format determines what characters have
8346
8347a special meaning in the pattern (with the exception of the quote
8348
8349character, which is not localized).  The format pattern must not
8350
8351contain the currency sign (#x00A4); support for this feature was added
8352
8353after the initial release of JDK 1.1.  The decimal-format name must be
8354
8355a <xnt href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as
8356
8357described in <specref ref="qname"/>.  It is an error if the stylesheet
8358
8359does not contain a declaration of the decimal-format with the specified
8360
8361<xtermref href="&XPath;#dt-expanded-name">expanded-name</xtermref>.</p>
8362
8363
8364
8365<note><p>Implementations are not required to use the JDK 1.1
8366
8367implementation, nor are implementations required to be implemented in
8368
8369Java.</p></note>
8370
8371
8372
8373<note><p>Stylesheets can use other facilities in XPath to control
8374
8375rounding.</p></note>
8376
8377
8378
8379<e:element-syntax name="decimal-format">
8380
8381  <e:in-category name="top-level-element"/>
8382
8383
8384
8385  <e:attribute name="name">
8386
8387    <e:data-type name="qname"/>
8388
8389  </e:attribute>
8390
8391  <e:attribute name="decimal-separator">
8392
8393    <e:data-type name="char"/>
8394
8395  </e:attribute>
8396
8397  <e:attribute name="grouping-separator">
8398
8399    <e:data-type name="char"/>
8400
8401  </e:attribute>
8402
8403  <e:attribute name="infinity">
8404
8405    <e:data-type name="string"/>
8406
8407  </e:attribute>
8408
8409  <e:attribute name="minus-sign">
8410
8411    <e:data-type name="char"/>
8412
8413  </e:attribute>
8414
8415  <e:attribute name="NaN">
8416
8417    <e:data-type name="string"/>
8418
8419  </e:attribute>
8420
8421  <e:attribute name="percent">
8422
8423    <e:data-type name="char"/>
8424
8425  </e:attribute>
8426
8427  <e:attribute name="per-mille">
8428
8429    <e:data-type name="char"/>
8430
8431  </e:attribute>
8432
8433  <e:attribute name="zero-digit">
8434
8435    <e:data-type name="char"/>
8436
8437  </e:attribute>
8438
8439  <e:attribute name="digit">
8440
8441    <e:data-type name="char"/>
8442
8443  </e:attribute>
8444
8445  <e:attribute name="pattern-separator">
8446
8447    <e:data-type name="char"/>
8448
8449  </e:attribute>
8450
8451  <e:empty/>
8452
8453</e:element-syntax>
8454
8455
8456
8457<p>The <code>xsl:decimal-format</code> element declares a
8458
8459decimal-format, which controls the interpretation of a format pattern
8460
8461used by the <function>format-number</function> function.  If there is
8462
8463a <code>name</code> attribute, then the element declares a named
8464
8465decimal-format; otherwise, it declares the default decimal-format.
8466
8467The value of the <code>name</code> attribute is a <xnt
8468
8469href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
8470
8471in <specref ref="qname"/>.  It is an error to declare either the
8472
8473default decimal-format or a decimal-format with a given name more than
8474
8475once (even with different <termref def="dt-import-precedence">import
8476
8477precedence</termref>), unless it is declared every time with the same
8478
8479value for all attributes (taking into account any default values).</p>
8480
8481
8482
8483<p>The other attributes on <code>xsl:decimal-format</code> correspond
8484
8485to the methods on the JDK 1.1 <loc href=
8486
8487"http://java.sun.com/products/jdk/1.1/docs/api/java.text.DecimalFormatSymbols.html"
8488
8489>DecimalFormatSymbols</loc> class.  For each
8490
8491<code>get</code>/<code>set</code> method pair there is an attribute
8492
8493defined for the <code>xsl:decimal-format</code> element.</p>
8494
8495
8496
8497<p>The following attributes both control the interpretation of
8498
8499characters in the format pattern and specify characters that may
8500
8501appear in the result of formatting the number:</p>
8502
8503
8504
8505<ulist>
8506
8507
8508
8509<item><p><code>decimal-separator</code> specifies the character used
8510
8511for the decimal sign; the default value is the period character
8512
8513(<code>.</code>)</p></item>
8514
8515
8516
8517<item><p><code>grouping-separator</code> specifies the character used
8518
8519as a grouping (e.g. thousands) separator; the default value is the
8520
8521comma character (<code>,</code>)</p></item>
8522
8523
8524
8525<item><p><code>percent</code> specifies the character used as a
8526
8527percent sign; the default value is the percent character
8528
8529(<code>%</code>)</p></item>
8530
8531
8532
8533<item><p><code>per-mille</code> specifies the character used as a per
8534
8535mille sign; the default value is the Unicode per-mille character
8536
8537(#x2030)</p></item>
8538
8539
8540
8541<item><p><code>zero-digit</code> specifies the character used as the
8542
8543digit zero; the default value is the digit zero
8544
8545(<code>0</code>)</p></item>
8546
8547
8548
8549</ulist>
8550
8551
8552
8553<p>The following attributes control the interpretation of characters
8554
8555in the format pattern:</p>
8556
8557
8558
8559<ulist>
8560
8561
8562
8563<item><p><code>digit</code> specifies the character used for a digit
8564
8565in the format pattern; the default value is the number sign character
8566
8567(<code>#</code>)</p></item>
8568
8569
8570
8571<item><p><code>pattern-separator</code> specifies the character used
8572
8573to separate positive and negative sub patterns in a pattern; the
8574
8575default value is the semi-colon character (<code>;</code>)</p></item>
8576
8577
8578
8579</ulist>
8580
8581
8582
8583<p>The following attributes specify characters or strings that may
8584
8585appear in the result of formatting the number:</p>
8586
8587
8588
8589<ulist>
8590
8591
8592
8593<item><p><code>infinity</code> specifies the string used to represent
8594
8595infinity; the default value is the string
8596
8597<code>Infinity</code></p></item>
8598
8599
8600
8601<item><p><code>NaN</code> specifies the string used to represent the
8602
8603NaN value; the default value is the string <code>NaN</code></p></item>
8604
8605
8606
8607<item><p><code>minus-sign</code> specifies the character used as the
8608
8609default minus sign; the default value is the hyphen-minus character
8610
8611(<code>-</code>, #x2D)</p></item>
8612
8613
8614
8615</ulist>
8616
8617
8618
8619</div2>
8620
8621
8622
8623<div2 id="misc-func">
8624
8625<head>Miscellaneous Additional Functions</head>
8626
8627
8628
8629<proto name="current" return-type="node-set"></proto>
8630
8631
8632
8633<p>The <function>current</function> function returns a node-set that
8634
8635has the <termref def="dt-current-node">current node</termref> as its
8636
8637only member.  For an outermost expression (an expression not occurring
8638
8639within another expression), the current node is always the same as the
8640
8641context node.  Thus,</p>
8642
8643
8644
8645<eg><![CDATA[<xsl:value-of select="current()"/>]]></eg>
8646
8647
8648
8649<p>means the same as</p>
8650
8651
8652
8653<eg><![CDATA[<xsl:value-of select="."/>]]></eg>
8654
8655
8656
8657<p>However, within square brackets the current node is usually
8658
8659different from the context node. For example,</p>
8660
8661
8662
8663<eg><![CDATA[<xsl:apply-templates select="//glossary/item[@name=current()/@ref]"/>]]></eg>
8664
8665
8666
8667<p>will process all <code>item</code> elements that have a
8668
8669<code>glossary</code> parent element and that have a <code>name</code>
8670
8671attribute with value equal to the value of the current node's
8672
8673<code>ref</code> attribute. This is different from</p>
8674
8675
8676
8677<eg><![CDATA[<xsl:apply-templates select="//glossary/item[@name=./@ref]"/>]]></eg>
8678
8679
8680
8681<p>which means the same as</p>
8682
8683
8684
8685<eg><![CDATA[<xsl:apply-templates select="//glossary/item[@name=@ref]"/>]]></eg>
8686
8687
8688
8689<p>and so would process all <code>item</code> elements that have a
8690
8691<code>glossary</code> parent element and that have a <code>name</code>
8692
8693attribute and a <code>ref</code> attribute with the same value.</p>
8694
8695
8696
8697<p>It is an error to use the <function>current</function> function in
8698
8699a <termref def="dt-pattern">pattern</termref>.</p>
8700
8701
8702
8703<proto name="unparsed-entity-uri" return-type="string"><arg type="string"/></proto>
8704
8705
8706
8707<p>The <function>unparsed-entity-uri</function> returns the URI of the
8708
8709unparsed entity with the specified name in the same document as the
8710
8711context node (see <specref ref="unparsed-entities"/>).  It returns the
8712
8713empty string if there is no such entity.</p>
8714
8715
8716
8717<proto name="generate-id" return-type="string"><arg occur="opt" type="node-set"/></proto>
8718
8719
8720
8721<p>The <function>generate-id</function> function returns a string that
8722
8723uniquely identifies the node in the argument node-set that is first in
8724
8725document order.  The unique identifier must consist of ASCII
8726
8727alphanumeric characters and must start with an alphabetic character.
8728
8729Thus, the string is syntactically an XML name.  An implementation is
8730
8731free to generate an identifier in any convenient way provided that it
8732
8733always generates the same identifier for the same node and that
8734
8735different identifiers are always generated from different nodes. An
8736
8737implementation is under no obligation to generate the same identifiers
8738
8739each time a document is transformed.  There is no guarantee that a
8740
8741generated unique identifier will be distinct from any unique IDs
8742
8743specified in the source document.  If the argument node-set is empty,
8744
8745the empty string is returned. If the argument is omitted, it defaults
8746
8747to the context node.</p>
8748
8749
8750
8751<proto name="system-property" return-type="object"><arg type="string"/></proto>
8752
8753
8754
8755<p>The argument must evaluate to a string that is a <xnt
8756
8757href="&XMLNames;#NT-QName">QName</xnt>.  The <xnt
8758
8759href="&XMLNames;#NT-QName">QName</xnt> is expanded into a name using
8760
8761the namespace declarations in scope for the expression. The
8762
8763<function>system-property</function> function returns an object
8764
8765representing the value of the system property identified by the name.
8766
8767If there is no such system property, the empty string should be
8768
8769returned.</p>
8770
8771
8772
8773<p>Implementations must provide the following system properties, which
8774
8775are all in the XSLT namespace:</p>
8776
8777
8778
8779<slist>
8780
8781
8782
8783<sitem><code>xsl:version</code>, a number giving the version of XSLT
8784
8785implemented by the processor; for XSLT processors implementing the
8786
8787version of XSLT specified by this document, this is the number
8788
87891.0</sitem>
8790
8791
8792
8793<sitem><code>xsl:vendor</code>, a string identifying the vendor of the
8794
8795XSLT processor</sitem>
8796
8797
8798
8799<sitem><code>xsl:vendor-url</code>, a string containing a URL
8800
8801identifying the vendor of the XSLT processor; typically this is the
8802
8803host page (home page) of the vendor's Web site.</sitem>
8804
8805
8806
8807</slist>
8808
8809
8810
8811</div2>
8812
8813
8814
8815</div1>
8816
8817
8818
8819<div1 id="message">
8820
8821<head>Messages</head>
8822
8823
8824
8825<e:element-syntax name="message">
8826
8827  <e:in-category name="instruction"/>
8828
8829  <e:attribute name="terminate">
8830
8831    <e:constant value="yes"/>
8832
8833    <e:constant value="no"/>
8834
8835  </e:attribute>
8836
8837  <e:model name="template"/>
8838
8839</e:element-syntax>
8840
8841
8842
8843<p>The <code>xsl:message</code> instruction sends a message in a way
8844
8845that is dependent on the XSLT processor.  The content of the
8846
8847<code>xsl:message</code> instruction is a template.  The
8848
8849<code>xsl:message</code> is instantiated by instantiating the content
8850
8851to create an XML fragment.  This XML fragment is the content of the
8852
8853message.</p>
8854
8855
8856
8857<note><p>An XSLT processor might implement <code>xsl:message</code> by
8858
8859popping up an alert box or by writing to a log file.</p></note>
8860
8861
8862
8863<p>If the <code>terminate</code> attribute has the value
8864
8865<code>yes</code>, then the XSLT processor should terminate processing
8866
8867after sending the message.  The default value is <code>no</code>.</p>
8868
8869
8870
8871<p>One convenient way to do localization is to put the localized
8872
8873information (message text, etc.) in an XML document, which becomes an
8874
8875additional input file to the stylesheet.  For example, suppose
8876
8877messages for a language <code><var>L</var></code> are stored in an XML
8878
8879file <code>resources/<var>L</var>.xml</code> in the form:</p>
8880
8881
8882
8883<eg><![CDATA[<messages>
8884
8885  <message name="problem">A problem was detected.</message>
8886
8887  <message name="error">An error was detected.</message>
8888
8889</messages>
8890
8891]]></eg>
8892
8893
8894
8895<p>Then a stylesheet could use the following approach to localize
8896
8897messages:</p>
8898
8899
8900
8901<eg><![CDATA[<xsl:param name="lang" select="en"/>
8902
8903<xsl:variable name="messages"
8904
8905  select="document(concat('resources/', $lang, '.xml'))/messages"/>
8906
8907
8908
8909<xsl:template name="localized-message">
8910
8911  <xsl:param name="name"/>
8912
8913  <xsl:message>
8914
8915    <xsl:value-of select="$messages/message[@name=$name]"/>
8916
8917  </xsl:message>
8918
8919</xsl:template>
8920
8921
8922
8923<xsl:template name="problem">
8924
8925  <xsl:call-template name="localized-message"/>
8926
8927    <xsl:with-param name="name">problem</xsl:with-param>
8928
8929  </xsl:call-template>
8930
8931</xsl:template>]]></eg>
8932
8933
8934
8935</div1>
8936
8937
8938
8939<div1 id="extension">
8940
8941<head>Extensions</head>
8942
8943
8944
8945<p>XSLT allows two kinds of extension, extension elements and
8946
8947extension functions.</p>
8948
8949
8950
8951<p>This version of XSLT does not provide a mechanism for defining
8952
8953implementations of extensions.  Therefore, an XSLT stylesheet that must
8954
8955be portable between XSLT implementations cannot rely on particular
8956
8957extensions being available.  XSLT provides mechanisms that allow an
8958
8959XSLT stylesheet to determine whether the XSLT processor by which it is
8960
8961being processed has implementations of particular extensions
8962
8963available, and to specify what should happen if those extensions are
8964
8965not available.  If an XSLT stylesheet is careful to make use of these
8966
8967mechanisms, it is possible for it to take advantage of extensions and
8968
8969still work with any XSLT implementation.</p>
8970
8971
8972
8973<div2 id="extension-element">
8974
8975<head>Extension Elements</head>
8976
8977
8978
8979<p><termdef id="dt-extension-namespace" term="Extension Namespace">The
8980
8981element extension mechanism allows namespaces to be designated as
8982
8983<term>extension namespace</term>s. When a namespace is designated as
8984
8985an extension namespace and an element with a name from that namespace
8986
8987occurs in a template, then the element is treated as an instruction
8988
8989rather than as a literal result element.</termdef> The namespace
8990
8991determines the semantics of the instruction.</p>
8992
8993
8994
8995<note><p>Since an element that is a child of an
8996
8997<code>xsl:stylesheet</code> element is not occurring <emph>in a
8998
8999template</emph>, non-XSLT <termref
9000
9001def="dt-top-level">top-level</termref> elements are not extension
9002
9003elements as defined here, and nothing in this section applies to
9004
9005them.</p></note>
9006
9007
9008
9009<p>A namespace is designated as an extension namespace by using an
9010
9011<code>extension-element-prefixes</code> attribute on an
9012
9013<code>xsl:stylesheet</code> element or an
9014
9015<code>xsl:extension-element-prefixes</code> attribute on a literal
9016
9017result element or extension element.
9018
9019The value of both these attributes is a
9020
9021whitespace-separated list of namespace prefixes. The namespace bound
9022
9023to each of the prefixes is designated as an extension namespace.  It
9024
9025is an error if there is no namespace bound to the prefix on the
9026
9027element bearing the <code>extension-element-prefixes</code> or
9028
9029<code>xsl:extension-element-prefixes</code> attribute.  The default
9030
9031namespace (as declared by <code>xmlns</code>) may be designated as an
9032
9033extension namespace by including <code>#default</code> in the list of
9034
9035namespace prefixes.  The designation of a namespace as an extension
9036
9037namespace is effective within the subtree of the stylesheet rooted at
9038
9039the element bearing the <code>extension-element-prefixes</code> or
9040
9041<code>xsl:extension-element-prefixes</code> attribute;
9042
9043a subtree rooted at an <code>xsl:stylesheet</code> element
9044
9045does not include any stylesheets imported or included by children
9046
9047of that <code>xsl:stylesheet</code> element.</p>
9048
9049
9050
9051<p>If the XSLT processor does not have an implementation of a
9052
9053particular extension element available, then the
9054
9055<function>element-available</function> function must return false for
9056
9057the name of the element.  When such an extension element is
9058
9059instantiated, then the XSLT processor must perform fallback for the
9060
9061element as specified in <specref ref="fallback"/>.  An XSLT processor
9062
9063must not signal an error merely because a template contains an
9064
9065extension element for which no implementation is available.</p>
9066
9067
9068
9069<p>If the XSLT processor has an implementation of a particular
9070
9071extension element available, then the
9072
9073<function>element-available</function> function must return true for
9074
9075the name of the element.</p>
9076
9077
9078
9079</div2>
9080
9081
9082
9083<div2>
9084
9085<head>Extension Functions</head>
9086
9087
9088
9089<p>If a <xnt href="&XPath;#NT-FunctionName">FunctionName</xnt> in a
9090
9091<xnt href="&XPath;#NT-FunctionCall">FunctionCall</xnt> expression is
9092
9093not an <xnt href="&XMLNames;#NT-NCName">NCName</xnt> (i.e. if it
9094
9095contains a colon), then it is treated as a call to an extension
9096
9097function.  The <xnt href="&XPath;#NT-FunctionName">FunctionName</xnt>
9098
9099is expanded to a name using the namespace declarations from the
9100
9101evaluation context.</p>
9102
9103
9104
9105<p>If the XSLT processor does not have an implementation of an
9106
9107extension function of a particular name available, then the
9108
9109<function>function-available</function> function must return false for
9110
9111that name.  If such an extension function occurs in an expression and
9112
9113the extension function is actually called, the XSLT processor must
9114
9115signal an error.  An XSLT processor must not signal an error merely
9116
9117because an expression contains an extension function for which no
9118
9119implementation is available.</p>
9120
9121
9122
9123<p>If the XSLT processor has an implementation of an extension
9124
9125function of a particular name available, then the
9126
9127<function>function-available</function> function must return
9128
9129true for that name. If such an extension is called, then the XSLT
9130
9131processor must call the implementation passing it the function call
9132
9133arguments; the result returned by the implementation is returned as
9134
9135the result of the function call.</p>
9136
9137
9138
9139</div2>
9140
9141
9142
9143</div1>
9144
9145
9146
9147<div1 id="fallback">
9148
9149<head>Fallback</head>
9150
9151
9152
9153<e:element-syntax name="fallback">
9154
9155  <e:in-category name="instruction"/>
9156
9157  <e:model name="template"/>
9158
9159</e:element-syntax>
9160
9161
9162
9163<p>Normally, instantiating an <code>xsl:fallback</code> element does
9164
9165nothing.  However, when an XSLT processor performs fallback for an
9166
9167instruction element, if the instruction element has one or more
9168
9169<code>xsl:fallback</code> children, then the content of each of the
9170
9171<code>xsl:fallback</code> children must be instantiated in sequence;
9172
9173otherwise, an error must be signaled. The content of an
9174
9175<code>xsl:fallback</code> element is a template.</p>
9176
9177
9178
9179<p>The following functions can be used with the
9180
9181<code>xsl:choose</code> and <code>xsl:if</code> instructions to
9182
9183explicitly control how a stylesheet should behave if particular
9184
9185elements or functions are not available.</p>
9186
9187
9188
9189<proto name="element-available" return-type="boolean"><arg
9190
9191type="string"/></proto>
9192
9193
9194
9195<p>The argument must evaluate to a string that is a <xnt
9196
9197href="&XMLNames;#NT-QName">QName</xnt>.  The <xnt
9198
9199href="&XMLNames;#NT-QName">QName</xnt> is expanded into an <xtermref
9200
9201href="&XPath;#dt-expanded-name">expanded-name</xtermref> using the
9202
9203namespace declarations in scope for the expression. The
9204
9205<function>element-available</function> function returns true if and
9206
9207only if the expanded-name is the name of an instruction.  If the
9208
9209expanded-name has a namespace URI equal to the XSLT namespace URI,
9210
9211then it refers to an element defined by XSLT.  Otherwise, it refers to
9212
9213an extension element. If the expanded-name has a null namespace URI,
9214
9215the <function>element-available</function> function will return
9216
9217false.</p>
9218
9219
9220
9221<proto name="function-available" return-type="boolean"><arg
9222
9223type="string"/></proto>
9224
9225
9226
9227<p>The argument must evaluate to a string that is a <xnt
9228
9229href="&XMLNames;#NT-QName">QName</xnt>.  The <xnt
9230
9231href="&XMLNames;#NT-QName">QName</xnt> is expanded into an <xtermref
9232
9233href="&XPath;#dt-expanded-name">expanded-name</xtermref> using the
9234
9235namespace declarations in scope for the expression. The
9236
9237<function>function-available</function> function returns true if and
9238
9239only if the expanded-name is the name of a function in the function
9240
9241library. If the expanded-name has a non-null namespace URI, then it
9242
9243refers to an extension function; otherwise, it refers to a function
9244
9245defined by XPath or XSLT.</p>
9246
9247
9248
9249</div1>
9250
9251
9252
9253<div1 id="output">
9254
9255<head>Output</head>
9256
9257
9258
9259<e:element-syntax name="output">
9260
9261  <e:in-category name="top-level-element"/>
9262
9263  <e:attribute name="method">
9264
9265    <e:constant value="xml"/>
9266
9267    <e:constant value="html"/>
9268
9269    <e:constant value="text"/>
9270
9271    <e:data-type name="qname-but-not-ncname"/>
9272
9273  </e:attribute>
9274
9275  <e:attribute name="version">
9276
9277    <e:data-type name="nmtoken"/>
9278
9279  </e:attribute>
9280
9281  <e:attribute name="encoding">
9282
9283    <e:data-type name="string"/>
9284
9285  </e:attribute>
9286
9287  <e:attribute name="omit-xml-declaration">
9288
9289    <e:constant value="yes"/>
9290
9291    <e:constant value="no"/>
9292
9293  </e:attribute>
9294
9295  <e:attribute name="standalone">
9296
9297    <e:constant value="yes"/>
9298
9299    <e:constant value="no"/>
9300
9301  </e:attribute>
9302
9303  <e:attribute name="doctype-public">
9304
9305    <e:data-type name="string"/>
9306
9307  </e:attribute>
9308
9309  <e:attribute name="doctype-system">
9310
9311    <e:data-type name="string"/>
9312
9313  </e:attribute>
9314
9315  <e:attribute name="cdata-section-elements">
9316
9317    <e:data-type name="qnames"/>
9318
9319  </e:attribute>
9320
9321  <e:attribute name="indent">
9322
9323    <e:constant value="yes"/>
9324
9325    <e:constant value="no"/>
9326
9327  </e:attribute>
9328
9329  <e:attribute name="media-type">
9330
9331    <e:data-type name="string"/>
9332
9333  </e:attribute>
9334
9335  <e:empty/>
9336
9337</e:element-syntax>
9338
9339
9340
9341<p>An XSLT processor may output the result tree as a sequence of
9342
9343bytes, although it is not required to be able to do so (see <specref
9344
9345ref="conformance"/>). The <code>xsl:output</code> element allows
9346
9347stylesheet authors to specify how they wish the result tree to be
9348
9349output. If an XSLT processor outputs the result tree, it should do so
9350
9351as specified by the <code>xsl:output</code> element; however, it is
9352
9353not required to do so.</p>
9354
9355
9356
9357<p>The <code>xsl:output</code> element is only allowed as a <termref
9358
9359def="dt-top-level">top-level</termref> element.</p>
9360
9361
9362
9363<p>The <code>method</code> attribute on <code>xsl:output</code>
9364
9365identifies the overall method that should be used for outputting the
9366
9367result tree.  The value must be a <xnt
9368
9369href="&XMLNames;#NT-QName">QName</xnt>.  If the <xnt
9370
9371href="&XMLNames;#NT-QName">QName</xnt> does not have a prefix, then it
9372
9373identifies a method specified in this document and must be one of
9374
9375<code>xml</code>, <code>html</code> or <code>text</code>.  If the <xnt
9376
9377href="&XMLNames;#NT-QName">QName</xnt> has a prefix, then the <xnt
9378
9379href="&XMLNames;#NT-QName">QName</xnt> is expanded into an <xtermref
9380
9381href="&XPath;#dt-expanded-name">expanded-name</xtermref> as described
9382
9383in <specref ref="qname"/>; the expanded-name identifies the output
9384
9385method; the behavior in this case is not specified by this
9386
9387document.</p>
9388
9389
9390
9391<p>The default for the <code>method</code> attribute is chosen as
9392
9393follows.  If</p>
9394
9395
9396
9397<ulist>
9398
9399
9400
9401<item><p>the root node of the result tree has an element
9402
9403child,</p></item>
9404
9405
9406
9407<item><p>the expanded-name of the first element child of the root node
9408
9409(i.e. the document element) of the result tree has local part
9410
9411<code>html</code> (in any combination of upper and lower case) and a
9412
9413null namespace URI, and</p></item>
9414
9415
9416
9417<item><p>any text nodes preceding the first element child of the root
9418
9419node of the result tree contain only whitespace characters,</p></item>
9420
9421
9422
9423</ulist>
9424
9425
9426
9427<p>then the default output method is <code>html</code>; otherwise, the
9428
9429default output method is <code>xml</code>.  The default output method
9430
9431should be used if there are no <code>xsl:output</code> elements or if
9432
9433none of the <code>xsl:output</code> elements specifies a value for the
9434
9435<code>method</code> attribute.</p>
9436
9437
9438
9439<p>The other attributes on <code>xsl:output</code> provide parameters
9440
9441for the output method.  The following attributes are allowed:</p>
9442
9443
9444
9445<ulist>
9446
9447
9448
9449<item><p><code>version</code> specifies the version of the output
9450
9451method</p></item>
9452
9453
9454
9455<item><p><code>indent</code> specifies whether the XSLT processor may
9456
9457add additional whitespace when outputting the result tree; the value
9458
9459must be <code>yes</code> or <code>no</code></p></item>
9460
9461
9462
9463<item><p><code>encoding</code> specifies the preferred character
9464
9465encoding that the XSLT processor should use to encode sequences of
9466
9467characters as sequences of bytes; the value of the attribute should be
9468
9469treated case-insensitively; the value must contain only characters in
9470
9471the range #x21 to #x7E (i.e. printable ASCII characters); the value
9472
9473should either be a <code>charset</code> registered with the Internet
9474
9475Assigned Numbers Authority <bibref ref="IANA"/>, <bibref
9476
9477ref="RFC2278"/> or start with <code>X-</code></p></item>
9478
9479
9480
9481<item><p><code>media-type</code> specifies the media type (MIME
9482
9483content type) of the data that results from outputting the result
9484
9485tree; the <code>charset</code> parameter should not be specified
9486
9487explicitly; instead, when the top-level media type is
9488
9489<code>text</code>, a <code>charset</code> parameter should be added
9490
9491according to the character encoding actually used by the output
9492
9493method</p></item>
9494
9495
9496
9497<item><p><code>doctype-system</code> specifies the system identifier
9498
9499to be used in the document type declaration</p></item>
9500
9501
9502
9503<item><p><code>doctype-public</code> specifies the public identifier
9504
9505to be used in the document type declaration</p></item>
9506
9507
9508
9509<item><p><code>omit-xml-declaration</code> specifies whether the XSLT
9510
9511processor should output an XML declaration; the value must be
9512
9513<code>yes</code> or <code>no</code></p></item>
9514
9515
9516
9517<item><p><code>standalone</code> specifies whether the XSLT processor
9518
9519should output a standalone document declaration; the value must be
9520
9521<code>yes</code> or <code>no</code></p></item>
9522
9523
9524
9525<item><p><code>cdata-section-elements</code> specifies a list of the
9526
9527names of elements whose text node children should be output using
9528
9529CDATA sections</p></item>
9530
9531
9532
9533</ulist>
9534
9535
9536
9537<p>The detailed semantics of each attribute will be described
9538
9539separately for each output method for which it is applicable.  If the
9540
9541semantics of an attribute are not described for an output method, then
9542
9543it is not applicable to that output method.</p>
9544
9545
9546
9547<p>A stylesheet may contain multiple <code>xsl:output</code> elements
9548
9549and may include or import stylesheets that also contain
9550
9551<code>xsl:output</code> elements.  All the <code>xsl:output</code>
9552
9553elements occurring in a stylesheet are merged into a single effective
9554
9555<code>xsl:output</code> element. For the
9556
9557<code>cdata-section-elements</code> attribute, the effective value is
9558
9559the union of the specified values.  For other attributes, the
9560
9561effective value is the specified value with the highest <termref
9562
9563def="dt-import-precedence">import precedence</termref>. It is an error
9564
9565if there is more than one such value for an attribute.  An XSLT
9566
9567processor may signal the error; if it does not signal the error, if
9568
9569should recover by using the value that occurs last in the stylesheet.
9570
9571The values of attributes are defaulted after the
9572
9573<code>xsl:output</code> elements have been merged; different output
9574
9575methods may have different default values for an attribute.</p>
9576
9577
9578
9579<div2>
9580
9581<head>XML Output Method</head>
9582
9583
9584
9585<p>The <code>xml</code> output method outputs the result tree as a
9586
9587well-formed XML external general parsed entity. If the root node of
9588
9589the result tree has a single element node child and no text node
9590
9591children, then the entity should also be a well-formed XML document
9592
9593entity. When the entity is referenced within a trivial XML document
9594
9595wrapper like this</p>
9596
9597
9598
9599<eg><![CDATA[
9600
9601<!DOCTYPE doc [
9602
9603<!ENTITY e SYSTEM "]]><var>entity-URI</var><![CDATA[">
9604
9605]>
9606
9607<doc>&e;</doc>]]></eg>
9608
9609
9610
9611<p>where <code><var>entity-URI</var></code> is a URI for the entity,
9612
9613then the wrapper
9614
9615document as a whole should be a well-formed XML document conforming to
9616
9617the XML Namespaces Recommendation <bibref ref="XMLNAMES"/>.  In
9618
9619addition, the output should be such that if a new tree was constructed
9620
9621by parsing the wrapper as an XML document as specified in <specref
9622
9623ref="data-model"/>, and then removing the document element, making its
9624
9625children instead be children of the root node, then the new tree would
9626
9627be the same as the result tree, with the following possible
9628
9629exceptions:</p>
9630
9631
9632
9633<ulist>
9634
9635
9636
9637<item><p>The order of attributes in the two trees may be
9638
9639different.</p></item>
9640
9641
9642
9643<item><p>The new tree may contain namespace nodes that were not
9644
9645present in the result tree.</p>
9646
9647<note><p>An XSLT processor may need to add
9648
9649namespace declarations in the course of outputting the result tree as
9650
9651XML.</p></note>
9652
9653</item>
9654
9655
9656
9657</ulist>
9658
9659
9660
9661<p>If the XSLT processor generated a document type declaration because
9662
9663of the <code>doctype-system</code> attribute, then the above
9664
9665requirements apply to the entity with the generated document type
9666
9667declaration removed.</p>
9668
9669
9670
9671<p>The <code>version</code> attribute specifies the version of XML to
9672
9673be used for outputting the result tree.  If the XSLT processor does
9674
9675not support this version of XML, it should use a version of XML that
9676
9677it does support.  The version output in the XML declaration (if an XML
9678
9679declaration is output) should correspond to the version of XML that
9680
9681the processor used for outputting the result tree. The value of the
9682
9683<code>version</code> attribute should match the <xnt
9684
9685href="&XML;#NT-VersionNum">VersionNum</xnt> production of the XML
9686
9687Recommendation <bibref ref="XML"/>. The default value is
9688
9689<code>1.0</code>.</p>
9690
9691
9692
9693<p>The <code>encoding</code> attribute specifies the preferred
9694
9695encoding to use for outputting the result tree.  XSLT processors are
9696
9697required to respect values of <code>UTF-8</code> and
9698
9699<code>UTF-16</code>.  For other values, if the XSLT processor does not
9700
9701support the specified encoding it may signal an error; if it does not
9702
9703signal an error it should use <code>UTF-8</code> or
9704
9705<code>UTF-16</code> instead.  The XSLT processor must not use an
9706
9707encoding whose name does not match the <xnt
9708
9709href="&XML;#NT-EncName">EncName</xnt> production of the XML
9710
9711Recommendation <bibref ref="XML"/>.  If no <code>encoding</code>
9712
9713attribute is specified, then the XSLT processor should use either
9714
9715<code>UTF-8</code> or <code>UTF-16</code>.  It is possible that the
9716
9717result tree will contain a character that cannot be represented in the
9718
9719encoding that the XSLT processor is using for output.  In this case,
9720
9721if the character occurs in a context where XML recognizes character
9722
9723references (i.e. in the value of an attribute node or text node), then
9724
9725the character should be output as a character reference; otherwise
9726
9727(for example if the character occurs in the name of an element) the
9728
9729XSLT processor should signal an error.</p>
9730
9731
9732
9733<p>If the <code>indent</code> attribute has the value
9734
9735<code>yes</code>, then the <code>xml</code> output method may output
9736
9737whitespace in addition to the whitespace in the result tree (possibly
9738
9739based on whitespace stripped from either the source document or the
9740
9741stylesheet) in order to indent the result nicely; if the
9742
9743<code>indent</code> attribute has the value <code>no</code>, it should
9744
9745not output any additional whitespace. The default value is
9746
9747<code>no</code>.  The <code>xml</code> output method should use an
9748
9749algorithm to output additional whitespace that ensures that the result
9750
9751if whitespace were to be stripped from the output using the process
9752
9753described in <specref ref="strip"/> with the set of
9754
9755whitespace-preserving elements consisting of just
9756
9757<code>xsl:text</code> would be the same when additional whitespace is
9758
9759output as when additional whitespace is not output.</p>
9760
9761
9762
9763<note><p>It is usually not safe to use <code>indent="yes"</code> with
9764
9765document types that include element types with mixed content.</p></note>
9766
9767
9768
9769<p>The <code>cdata-section-elements</code> attribute contains a
9770
9771whitespace-separated list of <xnt
9772
9773href="&XMLNames;#NT-QName">QName</xnt>s.  Each <xnt
9774
9775href="&XMLNames;#NT-QName">QName</xnt> is expanded into an
9776
9777expanded-name using the namespace declarations in effect on the
9778
9779<code>xsl:output</code> element in which the <xnt
9780
9781href="&XMLNames;#NT-QName">QName</xnt> occurs; if there is a default
9782
9783namespace, it is used for <xnt href="&XMLNames;#NT-QName">QName</xnt>s
9784
9785that do not have a prefix.  The expansion is performed before the
9786
9787merging of multiple <code>xsl:output</code> elements into a single
9788
9789effective <code>xsl:output</code> element. If the expanded-name of the
9790
9791parent of a text node is a member of the list, then the text node
9792
9793should be output as a CDATA section. For example,</p>
9794
9795
9796
9797<eg><![CDATA[<xsl:output cdata-section-elements="example"/>]]></eg>
9798
9799
9800
9801<p>would cause a literal result element written in the stylesheet as</p>
9802
9803
9804
9805<eg><![CDATA[<example>&lt;foo></example>]]></eg>
9806
9807
9808
9809<p>or as</p>
9810
9811
9812
9813<eg>&lt;example>&lt;![CDATA[&lt;foo>]]&gt;&lt;/example></eg>
9814
9815
9816
9817<p>to be output as</p>
9818
9819
9820
9821<eg>&lt;example>&lt;![CDATA[&lt;foo>]]&gt;&lt;/example></eg>
9822
9823
9824
9825<p>If the text node contains the sequence of characters
9826
9827<code>]]&gt;</code>, then the currently open CDATA section should be
9828
9829closed following the <code>]]</code> and a new CDATA section opened
9830
9831before the <code>&gt;</code>. For example, a literal result element
9832
9833written in the stylesheet as</p>
9834
9835
9836
9837<eg>&lt;example&gt;]]&amp;gt;&lt;/example&gt;</eg>
9838
9839
9840
9841<p>would be output as</p>
9842
9843
9844
9845<eg>&lt;example&gt;&lt;![CDATA[]]]]&gt;&lt;![CDATA[&gt;]]&gt;&lt;/example&gt;</eg>
9846
9847
9848
9849<p>If the text node contains a character that is not representable in
9850
9851the character encoding being used to output the result tree, then the
9852
9853currently open CDATA section should be closed before the character,
9854
9855the character should be output using a character reference or entity
9856
9857reference, and a new CDATA section should be opened for any further
9858
9859characters in the text node.</p>
9860
9861
9862
9863<p>CDATA sections should not be used except for text nodes that the
9864
9865<code>cdata-section-elements</code> attribute explicitly specifies
9866
9867should be output using CDATA sections.</p>
9868
9869
9870
9871<p>The <code>xml</code> output method should output an XML declaration
9872
9873unless the <code>omit-xml-declaration</code> attribute has the value
9874
9875<code>yes</code>. The XML declaration should include both version
9876
9877information and an encoding declaration. If the
9878
9879<code>standalone</code> attribute is specified, it should include a
9880
9881standalone document declaration with the same value as the value as
9882
9883the value of the <code>standalone</code> attribute.  Otherwise, it
9884
9885should not include a standalone document declaration; this ensures
9886
9887that it is both a XML declaration (allowed at the beginning of a
9888
9889document entity) and a text declaration (allowed at the beginning of
9890
9891an external general parsed entity).</p>
9892
9893
9894
9895<p>If the <code>doctype-system</code> attribute is specified, the
9896
9897<code>xml</code> output method should output a document type
9898
9899declaration immediately before the first element.  The name following
9900
9901<code>&lt;!DOCTYPE</code> should be the name of the first element.  If
9902
9903<code>doctype-public</code> attribute is also specified, then the
9904
9905<code>xml</code> output method should output <code>PUBLIC</code>
9906
9907followed by the public identifier and then the system identifier;
9908
9909otherwise, it should output <code>SYSTEM</code> followed by the system
9910
9911identifier.  The internal subset should be empty.  The
9912
9913<code>doctype-public</code> attribute should be ignored unless the
9914
9915<code>doctype-system</code> attribute is specified.</p>
9916
9917
9918
9919<p>The <code>media-type</code> attribute is applicable for the
9920
9921<code>xml</code> output method.  The default value for the
9922
9923<code>media-type</code> attribute is <code>text/xml</code>.</p>
9924
9925
9926
9927</div2>
9928
9929
9930
9931<div2>
9932
9933<head>HTML Output Method</head>
9934
9935
9936
9937<p>The <code>html</code> output method outputs the result tree as
9938
9939HTML; for example,</p>
9940
9941
9942
9943<eg>&lt;xsl:stylesheet version="1.0"
9944
9945                xmlns:xsl="&XSLT.ns;"><![CDATA[
9946
9947
9948
9949<xsl:output method="html"/>
9950
9951
9952
9953<xsl:template match="/">
9954
9955  <html>
9956
9957   <xsl:apply-templates/>
9958
9959  </html>
9960
9961</xsl:template>
9962
9963
9964
9965...
9966
9967
9968
9969</xsl:stylesheet>]]></eg>
9970
9971
9972
9973<p>The <code>version</code> attribute indicates the version of the
9974
9975HTML.  The default value is <code>4.0</code>, which specifies that the
9976
9977result should be output as HTML conforming to the HTML 4.0
9978
9979Recommendation <bibref ref="HTML"/>.</p>
9980
9981
9982
9983<p>The <code>html</code> output method should not output an element
9984
9985differently from the <code>xml</code> output method unless the
9986
9987expanded-name of the element has a null namespace URI; an element
9988
9989whose expanded-name has a non-null namespace URI should be output as
9990
9991XML.  If the expanded-name of the element has a null namespace URI,
9992
9993but the local part of the expanded-name is not recognized as the name
9994
9995of an HTML element, the element should output in the same way as a
9996
9997non-empty, inline element such as <code>span</code>.</p>
9998
9999
10000
10001<p>The <code>html</code> output method should not output an end-tag
10002
10003for empty elements.  For HTML 4.0, the empty elements are
10004
10005<code>area</code>, <code>base</code>, <code>basefont</code>,
10006
10007<code>br</code>, <code>col</code>, <code>frame</code>,
10008
10009<code>hr</code>, <code>img</code>, <code>input</code>,
10010
10011<code>isindex</code>, <code>link</code>, <code>meta</code> and
10012
10013<code>param</code>. For example, an element written as
10014
10015<code>&lt;br/></code> or <code>&lt;br>&lt;/br></code> in the
10016
10017stylesheet should be output as <code>&lt;br></code>.</p>
10018
10019
10020
10021<p>The <code>html</code> output method should recognize the names of
10022
10023HTML elements regardless of case.  For example, elements named
10024
10025<code>br</code>, <code>BR</code> or <code>Br</code> should all be
10026
10027recognized as the HTML <code>br</code> element and output without an
10028
10029end-tag.</p>
10030
10031
10032
10033<p>The <code>html</code> output method should not perform escaping for
10034
10035the content of the <code>script</code> and <code>style</code>
10036
10037elements. For example, a literal result element written in the
10038
10039stylesheet as</p>
10040
10041
10042
10043<eg><![CDATA[<script>if (a &lt; b) foo()</script>]]></eg>
10044
10045
10046
10047<p>or</p>
10048
10049
10050
10051<eg><![CDATA[<script><![CDATA[if (a < b) foo()]]]]><![CDATA[></script>]]></eg>
10052
10053
10054
10055<p>should be output as</p>
10056
10057
10058
10059<eg><![CDATA[<script>if (a < b) foo()</script>]]></eg>
10060
10061
10062
10063<p>The <code>html</code> output method should not escape
10064
10065<code>&lt;</code> characters occurring in attribute values.</p>
10066
10067
10068
10069<p>If the <code>indent</code> attribute has the value
10070
10071<code>yes</code>, then the <code>html</code> output method may add or
10072
10073remove whitespace as it outputs the result tree, so long as it does
10074
10075not change how an HTML user agent would render the output.  The
10076
10077default value is <code>yes</code>.</p>
10078
10079
10080
10081<p>The <code>html</code> output method should escape non-ASCII
10082
10083characters in URI attribute values using the method recommended in
10084
10085<loc
10086
10087href="http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.2.1">Section
10088
10089B.2.1</loc> of the HTML 4.0 Recommendation.</p>
10090
10091
10092
10093<p>The <code>html</code> output method may output a character using a
10094
10095character entity reference, if one is defined for it in the version of
10096
10097HTML that the output method is using.</p>
10098
10099
10100
10101<p>The <code>html</code> output method should terminate processing
10102
10103instructions with <code>&gt;</code> rather than
10104
10105<code>?&gt;</code>.</p>
10106
10107
10108
10109<p>The <code>html</code> output method should output boolean
10110
10111attributes (that is attributes with only a single allowed value that
10112
10113is equal to the name of the attribute) in minimized form. For example,
10114
10115a start-tag written in the stylesheet as</p>
10116
10117
10118
10119<eg><![CDATA[<OPTION selected="selected">]]></eg>
10120
10121
10122
10123<p>should be output as</p>
10124
10125
10126
10127<eg><![CDATA[<OPTION selected>]]></eg>
10128
10129
10130
10131<p>The <code>html</code> output method should not escape a
10132
10133<code>&amp;</code> character occurring in an attribute value
10134
10135immediately followed by a <code>{</code> character (see <loc
10136
10137href="http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.7.1.1">Section
10138
10139B.7.1</loc> of the HTML 4.0 Recommendation). For example, a start-tag
10140
10141written in the stylesheet as</p>
10142
10143
10144
10145<eg><![CDATA[<BODY bgcolor='&amp;{{randomrbg}};'>]]></eg>
10146
10147
10148
10149<p>should be output as</p>
10150
10151
10152
10153<eg><![CDATA[<BODY bgcolor='&{randomrbg};'>]]></eg>
10154
10155
10156
10157<p>The <code>encoding</code> attribute specifies the preferred
10158
10159encoding to be used. If there is a <code>HEAD</code> element, then the
10160
10161<code>html</code> output method should add a <code>META</code> element
10162
10163immediately after the start-tag of the <code>HEAD</code> element
10164
10165specifying the character encoding actually used. For example,</p>
10166
10167
10168
10169<eg><![CDATA[<HEAD>
10170
10171<META http-equiv="Content-Type" content="text/html; charset=EUC-JP">
10172
10173...]]></eg>
10174
10175
10176
10177<p>It is possible that the result tree will contain a character that
10178
10179cannot be represented in the encoding that the XSLT processor is using
10180
10181for output.  In this case, if the character occurs in a context where
10182
10183HTML recognizes character references, then the character should be
10184
10185output as a character entity reference or decimal numeric character
10186
10187reference; otherwise (for example, in a
10188
10189<code>script</code> or <code>style</code> element or in a comment),
10190
10191the XSLT processor should signal an error.</p>
10192
10193
10194
10195<p>If the <code>doctype-public</code> or <code>doctype-system</code>
10196
10197attributes are specified, then the <code>html</code> output method
10198
10199should output a document type declaration immediately before the first
10200
10201element.  The name following <code>&lt;!DOCTYPE</code> should be
10202
10203<code>HTML</code> or <code>html</code>.  If the
10204
10205<code>doctype-public</code> attribute is specified, then the output
10206
10207method should output <code>PUBLIC</code> followed by the specified
10208
10209public identifier; if the <code>doctype-system</code> attribute is
10210
10211also specified, it should also output the specified system identifier
10212
10213following the public identifier.  If the <code>doctype-system</code>
10214
10215attribute is specified but the <code>doctype-public</code> attribute
10216
10217is not specified, then the output method should output
10218
10219<code>SYSTEM</code> followed by the specified system identifier.</p>
10220
10221
10222
10223<p>The <code>media-type</code> attribute is applicable for the
10224
10225<code>html</code> output method.  The default value is
10226
10227<code>text/html</code>.</p>
10228
10229
10230
10231</div2>
10232
10233
10234
10235<div2>
10236
10237<head>Text Output Method</head>
10238
10239
10240
10241<p>The <code>text</code> output method outputs the result tree by
10242
10243outputting the string-value of every text node in the result tree in
10244
10245document order without any escaping.</p>
10246
10247
10248
10249<p>The <code>media-type</code> attribute is applicable for the
10250
10251<code>text</code> output method.  The default value for the
10252
10253<code>media-type</code> attribute is <code>text/plain</code>.</p>
10254
10255
10256
10257<p>The <code>encoding</code> attribute identifies the encoding that
10258
10259the <code>text</code> output method should use to convert sequences of
10260
10261characters to sequences of bytes.  The default is system-dependent. If
10262
10263the result tree contains a character that cannot be represented in the
10264
10265encoding that the XSLT processor is using for output, the XSLT
10266
10267processor should signal an error.</p>
10268
10269
10270
10271</div2>
10272
10273
10274
10275<div2 id="disable-output-escaping">
10276
10277<head>Disabling Output Escaping</head>
10278
10279
10280
10281<p>Normally, the <code>xml</code> output method escapes &amp; and &lt;
10282
10283(and possibly other characters) when outputting text nodes.  This
10284
10285ensures that the output is well-formed XML. However, it is sometimes
10286
10287convenient to be able to produce output that is almost, but not quite
10288
10289well-formed XML; for example, the output may include ill-formed
10290
10291sections which are intended to be transformed into well-formed XML by
10292
10293a subsequent non-XML aware process.  For this reason, XSLT provides a
10294
10295mechanism for disabling output escaping. An <code>xsl:value-of</code>
10296
10297or <code>xsl:text</code> element may have a
10298
10299<code>disable-output-escaping</code> attribute; the allowed values are
10300
10301<code>yes</code> or <code>no</code>; the default is <code>no</code>;
10302
10303if the value is <code>yes</code>, then a text node generated by
10304
10305instantiating the <code>xsl:value-of</code> or <code>xsl:text</code>
10306
10307element should be output without any escaping. For example,</p>
10308
10309
10310
10311<eg><![CDATA[<xsl:text disable-output-escaping="yes">&lt;</xsl:text>]]></eg>
10312
10313
10314
10315<p>should generate the single character <code>&lt;</code>.</p>
10316
10317
10318
10319<p>It is an error for output escaping to be disabled for a text node
10320
10321that is used for something other than a text node in the result tree.
10322
10323Thus, it is an error to disable output escaping for an
10324
10325<code>xsl:value-of</code> or <code>xsl:text</code> element that is
10326
10327used to generate the string-value of a comment, processing instruction
10328
10329or attribute node; it is also an error to convert a <termref
10330
10331def="dt-result-tree-fragment">result tree fragment</termref> to a
10332
10333number or a string if the result tree fragment contains a text node for
10334
10335which escaping was disabled.  In both cases, an XSLT processor may
10336
10337signal the error; if it does not signal the error, it must recover by
10338
10339ignoring the <code>disable-output-escaping</code> attribute.</p>
10340
10341
10342
10343<p>The <code>disable-output-escaping</code> attribute may be used with
10344
10345the <code>html</code> output method as well as with the
10346
10347<code>xml</code> output method.  The <code>text</code> output method
10348
10349ignores the <code>disable-output-escaping</code> attribute, since it
10350
10351does not perform any output escaping.</p>
10352
10353
10354
10355<p>An XSLT processor will only be able to disable output escaping if
10356
10357it controls how the result tree is output. This may not always be the
10358
10359case.  For example, the result tree may be used as the source tree for
10360
10361another XSLT transformation instead of being output.  An XSLT
10362
10363processor is not required to support disabling output escaping.  If an
10364
10365<code>xsl:value-of</code> or <code>xsl:text</code> specifies that
10366
10367output escaping should be disabled and the XSLT processor does not
10368
10369support this, the XSLT processor may signal an error; if it does not
10370
10371signal an error, it must recover by not disabling output escaping.</p>
10372
10373
10374
10375<p>If output escaping is disabled for a character that is not
10376
10377representable in the encoding that the XSLT processor is using for
10378
10379output, then the XSLT processor may signal an error; if it does not
10380
10381signal an error, it must recover by not disabling output escaping.</p>
10382
10383
10384
10385<p>Since disabling output escaping may not work with all XSLT
10386
10387processors and can result in XML that is not well-formed, it should be
10388
10389used only when there is no alternative.</p>
10390
10391
10392
10393
10394
10395</div2>
10396
10397
10398
10399</div1>
10400
10401
10402
10403<div1 id="conformance">
10404
10405<head>Conformance</head>
10406
10407
10408
10409<p>A conforming XSLT processor must be able to use a stylesheet to
10410
10411transform a source tree into a result tree as specified in this
10412
10413document.  A conforming XSLT processor need not be able to output the
10414
10415result in XML or in any other form.</p>
10416
10417
10418
10419<note><p>Vendors of XSLT processors are strongly encouraged to provide
10420
10421a way to verify that their processor is behaving conformingly by
10422
10423allowing the result tree to be output as XML or by providing access to
10424
10425the result tree through a standard API such as the DOM or
10426
10427SAX.</p></note>
10428
10429
10430
10431<p>A conforming XSLT processor must signal any errors except for those
10432
10433that this document specifically allows an XSLT processor not to
10434
10435signal. A conforming XSLT processor may but need not recover from any
10436
10437errors that it signals.</p>
10438
10439
10440
10441<p>A conforming XSLT processor may impose limits on the processing
10442
10443resources consumed by the processing of a stylesheet.</p>
10444
10445
10446
10447</div1>
10448
10449
10450
10451<div1 id="notation">
10452
10453<head>Notation</head>
10454
10455
10456
10457<p>The specification of each XSLT-defined element type is preceded by
10458
10459a summary of its syntax in the form of a model for elements of that
10460
10461element type.  The meaning of syntax summary notation is as
10462
10463follows:</p>
10464
10465
10466
10467<ulist>
10468
10469
10470
10471<item><p>An attribute is required if and only if its name is in
10472
10473bold.</p></item>
10474
10475
10476
10477<item><p>The string that occurs in the place of an attribute value
10478
10479specifies the allowed values of the attribute.  If this is surrounded
10480
10481by curly braces, then the attribute value is treated as an <termref
10482
10483def="dt-attribute-value-template">attribute value template</termref>,
10484
10485and the string occurring within curly braces specifies the allowed
10486
10487values of the result of instantiating the attribute value template.
10488
10489Alternative allowed values are separated by <code>|</code>.  A quoted
10490
10491string indicates a value equal to that specific string. An unquoted,
10492
10493italicized name specifies a particular type of value.</p></item>
10494
10495
10496
10497<item><p>If the element is allowed not to be empty, then the element
10498
10499contains a comment specifying the allowed content.  The allowed
10500
10501content is specified in a similar way to an element type declaration
10502
10503in XML; <emph>template</emph> means that any mixture of text nodes,
10504
10505literal result elements, extension elements, and XSLT elements from
10506
10507the <code>instruction</code> category is allowed;
10508
10509<emph>top-level-elements</emph> means that any mixture of XSLT
10510
10511elements from the <code>top-level-element</code> category is
10512
10513allowed.</p></item>
10514
10515
10516
10517<item><p>The element is prefaced by comments indicating if it belongs
10518
10519to the <code>instruction</code> category or
10520
10521<code>top-level-element</code> category or both.  The category of an
10522
10523element just affects whether it is allowed in the content of elements
10524
10525that allow a <emph>template</emph> or
10526
10527<emph>top-level-elements</emph>.</p></item>
10528
10529
10530
10531</ulist>
10532
10533
10534
10535</div1>
10536
10537
10538
10539</body>
10540
10541
10542
10543<back>
10544
10545<div1>
10546
10547<head>References</head>
10548
10549<div2>
10550
10551<head>Normative References</head>
10552
10553
10554
10555<blist>
10556
10557
10558
10559<bibl id="XML" key="XML">World Wide Web Consortium. <emph>Extensible
10560
10561Markup Language (XML) 1.0.</emph> W3C Recommendation. See <loc
10562
10563href="http://www.w3.org/TR/1998/REC-xml-19980210">http://www.w3.org/TR/1998/REC-xml-19980210</loc></bibl>
10564
10565
10566
10567<bibl id="XMLNAMES" key="XML Names">World Wide Web
10568
10569Consortium. <emph>Namespaces in XML.</emph> W3C Recommendation. See
10570
10571<loc
10572
10573href="http://www.w3.org/TR/REC-xml-names">http://www.w3.org/TR/REC-xml-names</loc></bibl>
10574
10575
10576
10577<bibl id="XPATH" key="XPath">World Wide Web Consortium. <emph>XML Path
10578
10579Language.</emph> W3C Recommendation. See <loc
10580
10581href="&XPath;">http://www.w3.org/TR/xpath</loc></bibl>
10582
10583
10584
10585</blist>
10586
10587</div2>
10588
10589<div2>
10590
10591<head>Other References</head>
10592
10593
10594
10595<blist>
10596
10597
10598
10599<bibl id="CSS2" key="CSS2">World Wide Web Consortium.  <emph>Cascading
10600
10601Style Sheets, level 2 (CSS2)</emph>.  W3C Recommendation.  See <loc
10602
10603href="http://www.w3.org/TR/1998/REC-CSS2-19980512"
10604
10605>http://www.w3.org/TR/1998/REC-CSS2-19980512</loc></bibl>
10606
10607
10608
10609<bibl id="DSSSL" key="DSSSL">International Organization
10610
10611for Standardization, International Electrotechnical Commission.
10612
10613<emph>ISO/IEC 10179:1996.  Document Style Semantics and Specification
10614
10615Language (DSSSL)</emph>.  International Standard.</bibl>
10616
10617
10618
10619<bibl id="HTML" key="HTML">World Wide Web Consortium. <emph>HTML 4.0
10620
10621specification</emph>. W3C Recommendation. See <loc
10622
10623href="http://www.w3.org/TR/REC-html40"
10624
10625>http://www.w3.org/TR/REC-html40</loc></bibl>
10626
10627
10628
10629<bibl id="IANA" key="IANA">Internet Assigned Numbers
10630
10631Authority. <emph>Character Sets</emph>. See <loc
10632
10633href="ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets"
10634
10635>ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets</loc>.</bibl>
10636
10637
10638
10639<bibl id="RFC2278" key="RFC2278">N. Freed, J. Postel.  <emph>IANA
10640
10641Charset Registration Procedures</emph>.  IETF RFC 2278. See <loc
10642
10643href="http://www.ietf.org/rfc/rfc2278.txt"
10644
10645>http://www.ietf.org/rfc/rfc2278.txt</loc>.</bibl>
10646
10647
10648
10649<bibl id="RFC2376" key="RFC2376">E. Whitehead, M. Murata.  <emph>XML
10650
10651Media Types</emph>. IETF RFC 2376. See <loc
10652
10653href="http://www.ietf.org/rfc/rfc2376.txt"
10654
10655>http://www.ietf.org/rfc/rfc2376.txt</loc>.</bibl>
10656
10657
10658
10659<bibl id="RFC2396" key="RFC2396">T. Berners-Lee, R. Fielding, and
10660
10661L. Masinter.  <emph>Uniform Resource Identifiers (URI): Generic
10662
10663Syntax</emph>. IETF RFC 2396. See <loc
10664
10665href="http://www.ietf.org/rfc/rfc2396.txt">http://www.ietf.org/rfc/rfc2396.txt</loc>.</bibl>
10666
10667
10668
10669<bibl id="UNICODE-TR10" key="UNICODE TR10">Unicode Consortium.
10670
10671<emph>Unicode Technical Report #10. Unicode Collation
10672
10673Algorithm</emph>.  Unicode Technical Report.  See <loc
10674
10675href="http://www.unicode.org/unicode/reports/tr10/index.html"
10676
10677>http://www.unicode.org/unicode/reports/tr10/index.html</loc>.</bibl>
10678
10679
10680
10681<bibl id="XHTML" key="XHTML">World Wide Web Consortium. <emph>XHTML
10682
106831.0: The Extensible HyperText Markup Language.</emph> W3C Proposed
10684
10685Recommendation. See <loc href="http://www.w3.org/TR/xhtml1"
10686
10687>http://www.w3.org/TR/xhtml1</loc></bibl>
10688
10689
10690
10691<bibl id="XPTR" key="XPointer">World Wide Web
10692
10693Consortium. <emph>XML Pointer Language (XPointer).</emph> W3C Working
10694
10695Draft. See <loc href="http://www.w3.org/TR/xptr"
10696
10697>http://www.w3.org/TR/xptr</loc></bibl>
10698
10699
10700
10701<bibl id="XMLSTYLE" key="XML Stylesheet">World Wide Web
10702
10703Consortium. <emph>Associating stylesheets with XML documents.</emph>
10704
10705W3C Recommendation. See <loc
10706
10707href="http://www.w3.org/TR/xml-stylesheet"
10708
10709>http://www.w3.org/TR/xml-stylesheet</loc></bibl>
10710
10711
10712
10713<bibl id="XSL" key="XSL">World Wide Web Consortium.  <emph>Extensible
10714
10715Stylesheet Language (XSL).</emph>  W3C Working Draft.  See <loc
10716
10717href="http://www.w3.org/TR/WD-xsl"
10718
10719     >http://www.w3.org/TR/WD-xsl</loc></bibl>
10720
10721
10722
10723</blist>
10724
10725
10726
10727</div2>
10728
10729</div1>
10730
10731
10732
10733<div1 id="element-syntax-summary">
10734
10735<head>Element Syntax Summary</head>
10736
10737
10738
10739<e:element-syntax-summary/>
10740
10741
10742
10743</div1>
10744
10745
10746
10747<inform-div1 id="dtd">
10748
10749<head>DTD Fragment for XSLT Stylesheets</head>
10750
10751
10752
10753<note><p>This DTD Fragment is not normative because XML 1.0 DTDs do
10754
10755not support XML Namespaces and thus cannot correctly describe the
10756
10757allowed structure of an XSLT stylesheet.</p></note>
10758
10759
10760
10761<p>The following entity can be used to construct a DTD for XSLT
10762
10763stylesheets that create instances of a particular result DTD.  Before
10764
10765referencing the entity, the stylesheet DTD must define a
10766
10767<code>result-elements</code> parameter entity listing the allowed
10768
10769result element types.  For example:</p>
10770
10771
10772
10773<eg><![CDATA[<!ENTITY % result-elements "
10774
10775  | fo:inline-sequence
10776
10777  | fo:block
10778
10779">]]></eg>
10780
10781
10782
10783<p>Such result elements should be declared to have
10784
10785<code>xsl:use-attribute-sets</code> and
10786
10787<code>xsl:extension-element-prefixes</code> attributes.  The following
10788
10789entity declares the <code>result-element-atts</code> parameter for
10790
10791this purpose. The content that XSLT allows for result elements is the
10792
10793same as it allows for the XSLT elements that are declared in the
10794
10795following entity with a content model of <code>%template;</code>.  The
10796
10797DTD may use a more restrictive content model than
10798
10799<code>%template;</code> to reflect the constraints of the result
10800
10801DTD.</p>
10802
10803
10804
10805<p>The DTD may define the <code>non-xsl-top-level</code> parameter
10806
10807entity to allow additional top-level elements from namespaces other
10808
10809than the XSLT namespace.</p>
10810
10811
10812
10813<p>The use of the <code>xsl:</code> prefix in this DTD does not imply
10814
10815that XSLT stylesheets are required to use this prefix.  Any of the
10816
10817elements declared in this DTD may have attributes whose name starts
10818
10819with <code>xmlns:</code> or is equal to <code>xmlns</code> in addition
10820
10821to the attributes declared in this DTD.</p>
10822
10823
10824
10825<eg><![CDATA[<!ENTITY % char-instructions "
10826
10827  | xsl:apply-templates
10828
10829  | xsl:call-template
10830
10831  | xsl:apply-imports
10832
10833  | xsl:for-each
10834
10835  | xsl:value-of
10836
10837  | xsl:copy-of
10838
10839  | xsl:number
10840
10841  | xsl:choose
10842
10843  | xsl:if
10844
10845  | xsl:text
10846
10847  | xsl:copy
10848
10849  | xsl:variable
10850
10851  | xsl:message
10852
10853  | xsl:fallback
10854
10855">
10856
10857
10858
10859<!ENTITY % instructions "
10860
10861  %char-instructions;
10862
10863  | xsl:processing-instruction
10864
10865  | xsl:comment
10866
10867  | xsl:element
10868
10869  | xsl:attribute
10870
10871">
10872
10873
10874
10875<!ENTITY % char-template "
10876
10877 (#PCDATA
10878
10879  %char-instructions;)*
10880
10881">
10882
10883
10884
10885<!ENTITY % template "
10886
10887 (#PCDATA
10888
10889  %instructions;
10890
10891  %result-elements;)*
10892
10893">
10894
10895
10896
10897<!-- Used for the type of an attribute value that is a URI reference.-->
10898
10899<!ENTITY % URI "CDATA">
10900
10901
10902
10903<!-- Used for the type of an attribute value that is a pattern.-->
10904
10905<!ENTITY % pattern "CDATA">
10906
10907
10908
10909<!-- Used for the type of an attribute value that is an
10910
10911     attribute value template.-->
10912
10913<!ENTITY % avt "CDATA">
10914
10915
10916
10917<!-- Used for the type of an attribute value that is a QName; the prefix
10918
10919     gets expanded by the XSLT processor. -->
10920
10921<!ENTITY % qname "NMTOKEN">
10922
10923
10924
10925<!-- Like qname but a whitespace-separated list of QNames. -->
10926
10927<!ENTITY % qnames "NMTOKENS">
10928
10929
10930
10931<!-- Used for the type of an attribute value that is an expression.-->
10932
10933<!ENTITY % expr "CDATA">
10934
10935
10936
10937<!-- Used for the type of an attribute value that consists
10938
10939     of a single character.-->
10940
10941<!ENTITY % char "CDATA">
10942
10943
10944
10945<!-- Used for the type of an attribute value that is a priority. -->
10946
10947<!ENTITY % priority "NMTOKEN">
10948
10949
10950
10951<!ENTITY % space-att "xml:space (default|preserve) #IMPLIED">
10952
10953
10954
10955<!-- This may be overridden to customize the set of elements allowed
10956
10957at the top-level. -->
10958
10959
10960
10961<!ENTITY % non-xsl-top-level "">
10962
10963
10964
10965<!ENTITY % top-level "
10966
10967 (xsl:import*,
10968
10969  (xsl:include
10970
10971  | xsl:strip-space
10972
10973  | xsl:preserve-space
10974
10975  | xsl:output
10976
10977  | xsl:key
10978
10979  | xsl:decimal-format
10980
10981  | xsl:attribute-set
10982
10983  | xsl:variable
10984
10985  | xsl:param
10986
10987  | xsl:template
10988
10989  | xsl:namespace-alias
10990
10991  %non-xsl-top-level;)*)
10992
10993">
10994
10995
10996
10997<!ENTITY % top-level-atts '
10998
10999  extension-element-prefixes CDATA #IMPLIED
11000
11001  exclude-result-prefixes CDATA #IMPLIED
11002
11003  id ID #IMPLIED
11004
11005  version NMTOKEN #REQUIRED
11006
11007  xmlns:xsl CDATA #FIXED "]]>&XSLT.ns;<![CDATA["
11008
11009  %space-att;
11010
11011'>
11012
11013
11014
11015<!-- This entity is defined for use in the ATTLIST declaration
11016
11017for result elements. -->
11018
11019
11020
11021<!ENTITY % result-element-atts '
11022
11023  xsl:extension-element-prefixes CDATA #IMPLIED
11024
11025  xsl:exclude-result-prefixes CDATA #IMPLIED
11026
11027  xsl:use-attribute-sets %qnames; #IMPLIED
11028
11029  xsl:version NMTOKEN #IMPLIED
11030
11031'>
11032
11033
11034
11035<!ELEMENT xsl:stylesheet %top-level;>
11036
11037<!ATTLIST xsl:stylesheet %top-level-atts;>
11038
11039
11040
11041<!ELEMENT xsl:transform %top-level;>
11042
11043<!ATTLIST xsl:transform %top-level-atts;>
11044
11045
11046
11047<!ELEMENT xsl:import EMPTY>
11048
11049<!ATTLIST xsl:import href %URI; #REQUIRED>
11050
11051
11052
11053<!ELEMENT xsl:include EMPTY>
11054
11055<!ATTLIST xsl:include href %URI; #REQUIRED>
11056
11057
11058
11059<!ELEMENT xsl:strip-space EMPTY>
11060
11061<!ATTLIST xsl:strip-space elements CDATA #REQUIRED>
11062
11063
11064
11065<!ELEMENT xsl:preserve-space EMPTY>
11066
11067<!ATTLIST xsl:preserve-space elements CDATA #REQUIRED>
11068
11069
11070
11071<!ELEMENT xsl:output EMPTY>
11072
11073<!ATTLIST xsl:output
11074
11075  method %qname; #IMPLIED
11076
11077  version NMTOKEN #IMPLIED
11078
11079  encoding CDATA #IMPLIED
11080
11081  omit-xml-declaration (yes|no) #IMPLIED
11082
11083  standalone (yes|no) #IMPLIED
11084
11085  doctype-public CDATA #IMPLIED
11086
11087  doctype-system CDATA #IMPLIED
11088
11089  cdata-section-elements %qnames; #IMPLIED
11090
11091  indent (yes|no) #IMPLIED
11092
11093  media-type CDATA #IMPLIED
11094
11095>
11096
11097
11098
11099<!ELEMENT xsl:key EMPTY>
11100
11101<!ATTLIST xsl:key
11102
11103  name %qname; #REQUIRED
11104
11105  match %pattern; #REQUIRED
11106
11107  use %expr; #REQUIRED
11108
11109>
11110
11111
11112
11113<!ELEMENT xsl:decimal-format EMPTY>
11114
11115<!ATTLIST xsl:decimal-format
11116
11117  name %qname; #IMPLIED
11118
11119  decimal-separator %char; "."
11120
11121  grouping-separator %char; ","
11122
11123  infinity CDATA "Infinity"
11124
11125  minus-sign %char; "-"
11126
11127  NaN CDATA "NaN"
11128
11129  percent %char; "%"
11130
11131  per-mille %char; "&#x2030;"
11132
11133  zero-digit %char; "0"
11134
11135  digit %char; "#"
11136
11137  pattern-separator %char; ";"
11138
11139>
11140
11141
11142
11143<!ELEMENT xsl:namespace-alias EMPTY>
11144
11145<!ATTLIST xsl:namespace-alias
11146
11147  stylesheet-prefix CDATA #REQUIRED
11148
11149  result-prefix CDATA #REQUIRED
11150
11151>
11152
11153
11154
11155<!ELEMENT xsl:template
11156
11157 (#PCDATA
11158
11159  %instructions;
11160
11161  %result-elements;
11162
11163  | xsl:param)*
11164
11165>
11166
11167
11168
11169<!ATTLIST xsl:template
11170
11171  match %pattern; #IMPLIED
11172
11173  name %qname; #IMPLIED
11174
11175  priority %priority; #IMPLIED
11176
11177  mode %qname; #IMPLIED
11178
11179  %space-att;
11180
11181>
11182
11183
11184
11185<!ELEMENT xsl:value-of EMPTY>
11186
11187<!ATTLIST xsl:value-of
11188
11189  select %expr; #REQUIRED
11190
11191  disable-output-escaping (yes|no) "no"
11192
11193>
11194
11195
11196
11197<!ELEMENT xsl:copy-of EMPTY>
11198
11199<!ATTLIST xsl:copy-of select %expr; #REQUIRED>
11200
11201
11202
11203<!ELEMENT xsl:number EMPTY>
11204
11205<!ATTLIST xsl:number
11206
11207   level (single|multiple|any) "single"
11208
11209   count %pattern; #IMPLIED
11210
11211   from %pattern; #IMPLIED
11212
11213   value %expr; #IMPLIED
11214
11215   format %avt; '1'
11216
11217   lang %avt; #IMPLIED
11218
11219   letter-value %avt; #IMPLIED
11220
11221   grouping-separator %avt; #IMPLIED
11222
11223   grouping-size %avt; #IMPLIED
11224
11225>
11226
11227
11228
11229<!ELEMENT xsl:apply-templates (xsl:sort|xsl:with-param)*>
11230
11231<!ATTLIST xsl:apply-templates
11232
11233  select %expr; "node()"
11234
11235  mode %qname; #IMPLIED
11236
11237>
11238
11239
11240
11241<!ELEMENT xsl:apply-imports EMPTY>
11242
11243
11244
11245<!-- xsl:sort cannot occur after any other elements or
11246
11247any non-whitespace character -->
11248
11249
11250
11251<!ELEMENT xsl:for-each
11252
11253 (#PCDATA
11254
11255  %instructions;
11256
11257  %result-elements;
11258
11259  | xsl:sort)*
11260
11261>
11262
11263
11264
11265<!ATTLIST xsl:for-each
11266
11267  select %expr; #REQUIRED
11268
11269  %space-att;
11270
11271>
11272
11273
11274
11275<!ELEMENT xsl:sort EMPTY>
11276
11277<!ATTLIST xsl:sort
11278
11279  select %expr; "."
11280
11281  lang %avt; #IMPLIED
11282
11283  data-type %avt; "text"
11284
11285  order %avt; "ascending"
11286
11287  case-order %avt; #IMPLIED
11288
11289>
11290
11291
11292
11293<!ELEMENT xsl:if %template;>
11294
11295<!ATTLIST xsl:if
11296
11297  test %expr; #REQUIRED
11298
11299  %space-att;
11300
11301>
11302
11303
11304
11305<!ELEMENT xsl:choose (xsl:when+, xsl:otherwise?)>
11306
11307<!ATTLIST xsl:choose %space-att;>
11308
11309
11310
11311<!ELEMENT xsl:when %template;>
11312
11313<!ATTLIST xsl:when
11314
11315  test %expr; #REQUIRED
11316
11317  %space-att;
11318
11319>
11320
11321
11322
11323<!ELEMENT xsl:otherwise %template;>
11324
11325<!ATTLIST xsl:otherwise %space-att;>
11326
11327
11328
11329<!ELEMENT xsl:attribute-set (xsl:attribute)*>
11330
11331<!ATTLIST xsl:attribute-set
11332
11333  name %qname; #REQUIRED
11334
11335  use-attribute-sets %qnames; #IMPLIED
11336
11337>
11338
11339
11340
11341<!ELEMENT xsl:call-template (xsl:with-param)*>
11342
11343<!ATTLIST xsl:call-template
11344
11345  name %qname; #REQUIRED
11346
11347>
11348
11349
11350
11351<!ELEMENT xsl:with-param %template;>
11352
11353<!ATTLIST xsl:with-param
11354
11355  name %qname; #REQUIRED
11356
11357  select %expr; #IMPLIED
11358
11359>
11360
11361
11362
11363<!ELEMENT xsl:variable %template;>
11364
11365<!ATTLIST xsl:variable
11366
11367  name %qname; #REQUIRED
11368
11369  select %expr; #IMPLIED
11370
11371>
11372
11373
11374
11375<!ELEMENT xsl:param %template;>
11376
11377<!ATTLIST xsl:param
11378
11379  name %qname; #REQUIRED
11380
11381  select %expr; #IMPLIED
11382
11383>
11384
11385
11386
11387<!ELEMENT xsl:text (#PCDATA)>
11388
11389<!ATTLIST xsl:text
11390
11391  disable-output-escaping (yes|no) "no"
11392
11393>
11394
11395
11396
11397<!ELEMENT xsl:processing-instruction %char-template;>
11398
11399<!ATTLIST xsl:processing-instruction
11400
11401  name %avt; #REQUIRED
11402
11403  %space-att;
11404
11405>
11406
11407
11408
11409<!ELEMENT xsl:element %template;>
11410
11411<!ATTLIST xsl:element
11412
11413  name %avt; #REQUIRED
11414
11415  namespace %avt; #IMPLIED
11416
11417  use-attribute-sets %qnames; #IMPLIED
11418
11419  %space-att;
11420
11421>
11422
11423
11424
11425<!ELEMENT xsl:attribute %char-template;>
11426
11427<!ATTLIST xsl:attribute
11428
11429  name %avt; #REQUIRED
11430
11431  namespace %avt; #IMPLIED
11432
11433  %space-att;
11434
11435>
11436
11437
11438
11439<!ELEMENT xsl:comment %char-template;>
11440
11441<!ATTLIST xsl:comment %space-att;>
11442
11443
11444
11445<!ELEMENT xsl:copy %template;>
11446
11447<!ATTLIST xsl:copy
11448
11449  %space-att;
11450
11451  use-attribute-sets %qnames; #IMPLIED
11452
11453>
11454
11455
11456
11457<!ELEMENT xsl:message %template;>
11458
11459<!ATTLIST xsl:message
11460
11461  %space-att;
11462
11463  terminate (yes|no) "no"
11464
11465>
11466
11467
11468
11469<!ELEMENT xsl:fallback %template;>
11470
11471<!ATTLIST xsl:fallback %space-att;>]]></eg>
11472
11473
11474
11475</inform-div1>
11476
11477
11478
11479<inform-div1>
11480
11481<head>Examples</head>
11482
11483
11484
11485<div2>
11486
11487<head>Document Example</head>
11488
11489
11490
11491<p>This example is a stylesheet for transforming documents that
11492
11493conform to a simple DTD into XHTML <bibref ref="XHTML"/>.  The DTD
11494
11495is:</p>
11496
11497
11498
11499<eg><![CDATA[<!ELEMENT doc (title, chapter*)>
11500
11501<!ELEMENT chapter (title, (para|note)*, section*)>
11502
11503<!ELEMENT section (title, (para|note)*)>
11504
11505<!ELEMENT title (#PCDATA|emph)*>
11506
11507<!ELEMENT para (#PCDATA|emph)*>
11508
11509<!ELEMENT note (#PCDATA|emph)*>
11510
11511<!ELEMENT emph (#PCDATA|emph)*>]]></eg>
11512
11513
11514
11515<p>The stylesheet is:</p>
11516
11517
11518
11519<eg>&lt;xsl:stylesheet version="1.0"
11520
11521                xmlns:xsl="&XSLT.ns;"
11522
11523                xmlns="&XHTML.ns;"><![CDATA[
11524
11525
11526
11527<xsl:strip-space elements="doc chapter section"/>
11528
11529<xsl:output
11530
11531   method="xml"
11532
11533   indent="yes"
11534
11535   encoding="iso-8859-1"
11536
11537/>
11538
11539
11540
11541<xsl:template match="doc">
11542
11543 <html>
11544
11545   <head>
11546
11547     <title>
11548
11549       <xsl:value-of select="title"/>
11550
11551     </title>
11552
11553   </head>
11554
11555   <body>
11556
11557     <xsl:apply-templates/>
11558
11559   </body>
11560
11561 </html>
11562
11563</xsl:template>
11564
11565
11566
11567<xsl:template match="doc/title">
11568
11569  <h1>
11570
11571    <xsl:apply-templates/>
11572
11573  </h1>
11574
11575</xsl:template>
11576
11577
11578
11579<xsl:template match="chapter/title">
11580
11581  <h2>
11582
11583    <xsl:apply-templates/>
11584
11585  </h2>
11586
11587</xsl:template>
11588
11589
11590
11591<xsl:template match="section/title">
11592
11593  <h3>
11594
11595    <xsl:apply-templates/>
11596
11597  </h3>
11598
11599</xsl:template>
11600
11601
11602
11603<xsl:template match="para">
11604
11605  <p>
11606
11607    <xsl:apply-templates/>
11608
11609  </p>
11610
11611</xsl:template>
11612
11613
11614
11615<xsl:template match="note">
11616
11617  <p class="note">
11618
11619    <b>NOTE: </b>
11620
11621    <xsl:apply-templates/>
11622
11623  </p>
11624
11625</xsl:template>
11626
11627
11628
11629<xsl:template match="emph">
11630
11631  <em>
11632
11633    <xsl:apply-templates/>
11634
11635  </em>
11636
11637</xsl:template>
11638
11639
11640
11641</xsl:stylesheet>]]></eg>
11642
11643
11644
11645<p>With the following input document</p>
11646
11647
11648
11649<eg><![CDATA[<!DOCTYPE doc SYSTEM "doc.dtd">
11650
11651<doc>
11652
11653<title>Document Title</title>
11654
11655<chapter>
11656
11657<title>Chapter Title</title>
11658
11659<section>
11660
11661<title>Section Title</title>
11662
11663<para>This is a test.</para>
11664
11665<note>This is a note.</note>
11666
11667</section>
11668
11669<section>
11670
11671<title>Another Section Title</title>
11672
11673<para>This is <emph>another</emph> test.</para>
11674
11675<note>This is another note.</note>
11676
11677</section>
11678
11679</chapter>
11680
11681</doc>]]></eg>
11682
11683
11684
11685<p>it would produce the following result</p>
11686
11687
11688
11689<eg>&lt;?xml version="1.0" encoding="iso-8859-1"?>
11690
11691&lt;html xmlns="&XHTML.ns;"><![CDATA[
11692
11693<head>
11694
11695<title>Document Title</title>
11696
11697</head>
11698
11699<body>
11700
11701<h1>Document Title</h1>
11702
11703<h2>Chapter Title</h2>
11704
11705<h3>Section Title</h3>
11706
11707<p>This is a test.</p>
11708
11709<p class="note">
11710
11711<b>NOTE: </b>This is a note.</p>
11712
11713<h3>Another Section Title</h3>
11714
11715<p>This is <em>another</em> test.</p>
11716
11717<p class="note">
11718
11719<b>NOTE: </b>This is another note.</p>
11720
11721</body>
11722
11723</html>]]></eg>
11724
11725
11726
11727</div2>
11728
11729
11730
11731<div2 id="data-example">
11732
11733<head>Data Example</head>
11734
11735
11736
11737<p>This is an example of transforming some data represented in XML
11738
11739using three different XSLT stylesheets to produce three different
11740
11741representations of the data, HTML, SVG and VRML.</p>
11742
11743
11744
11745<p>The input data is:</p>
11746
11747
11748
11749<eg><![CDATA[<sales>
11750
11751
11752
11753        <division id="North">
11754
11755                <revenue>10</revenue>
11756
11757                <growth>9</growth>
11758
11759                <bonus>7</bonus>
11760
11761        </division>
11762
11763
11764
11765        <division id="South">
11766
11767                <revenue>4</revenue>
11768
11769                <growth>3</growth>
11770
11771                <bonus>4</bonus>
11772
11773        </division>
11774
11775
11776
11777        <division id="West">
11778
11779                <revenue>6</revenue>
11780
11781                <growth>-1.5</growth>
11782
11783                <bonus>2</bonus>
11784
11785        </division>
11786
11787
11788
11789</sales>]]></eg>
11790
11791
11792
11793<p>The following stylesheet, which uses the simplified syntax
11794
11795described in <specref ref="result-element-stylesheet"/>, transforms
11796
11797the data into HTML:</p>
11798
11799
11800
11801<eg>&lt;html xsl:version="1.0"
11802
11803      xmlns:xsl="&XSLT.ns;"<![CDATA[
11804
11805      lang="en">
11806
11807    <head>
11808
11809	<title>Sales Results By Division</title>
11810
11811    </head>
11812
11813    <body>
11814
11815	<table border="1">
11816
11817	    <tr>
11818
11819		<th>Division</th>
11820
11821		<th>Revenue</th>
11822
11823		<th>Growth</th>
11824
11825		<th>Bonus</th>
11826
11827	    </tr>
11828
11829	    <xsl:for-each select="sales/division">
11830
11831		<!-- order the result by revenue -->
11832
11833		<xsl:sort select="revenue"
11834
11835			  data-type="number"
11836
11837			  order="descending"/>
11838
11839		<tr>
11840
11841		    <td>
11842
11843			<em><xsl:value-of select="@id"/></em>
11844
11845		    </td>
11846
11847		    <td>
11848
11849			<xsl:value-of select="revenue"/>
11850
11851		    </td>
11852
11853		    <td>
11854
11855			<!-- highlight negative growth in red -->
11856
11857			<xsl:if test="growth &lt; 0">
11858
11859			     <xsl:attribute name="style">
11860
11861				 <xsl:text>color:red</xsl:text>
11862
11863			     </xsl:attribute>
11864
11865			</xsl:if>
11866
11867			<xsl:value-of select="growth"/>
11868
11869		    </td>
11870
11871		    <td>
11872
11873			<xsl:value-of select="bonus"/>
11874
11875		    </td>
11876
11877		</tr>
11878
11879	    </xsl:for-each>
11880
11881	</table>
11882
11883    </body>
11884
11885</html>]]></eg>
11886
11887
11888
11889<p>The HTML output is:</p>
11890
11891
11892
11893<eg><![CDATA[<html lang="en">
11894
11895<head>
11896
11897<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
11898
11899<title>Sales Results By Division</title>
11900
11901</head>
11902
11903<body>
11904
11905<table border="1">
11906
11907<tr>
11908
11909<th>Division</th><th>Revenue</th><th>Growth</th><th>Bonus</th>
11910
11911</tr>
11912
11913<tr>
11914
11915<td><em>North</em></td><td>10</td><td>9</td><td>7</td>
11916
11917</tr>
11918
11919<tr>
11920
11921<td><em>West</em></td><td>6</td><td style="color:red">-1.5</td><td>2</td>
11922
11923</tr>
11924
11925<tr>
11926
11927<td><em>South</em></td><td>4</td><td>3</td><td>4</td>
11928
11929</tr>
11930
11931</table>
11932
11933</body>
11934
11935</html>]]></eg>
11936
11937
11938
11939<p>The following stylesheet transforms the data into SVG:</p>
11940
11941
11942
11943<eg>&lt;xsl:stylesheet version="1.0"
11944
11945                xmlns:xsl="&XSLT.ns;"<![CDATA[
11946
11947                xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">
11948
11949
11950
11951<xsl:output method="xml" indent="yes" media-type="image/svg"/>
11952
11953
11954
11955<xsl:template match="/">
11956
11957
11958
11959<svg width = "3in" height="3in">
11960
11961    <g style = "stroke: #000000">
11962
11963        <!-- draw the axes -->
11964
11965        <line x1="0" x2="150" y1="150" y2="150"/>
11966
11967        <line x1="0" x2="0" y1="0" y2="150"/>
11968
11969        <text x="0" y="10">Revenue</text>
11970
11971        <text x="150" y="165">Division</text>
11972
11973        <xsl:for-each select="sales/division">
11974
11975	    <!-- define some useful variables -->
11976
11977
11978
11979	    <!-- the bar's x position -->
11980
11981	    <xsl:variable name="pos"
11982
11983	                  select="(position()*40)-30"/>
11984
11985
11986
11987	    <!-- the bar's height -->
11988
11989	    <xsl:variable name="height"
11990
11991	                  select="revenue*10"/>
11992
11993
11994
11995	    <!-- the rectangle -->
11996
11997	    <rect x="{$pos}" y="{150-$height}"
11998
11999                  width="20" height="{$height}"/>
12000
12001
12002
12003	    <!-- the text label -->
12004
12005	    <text x="{$pos}" y="165">
12006
12007	        <xsl:value-of select="@id"/>
12008
12009	    </text>
12010
12011
12012
12013	    <!-- the bar value -->
12014
12015	    <text x="{$pos}" y="{145-$height}">
12016
12017	        <xsl:value-of select="revenue"/>
12018
12019	    </text>
12020
12021        </xsl:for-each>
12022
12023    </g>
12024
12025</svg>
12026
12027
12028
12029</xsl:template>
12030
12031</xsl:stylesheet>]]></eg>
12032
12033
12034
12035<p>The SVG output is:</p>
12036
12037
12038
12039<eg><![CDATA[<svg width="3in" height="3in"
12040
12041     xmlns="http://www.w3.org/Graphics/SVG/svg-19990412.dtd">
12042
12043    <g style="stroke: #000000">
12044
12045	<line x1="0" x2="150" y1="150" y2="150"/>
12046
12047	<line x1="0" x2="0" y1="0" y2="150"/>
12048
12049	<text x="0" y="10">Revenue</text>
12050
12051	<text x="150" y="165">Division</text>
12052
12053	<rect x="10" y="50" width="20" height="100"/>
12054
12055	<text x="10" y="165">North</text>
12056
12057	<text x="10" y="45">10</text>
12058
12059	<rect x="50" y="110" width="20" height="40"/>
12060
12061	<text x="50" y="165">South</text>
12062
12063	<text x="50" y="105">4</text>
12064
12065	<rect x="90" y="90" width="20" height="60"/>
12066
12067	<text x="90" y="165">West</text>
12068
12069	<text x="90" y="85">6</text>
12070
12071    </g>
12072
12073</svg>]]></eg>
12074
12075
12076
12077<p>The following stylesheet transforms the data into VRML:</p>
12078
12079
12080
12081<eg>&lt;xsl:stylesheet version="1.0"
12082
12083                xmlns:xsl="&XSLT.ns;"><![CDATA[
12084
12085
12086
12087<!-- generate text output as mime type model/vrml, using default charset -->
12088
12089<xsl:output method="text" encoding="UTF-8" media-type="model/vrml"/>
12090
12091
12092
12093        <xsl:template match="/">#VRML V2.0 utf8
12094
12095
12096
12097# externproto definition of a single bar element
12098
12099EXTERNPROTO bar [
12100
12101  field SFInt32 x
12102
12103  field SFInt32 y
12104
12105  field SFInt32 z
12106
12107  field SFString name
12108
12109  ]
12110
12111  "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl"
12112
12113
12114
12115# inline containing the graph axes
12116
12117Inline {
12118
12119        url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wrl"
12120
12121        }
12122
12123
12124
12125                <xsl:for-each select="sales/division">
12126
12127bar {
12128
12129        x <xsl:value-of select="revenue"/>
12130
12131        y <xsl:value-of select="growth"/>
12132
12133        z <xsl:value-of select="bonus"/>
12134
12135        name "<xsl:value-of select="@id"/>"
12136
12137        }
12138
12139                </xsl:for-each>
12140
12141
12142
12143        </xsl:template>
12144
12145
12146
12147</xsl:stylesheet>]]></eg>
12148
12149
12150
12151<p>The VRML output is:</p>
12152
12153
12154
12155<eg><![CDATA[#VRML V2.0 utf8
12156
12157
12158
12159# externproto definition of a single bar element
12160
12161EXTERNPROTO bar [
12162
12163  field SFInt32 x
12164
12165  field SFInt32 y
12166
12167  field SFInt32 z
12168
12169  field SFString name
12170
12171  ]
12172
12173  "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl"
12174
12175
12176
12177# inline containing the graph axes
12178
12179Inline {
12180
12181        url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wrl"
12182
12183        }
12184
12185
12186
12187
12188
12189bar {
12190
12191        x 10
12192
12193        y 9
12194
12195        z 7
12196
12197        name "North"
12198
12199        }
12200
12201
12202
12203bar {
12204
12205        x 4
12206
12207        y 3
12208
12209        z 4
12210
12211        name "South"
12212
12213        }
12214
12215
12216
12217bar {
12218
12219        x 6
12220
12221        y -1.5
12222
12223        z 2
12224
12225        name "West"
12226
12227        }]]></eg>
12228
12229
12230
12231</div2>
12232
12233
12234
12235</inform-div1>
12236
12237
12238
12239<inform-div1>
12240
12241<head>Acknowledgements</head>
12242
12243<p>The following have contributed to authoring this draft:</p>
12244
12245<slist>
12246
12247<sitem>Daniel Lipkin, Saba</sitem>
12248
12249<sitem>Jonathan Marsh, Microsoft</sitem>
12250
12251<sitem>Henry Thompson, University of Edinburgh</sitem>
12252
12253<sitem>Norman Walsh, Arbortext</sitem>
12254
12255<sitem>Steve Zilles, Adobe</sitem>
12256
12257</slist>
12258
12259
12260
12261<p>This specification was developed and approved for publication by the
12262
12263W3C XSL Working Group (WG). WG approval of this specification does not
12264
12265necessarily imply that all WG members voted for its approval. The
12266
12267current members of the XSL WG are:</p>
12268
12269
12270
12271<orglist>
12272
12273<member>
12274
12275<name>Sharon Adler</name>
12276
12277<affiliation>IBM</affiliation>
12278
12279<role>Co-Chair</role>
12280
12281</member>
12282
12283<member>
12284
12285<name>Anders Berglund</name>
12286
12287<affiliation>IBM</affiliation>
12288
12289</member>
12290
12291<member>
12292
12293<name>Perin Blanchard</name>
12294
12295<affiliation>Novell</affiliation>
12296
12297</member>
12298
12299<member>
12300
12301<name>Scott Boag</name>
12302
12303<affiliation>Lotus</affiliation>
12304
12305</member>
12306
12307<member>
12308
12309<name>Larry Cable</name>
12310
12311<affiliation>Sun</affiliation>
12312
12313</member>
12314
12315<member>
12316
12317<name>Jeff Caruso</name>
12318
12319<affiliation>Bitstream</affiliation>
12320
12321</member>
12322
12323<member>
12324
12325<name>James Clark</name>
12326
12327</member>
12328
12329<member>
12330
12331<name>Peter Danielsen</name>
12332
12333<affiliation>Bell Labs</affiliation>
12334
12335</member>
12336
12337<member>
12338
12339<name>Don Day</name>
12340
12341<affiliation>IBM</affiliation>
12342
12343</member>
12344
12345<member>
12346
12347<name>Stephen Deach</name>
12348
12349<affiliation>Adobe</affiliation>
12350
12351</member>
12352
12353<member>
12354
12355<name>Dwayne Dicks</name>
12356
12357<affiliation>SoftQuad</affiliation>
12358
12359</member>
12360
12361<member>
12362
12363<name>Andrew Greene</name>
12364
12365<affiliation>Bitstream</affiliation>
12366
12367</member>
12368
12369<member>
12370
12371<name>Paul Grosso</name>
12372
12373<affiliation>Arbortext</affiliation>
12374
12375</member>
12376
12377<member>
12378
12379<name>Eduardo Gutentag</name>
12380
12381<affiliation>Sun</affiliation>
12382
12383</member>
12384
12385<member>
12386
12387<name>Juliane Harbarth</name>
12388
12389<affiliation>Software AG</affiliation>
12390
12391</member>
12392
12393<member>
12394
12395<name>Mickey Kimchi</name>
12396
12397<affiliation>Enigma</affiliation>
12398
12399</member>
12400
12401<member>
12402
12403<name>Chris Lilley</name>
12404
12405<affiliation>W3C</affiliation>
12406
12407</member>
12408
12409<member>
12410
12411<name>Chris Maden</name>
12412
12413<affiliation>Exemplary Technologies</affiliation>
12414
12415</member>
12416
12417<member>
12418
12419<name>Jonathan Marsh</name>
12420
12421<affiliation>Microsoft</affiliation>
12422
12423</member>
12424
12425<member>
12426
12427<name>Alex Milowski</name>
12428
12429<affiliation>Lexica</affiliation>
12430
12431</member>
12432
12433<member>
12434
12435<name>Steve Muench</name>
12436
12437<affiliation>Oracle</affiliation>
12438
12439</member>
12440
12441<member>
12442
12443<name>Scott Parnell</name>
12444
12445<affiliation>Xerox</affiliation>
12446
12447</member>
12448
12449<member>
12450
12451<name>Vincent Quint</name>
12452
12453<affiliation>W3C</affiliation>
12454
12455</member>
12456
12457<member>
12458
12459<name>Dan Rapp</name>
12460
12461<affiliation>Novell</affiliation>
12462
12463</member>
12464
12465<member>
12466
12467<name>Gregg Reynolds</name>
12468
12469<affiliation>Datalogics</affiliation>
12470
12471</member>
12472
12473<member>
12474
12475<name>Jonathan Robie</name>
12476
12477<affiliation>Software AG</affiliation>
12478
12479</member>
12480
12481<member>
12482
12483<name>Mark Scardina</name>
12484
12485<affiliation>Oracle</affiliation>
12486
12487</member>
12488
12489<member>
12490
12491<name>Henry Thompson</name>
12492
12493<affiliation>University of Edinburgh</affiliation>
12494
12495</member>
12496
12497<member>
12498
12499<name>Philip Wadler</name>
12500
12501<affiliation>Bell Labs</affiliation>
12502
12503</member>
12504
12505<member>
12506
12507<name>Norman Walsh</name>
12508
12509<affiliation>Arbortext</affiliation>
12510
12511</member>
12512
12513<member>
12514
12515<name>Sanjiva Weerawarana</name>
12516
12517<affiliation>IBM</affiliation>
12518
12519</member>
12520
12521<member>
12522
12523<name>Steve Zilles</name>
12524
12525<affiliation>Adobe</affiliation>
12526
12527<role>Co-Chair</role>
12528
12529</member>
12530
12531</orglist>
12532
12533
12534
12535</inform-div1>
12536
12537
12538
12539<inform-div1>
12540
12541<head>Changes from Proposed Recommendation</head>
12542
12543
12544
12545<p>The following are the changes since the Proposed Recommendation:</p>
12546
12547
12548
12549<ulist>
12550
12551
12552
12553<item><p>The <code>xsl:version</code> attribute is required on a
12554
12555literal result element used as a stylesheet (see <specref
12556
12557ref="result-element-stylesheet"/>).</p></item>
12558
12559
12560
12561<item><p>The <code>data-type</code> attribute on <code>xsl:sort</code>
12562
12563can use a prefixed name to specify a data-type not defined by
12564
12565XSLT (see <specref ref="sorting"/>).</p></item>
12566
12567
12568
12569</ulist>
12570
12571
12572
12573</inform-div1>
12574
12575
12576
12577<inform-div1>
12578
12579<head>Features under Consideration for Future Versions of XSLT</head>
12580
12581
12582
12583<p>The following features are under consideration for versions of XSLT
12584
12585after XSLT 1.0:</p>
12586
12587
12588
12589<ulist>
12590
12591
12592
12593<item><p>a conditional expression;</p></item>
12594
12595
12596
12597<item><p>support for XML Schema datatypes and archetypes;</p></item>
12598
12599
12600
12601<item><p>support for something like style rules in the original XSL
12602
12603submission;</p></item>
12604
12605
12606
12607<item><p>an attribute to control the default namespace for names
12608
12609occurring in XSLT attributes;</p></item>
12610
12611
12612
12613<item><p>support for entity references;</p></item>
12614
12615
12616
12617<item><p>support for DTDs in the data model;</p></item>
12618
12619
12620
12621<item><p>support for notations in the data model;</p></item>
12622
12623
12624
12625<item><p>a way to get back from an element to the elements that
12626
12627reference it (e.g. by IDREF attributes);</p></item>
12628
12629
12630
12631<item><p>an easier way to get an ID or key in another document;</p></item>
12632
12633
12634
12635<item><p>support for regular expressions for matching against any or
12636
12637all of text nodes, attribute values, attribute names, element type
12638
12639names;</p></item>
12640
12641
12642
12643<item><p>case-insensitive comparisons;</p></item>
12644
12645
12646
12647<item><p>normalization of strings before comparison, for example for
12648
12649compatibility characters;</p></item>
12650
12651
12652
12653<item><p>a function <code>string resolve(node-set)</code> function
12654
12655that treats the value of the argument as a relative URI and turns it
12656
12657into an absolute URI using the base URI of the node;</p></item>
12658
12659
12660
12661<item><p>multiple result documents;</p></item>
12662
12663
12664
12665<item><p>defaulting the <code>select</code> attribute on
12666
12667<code>xsl:value-of</code> to the current node;</p></item>
12668
12669
12670
12671<item><p>an attribute on <code>xsl:attribute</code> to control how the
12672
12673attribute value is normalized;</p></item>
12674
12675
12676
12677<item><p>additional attributes on <code>xsl:sort</code> to provide
12678
12679further control over sorting, such as relative order of
12680
12681scripts;</p></item>
12682
12683
12684
12685<item><p>a way to put the text of a resource identified by a URI into
12686
12687the result tree;</p></item>
12688
12689
12690
12691<item><p>allow unions in steps (e.g. <code>foo/(bar|baz)</code>);</p></item>
12692
12693
12694
12695<item><p>allow for result tree fragments all operations that are
12696
12697allowed for node-sets;</p></item>
12698
12699
12700
12701<item><p>a way to group together consecutive nodes having duplicate
12702
12703subelements or attributes;</p></item>
12704
12705
12706
12707<item><p>features to make handling of the HTML <code>style</code>
12708
12709attribute more convenient.</p></item>
12710
12711
12712
12713</ulist>
12714
12715
12716
12717</inform-div1>
12718
12719
12720
12721</back>
12722
12723</spec>
12724
12725