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