home *** CD-ROM | disk | FTP | other *** search
/ XML Bible (2nd Edition) / XML_Bible_Second_Edition_Hungry_Minds_2001.iso / mac / specs / REC-xslt-19991116.xml < prev    next >
Extensible Markup Language  |  2001-04-26  |  248KB  |  6,364 lines

  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!-- $Id: REC-xslt-19991116.xml,v 1.1 1999/11/16 15:01:35 hugo Exp $ -->
  3. <!DOCTYPE spec PUBLIC "-//W3C//DTD Specification V2.0//EN"
  4.                       "xmlspec-v20.dtd" [
  5. <!ENTITY XML "http://www.w3.org/TR/REC-xml">
  6. <!ENTITY XMLNames "http://www.w3.org/TR/REC-xml-names">
  7. <!ENTITY XSLT.ns "http://www.w3.org/1999/XSL/Transform">
  8. <!ENTITY XSLTA.ns "http://www.w3.org/1999/XSL/TransformAlias">
  9. <!ENTITY XSLFO.ns "http://www.w3.org/1999/XSL/Format">
  10. <!ENTITY XHTML.ns "http://www.w3.org/TR/xhtml1/strict">
  11. <!ENTITY year "1999">
  12. <!ENTITY month "November">
  13. <!ENTITY MM "11">
  14. <!ENTITY day "16">
  15. <!ENTITY DD "16">
  16. <!ENTITY YYYYMMDD "&year;&MM;ⅅ">
  17. <!ENTITY LEV "REC">
  18. <!ENTITY XPath "http://www.w3.org/TR/xpath">
  19. <!ATTLIST xfunction href CDATA "&XPath;">
  20. <!-- DTD customizations -->
  21. <!ELEMENT proto (arg*)>
  22. <!ATTLIST proto
  23.   name NMTOKEN #REQUIRED
  24.   return-type (number|string|boolean|node-set|object) #REQUIRED
  25. >
  26. <!ELEMENT arg EMPTY>
  27. <!ATTLIST arg
  28.   type (number|string|boolean|node-set|object) #REQUIRED
  29.   occur (opt|rep) #IMPLIED
  30. >
  31. <!ELEMENT function (#PCDATA)>
  32. <!ELEMENT xfunction (#PCDATA)>
  33. <!ATTLIST xfunction href CDATA #REQUIRED>
  34. <!ELEMENT e:element-syntax
  35.   (e:in-category*, e:attribute*, (e:empty|e:text|e:element|e:model|e:sequence|e:choice))
  36. >
  37. <!ATTLIST e:element-syntax
  38.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  39.   name NMTOKEN #REQUIRED
  40. >
  41. <!ELEMENT e:in-category EMPTY>
  42. <!ATTLIST
  43.   e:in-category name NMTOKEN #REQUIRED
  44.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  45. >
  46. <!ELEMENT e:attribute (e:attribute-value-template|(e:constant|e:data-type)+)>
  47. <!ATTLIST e:attribute
  48.   name NMTOKEN #REQUIRED
  49.   required (yes) #IMPLIED
  50.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  51. >
  52. <!ELEMENT e:attribute-value-template (e:constant|e:data-type)+>
  53. <!ATTLIST e:attribute-value-template
  54.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  55. >
  56. <!ELEMENT e:constant EMPTY>
  57. <!ATTLIST
  58.   e:constant value CDATA #REQUIRED
  59.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  60. >
  61. <!ELEMENT e:data-type EMPTY>
  62. <!ATTLIST e:data-type
  63.   name NMTOKEN #REQUIRED
  64.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  65. >
  66. <!ELEMENT e:empty EMPTY>
  67. <!ATTLIST e:empty
  68.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  69. >
  70. <!ELEMENT e:text EMPTY>
  71. <!ATTLIST e:text
  72.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  73. >
  74. <!ELEMENT e:element EMPTY>
  75. <!ATTLIST e:element
  76.   name NMTOKEN #REQUIRED
  77.   repeat (zero-or-one|zero-or-more|one-or-more) #IMPLIED
  78.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  79. >
  80. <!ELEMENT e:model EMPTY>
  81. <!ATTLIST e:model
  82.   name NMTOKEN #REQUIRED
  83.   repeat (zero-or-one|zero-or-more|one-or-more) #IMPLIED
  84.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  85. >
  86. <!ELEMENT e:sequence (e:element|e:model|e:choice)+>
  87. <!ATTLIST e:sequence
  88.   repeat (zero-or-one|zero-or-more|one-or-more) #IMPLIED
  89.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  90. >
  91. <!ELEMENT e:choice (e:element|e:model|e:sequence)+>
  92. <!ATTLIST e:choice
  93.   repeat (zero-or-one|zero-or-more|one-or-more) #IMPLIED
  94.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  95. >
  96. <!ELEMENT e:element-syntax-summary EMPTY>
  97. <!ATTLIST e:element-syntax-summary 
  98.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  99. >
  100. <!ENTITY % local.illus.class "|proto|e:element-syntax|e:element-syntax-summary">
  101. <!ENTITY % local.tech.class "|function|xfunction">
  102. <!ENTITY % local.loc.class "|var">
  103. <!ELEMENT var (#PCDATA)>
  104. <!ATTLIST spec
  105.   xmlns:e CDATA #FIXED "http://www.w3.org/1999/XSL/Spec/ElementSyntax"
  106. >
  107. ]>
  108. <spec xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax">
  109. <header>
  110. <title>XSL Transformations (XSLT)</title>
  111. <version>Version 1.0</version>
  112. <w3c-designation>&LEV;-xslt-&YYYYMMDD;</w3c-designation>
  113. <w3c-doctype>W3C Recommendation</w3c-doctype>
  114. <pubdate><day>&day;</day><month>&month;</month><year>&year;</year></pubdate>
  115. <publoc>
  116. <loc href="http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;"
  117.           >http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;</loc>
  118. <loc role="available-format"
  119. href="http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;.xml">XML</loc>
  120. <loc role="available-format"
  121. href="http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;.html">HTML</loc>
  122. <!--
  123. <loc href="http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;.pdf"
  124.           >http://www.w3.org/TR/&year;/&LEV;-xslt-&YYYYMMDD;.pdf</loc>
  125. -->
  126. </publoc>
  127. <latestloc>
  128. <loc href="http://www.w3.org/TR/xslt"
  129.           >http://www.w3.org/TR/xslt</loc>
  130. </latestloc>
  131. <prevlocs>
  132. <loc href="http://www.w3.org/TR/1999/PR-xslt-19991008"
  133.           >http://www.w3.org/TR/1999/PR-xslt-19991008</loc>
  134. <loc href="http://www.w3.org/1999/08/WD-xslt-19990813"
  135.           >http://www.w3.org/1999/08/WD-xslt-19990813</loc>
  136. <loc href="http://www.w3.org/1999/07/WD-xslt-19990709"
  137.           >http://www.w3.org/1999/07/WD-xslt-19990709</loc>
  138. <loc href="http://www.w3.org/TR/1999/WD-xslt-19990421"
  139.           >http://www.w3.org/TR/1999/WD-xslt-19990421</loc>
  140. <loc href="http://www.w3.org/TR/1998/WD-xsl-19981216"
  141.           >http://www.w3.org/TR/1998/WD-xsl-19981216</loc>
  142. <loc href="http://www.w3.org/TR/1998/WD-xsl-19980818"
  143.           >http://www.w3.org/TR/1998/WD-xsl-19980818</loc>
  144. </prevlocs>
  145. <authlist>
  146. <author>
  147. <name>James Clark</name>
  148. <email href="mailto:jjc@jclark.com">jjc@jclark.com</email>
  149. </author>
  150. </authlist>
  151.  
  152. <status>
  153.  
  154. <p>This document has been reviewed by W3C Members and other interested
  155. parties and has been endorsed by the Director as a W3C <loc
  156. href="http://www.w3.org/Consortium/Process/#RecsW3C">Recommendation</loc>. It
  157. is a stable document and may be used as reference material or cited as
  158. a normative reference from other documents. W3C's role in making the
  159. Recommendation is to draw attention to the specification and to
  160. promote its widespread deployment. This enhances the functionality and
  161. interoperability of the Web.</p>
  162.  
  163. <p>The list of known errors in this specification is available at
  164. <loc href="http://www.w3.org/&year;/&MM;/&LEV;-xslt-&YYYYMMDD;-errata"
  165. >http://www.w3.org/&year;/&MM;/&LEV;-xslt-&YYYYMMDD;-errata</loc>.</p>
  166.  
  167. <p>Comments on this specification may be sent to <loc
  168. href="mailto:xsl-editors@w3.org">xsl-editors@w3.org</loc>; <loc
  169. href="http://lists.w3.org/Archives/Public/xsl-editors">archives</loc>
  170. of the comments are available.  Public discussion of XSL, including
  171. XSL Transformations, takes place on the <loc
  172. href="http://www.mulberrytech.com/xsl/xsl-list/index.html">XSL-List</loc>
  173. mailing list.</p>
  174.  
  175. <p>The English version of this specification is the only normative
  176. version. However, for translations of this document, see <loc
  177. href="http://www.w3.org/Style/XSL/translations.html"
  178. >http://www.w3.org/Style/XSL/translations.html</loc>.</p>
  179.  
  180. <p>A list of current W3C Recommendations and other technical documents
  181. can be found at <loc
  182. href="http://www.w3.org/TR">http://www.w3.org/TR</loc>.</p>
  183.  
  184. <p>This specification has been produced as part of the <loc
  185. href="http://www.w3.org/Style/Activity">W3C Style activity</loc>.</p>
  186.  
  187. </status>
  188.  
  189. <abstract>
  190.  
  191. <p>This specification defines the syntax and semantics of XSLT, which
  192. is a language for transforming XML documents into other XML
  193. documents.</p>
  194.  
  195. <p>XSLT is designed for use as part of XSL, which is a stylesheet
  196. language for XML. In addition to XSLT, XSL includes an XML vocabulary
  197. for specifying formatting.  XSL specifies the styling of an XML
  198. document by using XSLT to describe how the document is transformed
  199. into another XML document that uses the formatting vocabulary.</p>
  200.  
  201. <p>XSLT is also designed to be used independently of XSL.  However,
  202. XSLT is not intended as a completely general-purpose XML
  203. transformation language.  Rather it is designed primarily for the
  204. kinds of transformations that are needed when XSLT is used as part of
  205. XSL.</p>
  206.  
  207. </abstract>
  208.  
  209. <langusage>
  210. <language id="EN">English</language>
  211. <language id="ebnf">EBNF</language>
  212. </langusage>
  213. <revisiondesc>
  214. <slist>
  215. <sitem>See RCS log for revision history.</sitem>
  216. </slist>
  217. </revisiondesc>
  218. </header>
  219. <body>
  220. <div1>
  221. <head>Introduction</head>
  222.  
  223. <p>This specification defines the syntax and semantics of the XSLT
  224. language.  A transformation in the XSLT language is expressed as a
  225. well-formed XML document <bibref ref="XML"/> conforming to the
  226. Namespaces in XML Recommendation <bibref ref="XMLNAMES"/>, which may
  227. include both elements that are defined by XSLT and elements that are
  228. not defined by XSLT.  <termdef id="dt-xslt-namespace" term="XSLT
  229. Namespace">XSLT-defined elements are distinguished by belonging to a
  230. specific XML namespace (see <specref ref="xslt-namespace"/>), which is
  231. referred to in this specification as the <term>XSLT
  232. namespace</term>.</termdef> Thus this specification is a definition of
  233. the syntax and semantics of the XSLT namespace.</p>
  234.  
  235. <p>A transformation expressed in XSLT describes rules for transforming
  236. a source tree into a result tree.  The transformation is achieved by
  237. associating patterns with templates.  A pattern is matched against
  238. elements in the source tree.  A template is instantiated to create
  239. part of the result tree.  The result tree is separate from the source
  240. tree.  The structure of the result tree can be completely different
  241. from the structure of the source tree. In constructing the result
  242. tree, elements from the source tree can be filtered and reordered, and
  243. arbitrary structure can be added.</p>
  244.  
  245. <p>A transformation expressed in XSLT is called a stylesheet.  This is
  246. because, in the case when XSLT is transforming into the XSL formatting
  247. vocabulary, the transformation functions as a stylesheet.</p>
  248.  
  249. <p>This document does not specify how an XSLT stylesheet is associated
  250. with an XML document.  It is recommended that XSL processors support
  251. the mechanism described in <bibref ref="XMLSTYLE"/>.  When this or any
  252. other mechanism yields a sequence of more than one XSLT stylesheet to
  253. be applied simultaneously to a XML document, then the effect
  254. should be the same as applying a single stylesheet that imports each
  255. member of the sequence in order (see <specref ref="import"/>).</p>
  256.  
  257. <p>A stylesheet contains a set of template rules.  A template rule has
  258. two parts: a pattern which is matched against nodes in the source tree
  259. and a template which can be instantiated to form part of the result
  260. tree.  This allows a stylesheet to be applicable to a wide class of
  261. documents that have similar source tree structures.</p>
  262.  
  263. <p>A template is instantiated for a particular source element
  264. to create part of the result tree. A template can contain elements
  265. that specify literal result element structure.  A template can also
  266. contain elements from the XSLT namespace
  267. that are instructions for creating result tree
  268. fragments.  When a template is instantiated, each instruction is
  269. executed and replaced by the result tree fragment that it creates.
  270. Instructions can select and process descendant source elements.  Processing a
  271. descendant element creates a result tree fragment by finding the
  272. applicable template rule and instantiating its template. Note
  273. that elements are only processed when they have been selected by the
  274. execution of an instruction.  The result tree is constructed by
  275. finding the template rule for the root node and instantiating
  276. its template.</p>
  277.  
  278. <p>In the process of finding the applicable template rule, more
  279. than one template rule may have a pattern that matches a given
  280. element. However, only one template rule will be applied. The
  281. method for deciding which template rule to apply is described
  282. in <specref ref="conflict"/>.</p>
  283.  
  284. <p>A single template by itself has considerable power: it can create
  285. structures of arbitrary complexity; it can pull string values out of
  286. arbitrary locations in the source tree; it can generate structures
  287. that are repeated according to the occurrence of elements in the
  288. source tree.  For simple transformations where the structure of the
  289. result tree is independent of the structure of the source tree, a
  290. stylesheet can often consist of only a single template, which
  291. functions as a template for the complete result tree.  Transformations
  292. on XML documents that represent data are often of this kind (see
  293. <specref ref="data-example"/>). XSLT allows a simplified syntax for
  294. such stylesheets (see <specref ref="result-element-stylesheet"/>).</p>
  295.  
  296. <p>When a template is instantiated, it is always instantiated with
  297. respect to a <termdef id="dt-current-node" term="Current
  298. Node"><term>current node</term></termdef> and a <termdef
  299. id="dt-current-node-list" term="Current Node List"><term>current node
  300. list</term></termdef>. The current node is always a member of the
  301. current node list.  Many operations in XSLT are relative to the
  302. current node. Only a few instructions change the current node list or
  303. the current node (see <specref ref="rules"/> and <specref
  304. ref="for-each"/>); during the instantiation of one of these
  305. instructions, the current node list changes to a new list of nodes and
  306. each member of this new list becomes the current node in turn; after
  307. the instantiation of the instruction is complete, the current node and
  308. current node list revert to what they were before the instruction was
  309. instantiated.</p>
  310.  
  311. <p>XSLT makes use of the expression language defined by <bibref
  312. ref="XPATH"/> for selecting elements for processing, for conditional
  313. processing and for generating text.</p>
  314.  
  315. <p>XSLT provides two <quote>hooks</quote> for extending the language,
  316. one hook for extending the set of instruction elements used in
  317. templates and one hook for extending the set of functions used in
  318. XPath expressions.  These hooks are both based on XML namespaces.
  319. This version of XSLT does not define a mechanism for implementing the
  320. hooks. See <specref ref="extension"/>.</p>
  321.  
  322. <note><p>The XSL WG intends to define such a mechanism in a future
  323. version of this specification or in a separate
  324. specification.</p></note>
  325.  
  326. <p>The element syntax summary notation used to describe the syntax of
  327. XSLT-defined elements is described in <specref ref="notation"/>.</p>
  328.  
  329. <p>The MIME media types <code>text/xml</code> and
  330. <code>application/xml</code> <bibref ref="RFC2376"/> should be used
  331. for XSLT stylesheets.  It is possible that a media type will be
  332. registered specifically for XSLT stylesheets; if and when it is, that
  333. media type may also be used.</p>
  334.  
  335. </div1>
  336.  
  337. <div1>
  338. <head>Stylesheet Structure</head>
  339.  
  340. <div2 id="xslt-namespace">
  341. <head>XSLT Namespace</head>
  342.  
  343. <p>The XSLT namespace has the URI <code>&XSLT.ns;</code>.</p>
  344.  
  345. <note><p>The <code>1999</code> in the URI indicates the year in which
  346. the URI was allocated by the W3C.  It does not indicate the version of
  347. XSLT being used, which is specified by attributes (see <specref
  348. ref="stylesheet-element"/> and <specref
  349. ref="result-element-stylesheet"/>).</p></note>
  350.  
  351. <p>XSLT processors must use the XML namespaces mechanism <bibref
  352. ref="XMLNAMES"/> to recognize elements and attributes from this
  353. namespace. Elements from the XSLT namespace are recognized only in the
  354. stylesheet not in the source document. The complete list of
  355. XSLT-defined elements is specified in <specref
  356. ref="element-syntax-summary"/>.  Vendors must not extend the XSLT
  357. namespace with additional elements or attributes. Instead, any
  358. extension must be in a separate namespace.  Any namespace that is used
  359. for additional instruction elements must be identified by means of the
  360. extension element mechanism specified in <specref
  361. ref="extension-element"/>.</p>
  362.  
  363. <p>This specification uses a prefix of <code>xsl:</code> for referring
  364. to elements in the XSLT namespace. However, XSLT stylesheets are free
  365. to use any prefix, provided that there is a namespace declaration that
  366. binds the prefix to the URI of the XSLT namespace.</p>
  367.  
  368. <p>An element from the XSLT namespace may have any attribute not from
  369. the XSLT namespace, provided that the <xtermref
  370. href="&XPath;#dt-expanded-name">expanded-name</xtermref> of the
  371. attribute has a non-null namespace URI.  The presence of such
  372. attributes must not change the behavior of XSLT elements and functions
  373. defined in this document. Thus, an XSLT processor is always free to
  374. ignore such attributes, and must ignore such attributes without giving
  375. an error if it does not recognize the namespace URI. Such attributes
  376. can provide, for example, unique identifiers, optimization hints, or
  377. documentation.</p>
  378.  
  379. <p>It is an error for an element from the XSLT namespace to have
  380. attributes with expanded-names that have null namespace URIs
  381. (i.e. attributes with unprefixed names) other than attributes defined
  382. for the element in this document.</p>
  383.  
  384. <note><p>The conventions used for the names of XSLT elements,
  385. attributes and functions are that names are all lower-case, use
  386. hyphens to separate words, and use abbreviations only if they already
  387. appear in the syntax of a related language such as XML or
  388. HTML.</p></note>
  389.  
  390.  
  391. </div2>
  392.  
  393. <div2 id="stylesheet-element">
  394. <head>Stylesheet Element</head>
  395.  
  396. <e:element-syntax name="stylesheet">
  397.   <e:attribute name="id">
  398.     <e:data-type name="id"/>
  399.   </e:attribute>
  400.   <e:attribute name="extension-element-prefixes">
  401.     <e:data-type name="tokens"/>
  402.   </e:attribute>
  403.   <e:attribute name="exclude-result-prefixes">
  404.     <e:data-type name="tokens"/>
  405.   </e:attribute>
  406.   <e:attribute name="version" required="yes">
  407.     <e:data-type name="number"/>
  408.   </e:attribute>
  409.   <e:sequence>
  410.     <e:element repeat="zero-or-more" name="import"/>
  411.     <e:model name="top-level-elements"/>
  412.   </e:sequence>
  413. </e:element-syntax>
  414.  
  415. <e:element-syntax name="transform">
  416.   <e:attribute name="id">
  417.     <e:data-type name="id"/>
  418.   </e:attribute>
  419.   <e:attribute name="extension-element-prefixes">
  420.     <e:data-type name="tokens"/>
  421.   </e:attribute>
  422.   <e:attribute name="exclude-result-prefixes">
  423.     <e:data-type name="tokens"/>
  424.   </e:attribute>
  425.   <e:attribute name="version" required="yes">
  426.     <e:data-type name="number"/>
  427.   </e:attribute>
  428.   <e:sequence>
  429.     <e:element repeat="zero-or-more" name="import"/>
  430.     <e:model name="top-level-elements"/>
  431.   </e:sequence>
  432. </e:element-syntax>
  433.  
  434. <p>A stylesheet is represented by an <code>xsl:stylesheet</code>
  435. element in an XML document.  <code>xsl:transform</code> is allowed as
  436. a synonym for <code>xsl:stylesheet</code>.</p>
  437.  
  438. <p>An <code>xsl:stylesheet</code> element must have a
  439. <code>version</code> attribute, indicating the version of XSLT that
  440. the stylesheet requires.  For this version of XSLT, the value should
  441. be <code>1.0</code>.  When the value is not equal to <code>1.0</code>,
  442. forwards-compatible processing mode is enabled (see <specref
  443. ref="forwards"/>).</p>
  444.  
  445. <p>The <code>xsl:stylesheet</code> element may contain the following types
  446. of elements:</p>
  447. <ulist>
  448. <item><p><code>xsl:import</code></p></item>
  449. <item><p><code>xsl:include</code></p></item>
  450. <item><p><code>xsl:strip-space</code></p></item>
  451. <item><p><code>xsl:preserve-space</code></p></item>
  452. <item><p><code>xsl:output</code></p></item>
  453. <item><p><code>xsl:key</code></p></item>
  454. <item><p><code>xsl:decimal-format</code></p></item>
  455. <item><p><code>xsl:namespace-alias</code></p></item>
  456. <item><p><code>xsl:attribute-set</code></p></item>
  457. <item><p><code>xsl:variable</code></p></item>
  458. <item><p><code>xsl:param</code></p></item>
  459. <item><p><code>xsl:template</code></p></item>
  460. </ulist>
  461.  
  462. <p><termdef id="dt-top-level" term="Top-level">An element occurring as
  463. a child of an <code>xsl:stylesheet</code> element is called a
  464. <term>top-level</term> element.</termdef></p>
  465.  
  466. <p>This example shows the structure of a stylesheet.  Ellipses
  467. (<code>...</code>) indicate where attribute values or content have
  468. been omitted.  Although this example shows one of each type of allowed
  469. element, stylesheets may contain zero or more of each of these
  470. elements.</p>
  471.  
  472. <eg><xsl:stylesheet version="1.0"
  473.                 xmlns:xsl="&XSLT.ns;"><![CDATA[
  474.   <xsl:import href="..."/>
  475.  
  476.   <xsl:include href="..."/>
  477.  
  478.   <xsl:strip-space elements="..."/>
  479.   
  480.   <xsl:preserve-space elements="..."/>
  481.  
  482.   <xsl:output method="..."/>
  483.  
  484.   <xsl:key name="..." match="..." use="..."/>
  485.  
  486.   <xsl:decimal-format name="..."/>
  487.  
  488.   <xsl:namespace-alias stylesheet-prefix="..." result-prefix="..."/>
  489.  
  490.   <xsl:attribute-set name="...">
  491.     ...
  492.   </xsl:attribute-set>
  493.  
  494.   <xsl:variable name="...">...</xsl:variable>
  495.  
  496.   <xsl:param name="...">...</xsl:param>
  497.  
  498.   <xsl:template match="...">
  499.     ...
  500.   </xsl:template>
  501.  
  502.   <xsl:template name="...">
  503.     ...
  504.   </xsl:template>
  505.  
  506. </xsl:stylesheet>]]></eg>
  507.  
  508. <p>The order in which the children of the <code>xsl:stylesheet</code>
  509. element occur is not significant except for <code>xsl:import</code>
  510. elements and for error recovery.  Users are free to order the elements
  511. as they prefer, and stylesheet creation tools need not provide control
  512. over the order in which the elements occur.</p>
  513.  
  514. <p>In addition, the <code>xsl:stylesheet</code> element may contain
  515. any element not from the XSLT namespace, provided that the
  516. expanded-name of the element has a non-null namespace URI.  The presence of
  517. such top-level elements must not change the behavior of XSLT elements
  518. and functions defined in this document; for example, it would not be
  519. permitted for such a top-level element to specify that
  520. <code>xsl:apply-templates</code> was to use different rules to resolve
  521. conflicts. Thus, an XSLT processor is always free to ignore such
  522. top-level elements, and must ignore a top-level element without giving
  523. an error if it does not recognize the namespace URI. Such elements can
  524. provide, for example,</p>
  525.  
  526. <ulist>
  527.  
  528. <item><p>information used by extension elements or extension functions
  529. (see <specref ref="extension"/>),</p></item>
  530.  
  531. <item><p>information about what to do with the result tree,</p></item>
  532.  
  533. <item><p>information about how to obtain the source tree,</p></item>
  534.  
  535. <item><p>metadata about the stylesheet,</p></item>
  536.  
  537. <item><p>structured documentation for the stylesheet.</p></item>
  538.  
  539. </ulist>
  540.  
  541. </div2>
  542.  
  543. <div2 id="result-element-stylesheet">
  544. <head>Literal Result Element as Stylesheet</head>
  545.  
  546. <p>A simplified syntax is allowed for stylesheets that consist of only
  547. a single template for the root node.  The stylesheet may consist of
  548. just a literal result element (see <specref
  549. ref="literal-result-element"/>).  Such a stylesheet is equivalent to a
  550. stylesheet with an <code>xsl:stylesheet</code> element containing a
  551. template rule containing the literal result element; the template rule
  552. has a match pattern of <code>/</code>. For example</p>
  553.  
  554. <eg><html xsl:version="1.0"
  555.       xmlns:xsl="&XSLT.ns;"
  556.       xmlns="&XHTML.ns;"><![CDATA[
  557.   <head>
  558.     <title>Expense Report Summary</title>
  559.   </head>
  560.   <body>
  561.     <p>Total Amount: <xsl:value-of select="expense-report/total"/></p>
  562.   </body>
  563. </html>]]></eg>
  564.  
  565. <p>has the same meaning as</p>
  566.  
  567. <eg><xsl:stylesheet version="1.0"
  568.                 xmlns:xsl="&XSLT.ns;"
  569.                 xmlns="&XHTML.ns;"><![CDATA[
  570. <xsl:template match="/">
  571. <html>
  572.   <head>
  573.     <title>Expense Report Summary</title>
  574.   </head>
  575.   <body>
  576.     <p>Total Amount: <xsl:value-of select="expense-report/total"/></p>
  577.   </body>
  578. </html>
  579. </xsl:template>
  580. </xsl:stylesheet>]]></eg>
  581.  
  582. <p>A literal result element that is the document element of a
  583. stylesheet must have an <code>xsl:version</code> attribute, which
  584. indicates the version of XSLT that the stylesheet requires.  For this
  585. version of XSLT, the value should be <code>1.0</code>; the value must
  586. be a <xnt href="&XPath;#NT-Number">Number</xnt>.  Other literal result
  587. elements may also have an <code>xsl:version</code> attribute. When the
  588. <code>xsl:version</code> attribute is not equal to <code>1.0</code>,
  589. forwards-compatible processing mode is enabled (see <specref
  590. ref="forwards"/>).</p>
  591.  
  592. <p>The allowed content of a literal result element when used as a
  593. stylesheet is no different from when it occurs within a
  594. stylesheet. Thus, a literal result element used as a stylesheet cannot
  595. contain <termref def="dt-top-level">top-level</termref> elements.</p>
  596.  
  597. <p>In some situations, the only way that a system can recognize that an
  598. XML document needs to be processed by an XSLT processor as an XSLT
  599. stylesheet is by examining the XML document itself.  Using the
  600. simplified syntax makes this harder.</p>
  601.  
  602. <note><p>For example, another XML language (AXL) might also use an
  603. <code>axl:version</code> on the document element to indicate that an
  604. XML document was an AXL document that required processing by an AXL
  605. processor; if a document had both an <code>axl:version</code>
  606. attribute and an <code>xsl:version</code> attribute, it would be
  607. unclear whether the document should be processed by an XSLT processor
  608. or an AXL processor.</p></note>
  609.  
  610. <p>Therefore, the simplified syntax should not be used for XSLT
  611. stylesheets that may be used in such a situation.  This situation can,
  612. for example, arise when an XSLT stylesheet is transmitted as a message
  613. with a MIME media type of <code>text/xml</code> or
  614. <code>application/xml</code> to a recipient that will use the MIME
  615. media type to determine how the message is processed.</p>
  616.  
  617. </div2>
  618.  
  619. <div2 id="qname">
  620. <head>Qualified Names</head>
  621.  
  622. <p>The name of an internal XSLT object, specifically a named template
  623. (see <specref ref="named-templates"/>), a mode (see <specref
  624. ref="modes"/>), an attribute set (see <specref
  625. ref="attribute-sets"/>), a key (see <specref ref="key"/>), a
  626. decimal-format (see <specref ref="format-number"/>), a variable or a
  627. parameter (see <specref ref="variables"/>) is specified as a <xnt
  628. href="&XMLNames;#NT-QName">QName</xnt>.  If it has a prefix, then the
  629. prefix is expanded into a URI reference using the namespace
  630. declarations in effect on the attribute in which the name occurs.  The
  631. <xtermref href="&XPath;#dt-expanded-name">expanded-name</xtermref>
  632. consisting of the local part of the name and the possibly null URI
  633. reference is used as the name of the object.  The default namespace is
  634. <emph>not</emph> used for unprefixed names.</p>
  635.  
  636. </div2>
  637.  
  638. <div2 id="forwards">
  639. <head>Forwards-Compatible Processing</head>
  640.  
  641. <p>An element enables forwards-compatible mode for itself, its
  642. attributes, its descendants and their attributes if either it is an
  643. <code>xsl:stylesheet</code> element whose <code>version</code>
  644. attribute is not equal to <code>1.0</code>, or it is a literal result
  645. element that has an <code>xsl:version</code> attribute whose value is
  646. not equal to <code>1.0</code>, or it is a literal result element that
  647. does not have an <code>xsl:version</code> attribute and that is the
  648. document element of a stylesheet using the simplified syntax (see
  649. <specref ref="result-element-stylesheet"/>).  A literal result element
  650. that has an <code>xsl:version</code> attribute whose value is equal to
  651. <code>1.0</code> disables forwards-compatible mode for itself, its
  652. attributes, its descendants and their attributes.</p>
  653.  
  654. <p>If an element is processed in forwards-compatible mode, then:</p>
  655.  
  656. <ulist>
  657.  
  658. <item><p>if it is a <termref def="dt-top-level">top-level</termref>
  659. element and XSLT 1.0 does not allow such elements as top-level
  660. elements, then the element must be ignored along with its
  661. content;</p></item>
  662.  
  663. <item><p>if it is an element in a template and XSLT 1.0 does not allow
  664. such elements to occur in templates, then if the element is not
  665. instantiated, an error must not be signaled, and if the element is
  666. instantiated, the XSLT must perform fallback for the element as
  667. specified in <specref ref="fallback"/>;</p></item>
  668.  
  669. <item><p>if the element has an attribute that XSLT 1.0 does not allow
  670. the element to have or if the element has an optional attribute with a
  671. value that the XSLT 1.0 does not allow the attribute to have, then the
  672. attribute must be ignored.</p></item>
  673.  
  674. </ulist>
  675.  
  676. <p>Thus, any XSLT 1.0 processor must be able to process the following
  677. stylesheet without error, although the stylesheet includes elements
  678. from the XSLT namespace that are not defined in this
  679. specification:</p>
  680.  
  681. <eg><xsl:stylesheet version="1.1"
  682.                 xmlns:xsl="&XSLT.ns;"><![CDATA[
  683.   <xsl:template match="/">
  684.     <xsl:choose>
  685.       <xsl:when test="system-property('xsl:version') >= 1.1">
  686.         <xsl:exciting-new-1.1-feature/>
  687.       </xsl:when>
  688.       <xsl:otherwise>
  689.         <html>
  690.         <head>
  691.           <title>XSLT 1.1 required</title>
  692.         </head>
  693.         <body>
  694.           <p>Sorry, this stylesheet requires XSLT 1.1.</p>
  695.         </body>
  696.         </html>
  697.       </xsl:otherwise>
  698.     </xsl:choose>
  699.   </xsl:template>
  700. </xsl:stylesheet>]]></eg>
  701.  
  702. <note><p>If a stylesheet depends crucially on a top-level element
  703. introduced by a version of XSL after 1.0, then the stylesheet can use
  704. an <code>xsl:message</code> element with <code>terminate="yes"</code>
  705. (see <specref ref="message"/>) to ensure that XSLT processors
  706. implementing earlier versions of XSL will not silently ignore the
  707. top-level element. For example,</p>
  708.  
  709. <eg><xsl:stylesheet version="1.5"
  710.                 xmlns:xsl="&XSLT.ns;"><![CDATA[
  711.  
  712.   <xsl:important-new-1.1-declaration/>
  713.  
  714.   <xsl:template match="/">
  715.     <xsl:choose>
  716.       <xsl:when test="system-property('xsl:version') < 1.1">
  717.         <xsl:message terminate="yes">
  718.           <xsl:text>Sorry, this stylesheet requires XSLT 1.1.</xsl:text>
  719.         </xsl:message>
  720.       </xsl:when>
  721.       <xsl:otherwise>
  722.         ...
  723.       </xsl:otherwise>
  724.     </xsl:choose>
  725.   </xsl:template>
  726.   ...
  727. </xsl:stylesheet>]]></eg>
  728. </note>
  729.  
  730. <p>If an <termref def="dt-expression">expression</termref> occurs in
  731. an attribute that is processed in forwards-compatible mode, then an
  732. XSLT processor must recover from errors in the expression as
  733. follows:</p>
  734.  
  735. <ulist>
  736.  
  737. <item><p>if the expression does not match the syntax allowed by the
  738. XPath grammar, then an error must not be signaled unless the
  739. expression is actually evaluated;</p></item>
  740.  
  741. <item><p>if the expression calls a function with an unprefixed name
  742. that is not part of the XSLT library, then an error must not be
  743. signaled unless the function is actually called;</p></item>
  744.  
  745. <item><p>if the expression calls a function with a number of arguments
  746. that XSLT does not allow or with arguments of types that XSLT does not
  747. allow, then an error must not be signaled unless the function is
  748. actually called.</p></item>
  749.  
  750. </ulist>
  751.  
  752.  
  753. </div2>
  754.  
  755. <div2>
  756. <head>Combining Stylesheets</head>
  757.  
  758. <p>XSLT provides two mechanisms to combine stylesheets:</p>
  759.  
  760. <slist>
  761.  
  762. <sitem>an inclusion mechanism that allows stylesheets to be combined
  763. without changing the semantics of the stylesheets being combined,
  764. and</sitem>
  765.  
  766. <sitem>an import mechanism that allows stylesheets to override each
  767. other.</sitem>
  768.  
  769. </slist>
  770.  
  771. <div3 id="include">
  772. <head>Stylesheet Inclusion</head>
  773.  
  774. <e:element-syntax name="include">
  775.   <e:in-category name="top-level-element"/>
  776.   <e:attribute name="href" required="yes">
  777.     <e:data-type name="uri-reference"/>
  778.   </e:attribute>
  779.   <e:empty/>
  780. </e:element-syntax>
  781.  
  782. <p>An XSLT stylesheet may include another XSLT stylesheet using an
  783. <code>xsl:include</code> element. The <code>xsl:include</code> element
  784. has an <code>href</code> attribute whose value is a URI reference
  785. identifying the stylesheet to be included.  A relative URI is resolved
  786. relative to the base URI of the <code>xsl:include</code> element (see
  787. <specref ref="base-uri"/>).</p>
  788.  
  789. <p>The <code>xsl:include</code> element is only allowed as a <termref
  790. def="dt-top-level">top-level</termref> element.</p>
  791.  
  792. <p>The inclusion works at the XML tree level.  The resource located by
  793. the <code>href</code> attribute value is parsed as an XML document,
  794. and the children of the <code>xsl:stylesheet</code> element in this
  795. document replace the <code>xsl:include</code> element in the including
  796. document.  The fact that template rules or definitions are included
  797. does not affect the way they are processed.</p>
  798.  
  799. <p>The included stylesheet may use the simplified syntax described in
  800. <specref ref="result-element-stylesheet"/>.  The included stylesheet
  801. is treated the same as the equivalent <code>xsl:stylesheet</code>
  802. element.</p>
  803.  
  804. <p>It is an error if a stylesheet directly or indirectly includes
  805. itself.</p>
  806.  
  807. <note><p>Including a stylesheet multiple times can cause errors
  808. because of duplicate definitions.  Such multiple inclusions are less
  809. obvious when they are indirect. For example, if stylesheet
  810. <var>B</var> includes stylesheet <var>A</var>, stylesheet <var>C</var>
  811. includes stylesheet <var>A</var>, and stylesheet <var>D</var> includes
  812. both stylesheet <var>B</var> and stylesheet <var>C</var>, then
  813. <var>A</var> will be included indirectly by <var>D</var> twice.  If
  814. all of <var>B</var>, <var>C</var> and <var>D</var> are used as
  815. independent stylesheets, then the error can be avoided by separating
  816. everything in <var>B</var> other than the inclusion of <var>A</var>
  817. into a separate stylesheet <var>B'</var> and changing <var>B</var> to
  818. contain just inclusions of <var>B'</var> and <var>A</var>, similarly
  819. for <var>C</var>, and then changing <var>D</var> to include
  820. <var>A</var>, <var>B'</var>, <var>C'</var>.</p></note>
  821.  
  822. </div3>
  823.  
  824. <div3 id="import">
  825. <head>Stylesheet Import</head>
  826.  
  827. <e:element-syntax name="import">
  828.   <e:attribute name="href" required="yes">
  829.     <e:data-type name="uri-reference"/>
  830.   </e:attribute>
  831.   <e:empty/>
  832. </e:element-syntax>
  833.  
  834. <p>An XSLT stylesheet may import another XSLT stylesheet using an
  835. <code>xsl:import</code> element.  Importing a stylesheet is the same
  836. as including it (see <specref ref="include"/>) except that definitions
  837. and template rules in the importing stylesheet take precedence over
  838. template rules and definitions in the imported stylesheet; this is
  839. described in more detail below.  The <code>xsl:import</code> element
  840. has an <code>href</code> attribute whose value is a URI reference
  841. identifying the stylesheet to be imported.  A relative URI is resolved
  842. relative to the base URI of the <code>xsl:import</code> element (see
  843. <specref ref="base-uri"/>).</p>
  844.  
  845. <p>The <code>xsl:import</code> element is only allowed as a <termref
  846. def="dt-top-level">top-level</termref> element.  The
  847. <code>xsl:import</code> element children must precede all other
  848. element children of an <code>xsl:stylesheet</code> element, including
  849. any <code>xsl:include</code> element children.  When
  850. <code>xsl:include</code> is used to include a stylesheet, any
  851. <code>xsl:import</code> elements in the included document are moved up
  852. in the including document to after any existing
  853. <code>xsl:import</code> elements in the including document.</p>
  854.  
  855. <p>For example,</p>
  856.  
  857. <eg><xsl:stylesheet version="1.0"
  858.                 xmlns:xsl="&XSLT.ns;"><![CDATA[
  859.   <xsl:import href="article.xsl"/>
  860.   <xsl:import href="bigfont.xsl"/>
  861.   <xsl:attribute-set name="note-style">
  862.     <xsl:attribute name="font-style">italic</xsl:attribute>
  863.   </xsl:attribute-set>
  864. </xsl:stylesheet>]]></eg>
  865.  
  866. <p><termdef id="dt-import-tree" term="Import Tree">The
  867. <code>xsl:stylesheet</code> elements encountered during processing of
  868. a stylesheet that contains <code>xsl:import</code> elements are
  869. treated as forming an <term>import tree</term>.  In the import tree,
  870. each <code>xsl:stylesheet</code> element has one import child for each
  871. <code>xsl:import</code> element that it contains. Any
  872. <code>xsl:include</code> elements are resolved before constructing the
  873. import tree.</termdef> <termdef id="dt-import-precedence" term="Import
  874. Precedence">An <code>xsl:stylesheet</code> element in the import tree
  875. is defined to have lower <term>import precedence</term> than another
  876. <code>xsl:stylesheet</code> element in the import tree if it would be
  877. visited before that <code>xsl:stylesheet</code> element in a
  878. post-order traversal of the import tree (i.e. a traversal of the
  879. import tree in which an <code>xsl:stylesheet</code> element is visited
  880. after its import children).</termdef> Each definition and template
  881. rule has import precedence determined by the
  882. <code>xsl:stylesheet</code> element that contains it.</p>
  883.  
  884. <p>For example, suppose</p>
  885.  
  886. <ulist>
  887.  
  888. <item><p>stylesheet <var>A</var> imports stylesheets <var>B</var>
  889. and <var>C</var> in that order;</p></item>
  890.  
  891. <item><p>stylesheet <var>B</var> imports stylesheet
  892. <var>D</var>;</p></item>
  893.  
  894. <item><p>stylesheet <var>C</var> imports stylesheet
  895. <var>E</var>.</p></item>
  896.  
  897. </ulist>
  898.  
  899. <p>Then the order of import precedence (lowest first) is
  900. <var>D</var>, <var>B</var>, <var>E</var>, <var>C</var>,
  901. <var>A</var>.</p>
  902.  
  903. <note><p>Since <code>xsl:import</code> elements are required to occur
  904. before any definitions or template rules, an implementation that
  905. processes imported stylesheets at the point at which it encounters the
  906. <code>xsl:import</code> element will encounter definitions and
  907. template rules in increasing order of import precedence.</p></note>
  908.  
  909. <p>In general, a definition or template rule with higher import
  910. precedence takes precedence over a definition or template rule with
  911. lower import precedence.  This is defined in detail for each kind of
  912. definition and for template rules.</p>
  913.  
  914. <p>It is an error if a stylesheet directly or indirectly imports
  915. itself. Apart from this, the case where a stylesheet with a particular
  916. URI is imported in multiple places is not treated specially. The
  917. <termref def="dt-import-tree">import tree</termref> will have a
  918. separate <code>xsl:stylesheet</code> for each place that it is
  919. imported.</p>
  920.  
  921. <note><p>If <code>xsl:apply-imports</code> is used (see <specref
  922. ref="apply-imports"/>), the behavior may be different from the
  923. behavior if the stylesheet had been imported only at the place with
  924. the highest <termref def="dt-import-precedence">import
  925. precedence</termref>.</p></note>
  926.  
  927. </div3>
  928.  
  929. </div2>
  930.  
  931. <div2>
  932. <head>Embedding Stylesheets</head>
  933.  
  934. <p>Normally an XSLT stylesheet is a complete XML document with the
  935. <code>xsl:stylesheet</code> element as the document element. However,
  936. an XSLT stylesheet may also be embedded in another resource. Two forms
  937. of embedding are possible:</p>
  938.  
  939. <slist>
  940.  
  941. <sitem>the XSLT stylesheet may be textually embedded in a non-XML
  942. resource, or</sitem>
  943.  
  944. <sitem>the <code>xsl:stylesheet</code> element may occur in an XML
  945. document other than as the document element.</sitem>
  946.  
  947. </slist>
  948.  
  949. <p>To facilitate the second form of embedding, the
  950. <code>xsl:stylesheet</code> element is allowed to have an ID attribute
  951. that specifies a unique identifier.</p>
  952.  
  953. <note><p>In order for such an attribute to be used with the XPath
  954. <xfunction>id</xfunction> function, it must actually be declared in
  955. the DTD as being an ID.</p></note>
  956.  
  957. <p>The following example shows how the <code>xml-stylesheet</code>
  958. processing instruction <bibref ref="XMLSTYLE"/> can be used to allow a
  959. document to contain its own stylesheet.  The URI reference uses a
  960. relative URI with a fragment identifier to locate the
  961. <code>xsl:stylesheet</code> element:</p>
  962.  
  963. <eg><![CDATA[<?xml-stylesheet type="text/xml" href="#style1"?>
  964. <!DOCTYPE doc SYSTEM "doc.dtd">
  965. <doc>
  966. <head>
  967. <xsl:stylesheet id="style1"
  968.                 version="1.0"]]>
  969.                 xmlns:xsl="&XSLT.ns;"
  970.                 xmlns:fo="&XSLFO.ns;"><![CDATA[
  971. <xsl:import href="doc.xsl"/>
  972. <xsl:template match="id('foo')">
  973.   <fo:block font-weight="bold"><xsl:apply-templates/></fo:block>
  974. </xsl:template>
  975. <xsl:template match="xsl:stylesheet">
  976.   <!-- ignore -->
  977. </xsl:template>
  978. </xsl:stylesheet>
  979. </head>
  980. <body>
  981. <para id="foo">
  982. ...
  983. </para>
  984. </body>
  985. </doc>
  986. ]]></eg>
  987.  
  988. <note><p>A stylesheet that is embedded in the document to which it is
  989. to be applied or that may be included or imported into an stylesheet
  990. that is so embedded typically needs to contain a template rule that
  991. specifies that <code>xsl:stylesheet</code> elements are to be
  992. ignored.</p></note>
  993.  
  994. </div2>
  995.  
  996. </div1>
  997.  
  998. <div1 id="data-model">
  999. <head>Data Model</head>
  1000.  
  1001. <p>The data model used by XSLT is the same as that used by <xspecref
  1002. href="&XPath;#data-model">XPath</xspecref> with the additions
  1003. described in this section.  XSLT operates on source, result and
  1004. stylesheet documents using the same data model.  Any two XML documents
  1005. that have the same tree will be treated the same by XSLT.</p>
  1006.  
  1007. <p>Processing instructions and comments in the stylesheet are ignored:
  1008. the stylesheet is treated as if neither processing instruction nodes
  1009. nor comment nodes were included in the tree that represents the
  1010. stylesheet.</p>
  1011.  
  1012. <div2 id="root-node-children">
  1013. <head>Root Node Children</head>
  1014.  
  1015. <p>The normal restrictions on the children of the root node are
  1016. relaxed for the result tree.  The result tree may have any sequence of
  1017. nodes as children that would be possible for an element node. In
  1018. particular, it may have text node children, and any number of element
  1019. node children. When written out using the XML output method (see
  1020. <specref ref="output"/>), it is possible that a result tree will not
  1021. be a well-formed XML document; however, it will always be a
  1022. well-formed external general parsed entity.</p>
  1023.  
  1024. <p>When the source tree is created by parsing a well-formed XML
  1025. document, the root node of the source tree will automatically satisfy
  1026. the normal restrictions of having no text node children and exactly
  1027. one element child.  When the source tree is created in some other way,
  1028. for example by using the DOM, the usual restrictions are relaxed for
  1029. the source tree as for the result tree.</p>
  1030.  
  1031. </div2>
  1032.  
  1033. <div2 id="base-uri">
  1034. <head>Base URI</head>
  1035.  
  1036. <p>Every node also has an associated URI called its base URI, which is
  1037. used for resolving attribute values that represent relative URIs into
  1038. absolute URIs.  If an element or processing instruction occurs in an
  1039. external entity, the base URI of that element or processing
  1040. instruction is the URI of the external entity; otherwise, the base URI
  1041. is the base URI of the document.  The base URI of the document node is
  1042. the URI of the document entity.  The base URI for a text node, a
  1043. comment node, an attribute node or a namespace node is the base URI of
  1044. the parent of the node.</p>
  1045.  
  1046. </div2>
  1047.  
  1048. <div2 id="unparsed-entities">
  1049. <head>Unparsed Entities</head>
  1050.  
  1051. <p>The root node has a mapping that gives the URI for each unparsed
  1052. entity declared in the document's DTD.  The URI is generated from the
  1053. system identifier and public identifier specified in the entity
  1054. declaration. The XSLT processor may use the public identifier to
  1055. generate a URI for the entity instead of the URI specified in the
  1056. system identifier.  If the XSLT processor does not use the public
  1057. identifier to generate the URI, it must use the system identifier; if
  1058. the system identifier is a relative URI, it must be resolved into an
  1059. absolute URI using the URI of the resource containing the entity
  1060. declaration as the base URI <bibref ref="RFC2396"/>.</p>
  1061.  
  1062. </div2>
  1063.  
  1064. <div2 id="strip">
  1065. <head>Whitespace Stripping</head>
  1066.  
  1067. <p>After the tree for a source document or stylesheet document has
  1068. been constructed, but before it is otherwise processed by XSLT,
  1069. some text nodes are stripped.  A text node is never stripped
  1070. unless it contains only whitespace characters.  Stripping the text
  1071. node removes the text node from the tree.  The stripping process takes
  1072. as input a set of element names for which whitespace must be
  1073. preserved.  The stripping process is applied to both stylesheets and
  1074. source documents, but the set of whitespace-preserving element names
  1075. is determined differently for stylesheets and for source
  1076. documents.</p>
  1077.  
  1078. <p>A text node is preserved if any of the following apply:</p>
  1079.  
  1080. <ulist>
  1081.  
  1082. <item><p>The element name of the parent of the text node is in the set
  1083. of whitespace-preserving element names.</p></item>
  1084.  
  1085. <item><p>The text node contains at least one non-whitespace character.
  1086. As in XML, a whitespace character is #x20, #x9, #xD or #xA.</p></item>
  1087.  
  1088. <item><p>An ancestor element of the text node has an
  1089. <code>xml:space</code> attribute with a value of
  1090. <code>preserve</code>, and no closer ancestor element has
  1091. <code>xml:space</code> with a value of
  1092. <code>default</code>.</p></item>
  1093.  
  1094. </ulist>
  1095.  
  1096. <p>Otherwise, the text node is stripped.</p>
  1097.  
  1098. <p>The <code>xml:space</code> attributes are not stripped from the
  1099. tree.</p>
  1100.  
  1101. <note><p>This implies that if an <code>xml:space</code> attribute is
  1102. specified on a literal result element, it will be included in the
  1103. result.</p></note>
  1104.  
  1105. <p>For stylesheets, the set of whitespace-preserving element names
  1106. consists of just <code>xsl:text</code>.</p>
  1107.  
  1108. <e:element-syntax name="strip-space">
  1109.   <e:in-category name="top-level-element"/>
  1110.   <e:attribute name="elements" required="yes">
  1111.     <e:data-type name="tokens"/>
  1112.   </e:attribute>
  1113.   <e:empty/>
  1114. </e:element-syntax>
  1115.  
  1116. <e:element-syntax name="preserve-space">
  1117.   <e:in-category name="top-level-element"/>
  1118.   <e:attribute name="elements" required="yes">
  1119.     <e:data-type name="tokens"/>
  1120.   </e:attribute>
  1121.   <e:empty/>
  1122. </e:element-syntax>
  1123.  
  1124. <p>For source documents, the set of whitespace-preserving element
  1125. names is specified by <code>xsl:strip-space</code> and
  1126. <code>xsl:preserve-space</code> <termref
  1127. def="dt-top-level">top-level</termref> elements.  These elements each
  1128. have an <code>elements</code> attribute whose value is a
  1129. whitespace-separated list of <xnt
  1130. href="&XPath;#NT-NameTest">NameTest</xnt>s.  Initially, the
  1131. set of whitespace-preserving element names contains all element names.
  1132. If an element name matches a <xnt
  1133. href="&XPath;#NT-NameTest">NameTest</xnt> in an
  1134. <code>xsl:strip-space</code> element, then it is removed from the set
  1135. of whitespace-preserving element names.  If an element name matches a
  1136. <xnt href="&XPath;#NT-NameTest">NameTest</xnt> in an
  1137. <code>xsl:preserve-space</code> element, then it is added to the set
  1138. of whitespace-preserving element names.  An element matches a <xnt
  1139. href="&XPath;#NT-NameTest">NameTest</xnt> if and only if the
  1140. <xnt href="&XPath;#NT-NameTest">NameTest</xnt> would be true
  1141. for the element as an <xspecref href="&XPath;#node-tests">XPath node
  1142. test</xspecref>.  Conflicts between matches to
  1143. <code>xsl:strip-space</code> and <code>xsl:preserve-space</code>
  1144. elements are resolved the same way as conflicts between template rules
  1145. (see <specref ref="conflict"/>).  Thus, the applicable match for a
  1146. particular element name is determined as follows:</p>
  1147.  
  1148. <ulist>
  1149.  
  1150. <item><p>First, any match with lower <termref
  1151. def="dt-import-precedence">import precedence</termref> than another
  1152. match is ignored.</p></item>
  1153.  
  1154. <item><p>Next, any match with a <xnt
  1155. href="&XPath;#NT-NameTest">NameTest</xnt> that has a lower
  1156. <termref def="dt-default-priority">default priority</termref> than the
  1157. <termref def="dt-default-priority">default priority</termref> of the
  1158. <xnt href="&XPath;#NT-NameTest">NameTest</xnt> of another
  1159. match is ignored.</p></item>
  1160.  
  1161. </ulist>
  1162.  
  1163. <p>It is an error if this leaves more than one match.  An XSLT
  1164. processor may signal the error; if it does not signal the error, it
  1165. must recover by choosing, from amongst the matches that are left, the
  1166. one that occurs last in the stylesheet.</p>
  1167.  
  1168. </div2>
  1169.  
  1170. </div1>
  1171.  
  1172. <div1>
  1173. <head>Expressions</head>
  1174.  
  1175. <p>XSLT uses the expression language defined by XPath <bibref
  1176. ref="XPATH"/>.  Expressions are used in XSLT for a variety of purposes
  1177. including:</p>
  1178.  
  1179. <slist>
  1180. <sitem>selecting nodes for processing;</sitem>
  1181. <sitem>specifying conditions for different ways of processing a node;</sitem>
  1182. <sitem>generating text to be inserted in the result tree.</sitem>
  1183. </slist>
  1184.  
  1185. <p><termdef id="dt-expression" term="Expression">An
  1186. <term>expression</term> must match the XPath production <xnt
  1187. href="&XPath;#NT-Expr">Expr</xnt>.</termdef></p>
  1188.  
  1189. <p>Expressions occur as the value of certain attributes on
  1190. XSLT-defined elements and within curly braces in <termref
  1191. def="dt-attribute-value-template">attribute value
  1192. template</termref>s.</p>
  1193.  
  1194. <p>In XSLT, an outermost expression (i.e. an expression that is not
  1195. part of another expression) gets its context as follows:</p>
  1196.  
  1197. <ulist>
  1198.  
  1199. <item><p>the context node comes from the <termref
  1200. def="dt-current-node">current node</termref></p></item>
  1201.  
  1202. <item><p>the context position comes from the position of the <termref
  1203. def="dt-current-node">current node</termref> in the <termref
  1204. def="dt-current-node-list">current node list</termref>; the first
  1205. position is 1</p></item>
  1206.  
  1207. <item><p>the context size comes from the size of the <termref
  1208. def="dt-current-node-list">current node list</termref></p></item>
  1209.  
  1210. <item><p>the variable bindings are the bindings in scope on the
  1211. element which has the attribute in which the expression occurs (see
  1212. <specref ref="variables"/>)</p></item>
  1213.  
  1214. <item><p>the set of namespace declarations are those in scope on the
  1215. element which has the attribute in which the expression occurs;
  1216. this includes the implicit declaration of the prefix <code>xml</code>
  1217. required by the the XML Namespaces Recommendation <bibref ref="XMLNAMES"/>;
  1218. the default
  1219. namespace (as declared by <code>xmlns</code>) is not part of this
  1220. set</p></item>
  1221.  
  1222. <item><p>the function library consists of the core function library
  1223. together with the additional functions defined in <specref
  1224. ref="add-func"/> and extension functions as described in <specref
  1225. ref="extension"/>; it is an error for an expression to include a call
  1226. to any other function</p></item>
  1227.  
  1228. </ulist>
  1229.  
  1230. </div1>
  1231.  
  1232. <div1 id="rules">
  1233. <head>Template Rules</head>
  1234.  
  1235. <div2>
  1236. <head>Processing Model</head>
  1237.  
  1238. <p>A list of source nodes is processed to create a result tree
  1239. fragment.  The result tree is constructed by processing a list
  1240. containing just the root node.  A list of source nodes is processed by
  1241. appending the result tree structure created by processing each of the
  1242. members of the list in order.  A node is processed by finding all the
  1243. template rules with patterns that match the node, and choosing the
  1244. best amongst them; the chosen rule's template is then instantiated
  1245. with the node as the <termref def="dt-current-node">current
  1246. node</termref> and with the list of source nodes as the <termref
  1247. def="dt-current-node-list">current node list</termref>.  A template
  1248. typically contains instructions that select an additional list of
  1249. source nodes for processing.  The process of matching, instantiation
  1250. and selection is continued recursively until no new source nodes are
  1251. selected for processing.</p>
  1252.  
  1253. <p>Implementations are free to process the source document in any way
  1254. that produces the same result as if it were processed using this
  1255. processing model.</p>
  1256.  
  1257. </div2>
  1258.  
  1259. <div2 id="patterns">
  1260. <head>Patterns</head>
  1261.  
  1262. <p><termdef id="dt-pattern" term="Pattern">Template rules identify the
  1263. nodes to which they apply by using a <term>pattern</term>.  As well as
  1264. being used in template rules, patterns are used for numbering (see
  1265. <specref ref="number"/>) and for declaring keys (see <specref
  1266. ref="key"/>).  A pattern specifies a set of conditions on a node.  A
  1267. node that satisfies the conditions matches the pattern; a node that
  1268. does not satisfy the conditions does not match the pattern.  The
  1269. syntax for patterns is a subset of the syntax for expressions. In
  1270. particular, location paths that meet certain restrictions can be used
  1271. as patterns.  An expression that is also a pattern always evaluates to
  1272. an object of type node-set.  A node matches a pattern if the node is a
  1273. member of the result of evaluating the pattern as an expression with
  1274. respect to some possible context; the possible contexts are those
  1275. whose context node is the node being matched or one of its
  1276. ancestors.</termdef></p>
  1277.  
  1278. <p>Here are some examples of patterns:</p>
  1279.  
  1280. <ulist>
  1281.  
  1282. <item><p><code>para</code> matches any <code>para</code> element</p></item>
  1283.  
  1284. <item><p><code>*</code> matches any element</p></item>
  1285.  
  1286. <item><p><code>chapter|appendix</code> matches any
  1287. <code>chapter</code> element and any <code>appendix</code>
  1288. element</p></item>
  1289.  
  1290. <item><p><code>olist/item</code> matches any <code>item</code> element with
  1291. an <code>olist</code> parent</p></item>
  1292.  
  1293. <item><p><code>appendix//para</code> matches any <code>para</code> element with
  1294. an <code>appendix</code> ancestor element</p></item>
  1295.  
  1296. <item><p><code>/</code> matches the root node</p></item>
  1297.  
  1298. <item><p><code>text()</code> matches any text node</p></item>
  1299.  
  1300. <item><p><code>processing-instruction()</code> matches any processing
  1301. instruction</p></item>
  1302.  
  1303. <item><p><code>node()</code> matches any node other than an attribute
  1304. node and the root node</p></item>
  1305.  
  1306. <item><p><code>id("W11")</code> matches the element with unique ID
  1307. <code>W11</code></p></item>
  1308.  
  1309. <item><p><code>para[1]</code> matches any <code>para</code> element
  1310. that is the first <code>para</code> child element of its
  1311. parent</p></item>
  1312.  
  1313. <item><p><code>*[position()=1 and self::para]</code> matches any
  1314. <code>para</code> element that is the first child element of its
  1315. parent</p></item>
  1316.  
  1317. <item><p><code>para[last()=1]</code> matches any <code>para</code>
  1318. element that is the only <code>para</code> child element of its
  1319. parent</p></item>
  1320.  
  1321. <item><p><code>items/item[position()>1]</code> matches any
  1322. <code>item</code> element that has a <code>items</code> parent and
  1323. that is not the first <code>item</code> child of its parent</p></item>
  1324.  
  1325. <item><p><code>item[position() mod 2 = 1]</code> would be true for any
  1326. <code>item</code> element that is an odd-numbered <code>item</code>
  1327. child of its parent.</p></item>
  1328.  
  1329. <item><p><code>div[@class="appendix"]//p</code> matches any
  1330. <code>p</code> element with a <code>div</code> ancestor element that
  1331. has a <code>class</code> attribute with value
  1332. <code>appendix</code></p></item>
  1333.  
  1334. <item><p><code>@class</code> matches any <code>class</code> attribute
  1335. (<emph>not</emph> any element that has a <code>class</code>
  1336. attribute)</p></item>
  1337.  
  1338. <item><p><code>@*</code> matches any attribute</p></item>
  1339.  
  1340. </ulist>
  1341.  
  1342. <p>A pattern must match the grammar for <nt
  1343. def="NT-Pattern">Pattern</nt>.  A <nt def="NT-Pattern">Pattern</nt> is
  1344. a set of location path patterns separated by <code>|</code>.  A
  1345. location path pattern is a location path whose steps all use only the
  1346. <code>child</code> or <code>attribute</code> axes.  Although patterns
  1347. must not use the <code>descendant-or-self</code> axis, patterns may
  1348. use the <code>//</code> operator as well as the <code>/</code>
  1349. operator.  Location path patterns can also start with an
  1350. <xfunction>id</xfunction> or <function>key</function> function call
  1351. with a literal argument.  Predicates in a pattern can use arbitrary
  1352. expressions just like predicates in a location path.</p>
  1353.  
  1354. <scrap>
  1355. <head>Patterns</head>
  1356. <prodgroup pcw5="1" pcw2="10">
  1357. <prod id="NT-Pattern">
  1358. <lhs>Pattern</lhs>
  1359. <rhs><nt def="NT-LocationPathPattern">LocationPathPattern</nt></rhs>
  1360. <rhs>| <nt def="NT-Pattern">Pattern</nt> '|' <nt def="NT-LocationPathPattern">LocationPathPattern</nt></rhs>
  1361. </prod>
  1362. <prod id="NT-LocationPathPattern">
  1363. <lhs>LocationPathPattern</lhs>
  1364. <rhs>'/' <nt def="NT-RelativePathPattern">RelativePathPattern</nt>?</rhs>
  1365. <rhs>| <nt def="NT-IdKeyPattern">IdKeyPattern</nt> (('/' | '//') <nt def="NT-RelativePathPattern">RelativePathPattern</nt>)?</rhs>
  1366. <rhs>| '//'? <nt def="NT-RelativePathPattern">RelativePathPattern</nt></rhs>
  1367. </prod>
  1368. <prod id="NT-IdKeyPattern">
  1369. <lhs>IdKeyPattern</lhs>
  1370. <rhs>'id' '(' <xnt href="&XPath;#NT-Literal">Literal</xnt> ')'</rhs>
  1371. <rhs>| 'key' '(' <xnt href="&XPath;#NT-Literal">Literal</xnt> ',' <xnt href="&XPath;#NT-Literal">Literal</xnt> ')'</rhs>
  1372. </prod>
  1373. <prod id="NT-RelativePathPattern">
  1374. <lhs>RelativePathPattern</lhs>
  1375. <rhs><nt def="NT-StepPattern">StepPattern</nt></rhs>
  1376. <rhs>| <nt def="NT-RelativePathPattern">RelativePathPattern</nt> '/' <nt def="NT-StepPattern">StepPattern</nt></rhs>
  1377. <rhs>| <nt def="NT-RelativePathPattern">RelativePathPattern</nt> '//' <nt def="NT-StepPattern">StepPattern</nt></rhs>
  1378. </prod>
  1379. <prod id="NT-StepPattern">
  1380. <lhs>StepPattern</lhs>
  1381. <rhs>
  1382. <nt def="NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</nt>
  1383. <xnt href="&XPath;#NT-NodeTest">NodeTest</xnt>
  1384. <xnt href="&XPath;#NT-Predicate">Predicate</xnt>*
  1385. </rhs>
  1386. </prod>
  1387. <prod id="NT-ChildOrAttributeAxisSpecifier">
  1388. <lhs>ChildOrAttributeAxisSpecifier</lhs>
  1389. <rhs><xnt href="&XPath;#NT-AbbreviatedAxisSpecifier">AbbreviatedAxisSpecifier</xnt></rhs>
  1390. <rhs>| ('child' | 'attribute') '::'</rhs>
  1391. </prod>
  1392. </prodgroup>
  1393. </scrap>
  1394.  
  1395. <p>A pattern is defined to match a node if and only if there is
  1396. possible context such that when the pattern is evaluated as an
  1397. expression with that context, the node is a member of the resulting
  1398. node-set.  When a node is being matched, the possible contexts have a
  1399. context node that is the node being matched or any ancestor of that
  1400. node, and a context node list containing just the context node.</p>
  1401.  
  1402. <p>For example, <code>p</code> matches any <code>p</code> element,
  1403. because for any <code>p</code> if the expression <code>p</code> is
  1404. evaluated with the parent of the <code>p</code> element as context the
  1405. resulting node-set will contain that <code>p</code> element as one of
  1406. its members.</p>
  1407.  
  1408. <note><p>This matches even a <code>p</code> element that is the
  1409. document element, since the document root is the parent of the
  1410. document element.</p></note>
  1411.  
  1412. <p>Although the semantics of patterns are specified indirectly in
  1413. terms of expression evaluation, it is easy to understand the meaning
  1414. of a pattern directly without thinking in terms of expression
  1415. evaluation.  In a pattern, <code>|</code> indicates alternatives; a
  1416. pattern with one or more <code>|</code> separated alternatives matches
  1417. if any one of the alternative matches.  A pattern that consists of a
  1418. sequence of <nt def="NT-StepPattern">StepPattern</nt>s separated by
  1419. <code>/</code> or <code>//</code> is matched from right to left.  The
  1420. pattern only matches if the rightmost <nt
  1421. def="NT-StepPattern">StepPattern</nt> matches and a suitable element
  1422. matches the rest of the pattern; if the separator is <code>/</code>
  1423. then only the parent is a suitable element; if the separator is
  1424. <code>//</code>, then any ancestor is a suitable element.  A <nt
  1425. def="NT-StepPattern">StepPattern</nt> that uses the child axis matches
  1426. if the <xnt href="&XPath;#NT-NodeTest">NodeTest</xnt> is true for the
  1427. node and the node is not an attribute node.  A <nt
  1428. def="NT-StepPattern">StepPattern</nt> that uses the attribute axis
  1429. matches if the <xnt href="&XPath;#NT-NodeTest">NodeTest</xnt> is true
  1430. for the node and the node is an attribute node.  When <code>[]</code>
  1431. is present, then the first <xnt
  1432. href="&XPath;#NT-PredicateExpr">PredicateExpr</xnt> in a <nt
  1433. def="NT-StepPattern">StepPattern</nt> is evaluated with the node being
  1434. matched as the context node and the siblings of the context node that
  1435. match the <xnt href="&XPath;#NT-NodeTest">NodeTest</xnt> as the
  1436. context node list, unless the node being matched is an attribute node,
  1437. in which case the context node list is all the attributes that have
  1438. the same parent as the attribute being matched and that match the <xnt
  1439. href="&XPath;#NT-NameTest">NameTest</xnt>.</p>
  1440.  
  1441. <p>For example</p>
  1442.  
  1443. <eg>appendix//ulist/item[position()=1]</eg>
  1444.  
  1445. <p>matches a node if and only if all of the following are true:</p>
  1446.  
  1447. <ulist>
  1448.  
  1449. <item><p>the <xnt href="&XPath;#NT-NodeTest">NodeTest</xnt> <code>item</code> is
  1450. true for the node and the node is not an attribute; in other words the
  1451. node is an <code>item</code> element</p></item>
  1452.  
  1453. <item><p>evaluating the <xnt href="&XPath;#NT-PredicateExpr">PredicateExpr</xnt>
  1454. <code>position()=1</code> with the node as context node and the
  1455. siblings of the node that are <code>item</code> elements as the
  1456. context node list yields true</p></item>
  1457.  
  1458. <item><p>the node has a parent that matches
  1459. <code>appendix//ulist</code>; this will be true if the parent is a
  1460. <code>ulist</code> element that has an <code>appendix</code> ancestor
  1461. element.</p></item>
  1462.  
  1463. </ulist>
  1464.  
  1465. </div2>
  1466.  
  1467. <div2>
  1468. <head>Defining Template Rules</head>
  1469.  
  1470. <e:element-syntax name="template">
  1471.   <e:in-category name="top-level-element"/>
  1472.   <e:attribute name="match">
  1473.     <e:data-type name="pattern"/>
  1474.   </e:attribute>
  1475.   <e:attribute name="name">
  1476.     <e:data-type name="qname"/>
  1477.   </e:attribute>
  1478.   <e:attribute name="priority">
  1479.     <e:data-type name="number"/>
  1480.   </e:attribute>
  1481.   <e:attribute name="mode">
  1482.     <e:data-type name="qname"/>
  1483.   </e:attribute>
  1484.   <e:sequence>
  1485.     <e:element repeat="zero-or-more" name="param"/>
  1486.     <e:model name="template"/>
  1487.   </e:sequence>
  1488. </e:element-syntax>
  1489.  
  1490. <p>A template rule is specified with the <code>xsl:template</code>
  1491. element. The <code>match</code> attribute is a <nt
  1492. def="NT-Pattern">Pattern</nt> that identifies the source node or nodes
  1493. to which the rule applies.  The <code>match</code> attribute is
  1494. required unless the <code>xsl:template</code> element has a
  1495. <code>name</code> attribute (see <specref ref="named-templates"/>).
  1496. It is an error for the value of the <code>match</code> attribute to
  1497. contain a <xnt
  1498. href="&XPath;#NT-VariableReference">VariableReference</xnt>. The
  1499. content of the <code>xsl:template</code> element is the template that
  1500. is instantiated when the template rule is applied.</p>
  1501.  
  1502. <p>For example, an XML document might contain:</p>
  1503.  
  1504. <eg><![CDATA[This is an <emph>important</emph> point.]]></eg>
  1505.  
  1506. <p>The following template rule matches <code>emph</code> elements and
  1507. produces a <code>fo:inline-sequence</code> formatting object with a
  1508. <code>font-weight</code> property of <code>bold</code>.</p>
  1509.  
  1510. <eg><![CDATA[<xsl:template match="emph">
  1511.   <fo:inline-sequence font-weight="bold">
  1512.     <xsl:apply-templates/>
  1513.   </fo:inline-sequence>
  1514. </xsl:template>
  1515. ]]></eg>
  1516.  
  1517. <note><p>Examples in this document use the <code>fo:</code> prefix for
  1518. the namespace <code>&XSLFO.ns;</code>, which is
  1519. the namespace of the formatting objects defined in <bibref
  1520. ref="XSL"/>.</p></note>
  1521.  
  1522. <p>As described next, the <code>xsl:apply-templates</code> element
  1523. recursively processes the children of the source element.</p>
  1524.  
  1525. </div2>
  1526.  
  1527. <div2>
  1528. <head>Applying Template Rules</head>
  1529.  
  1530. <e:element-syntax name="apply-templates">
  1531.   <e:in-category name="instruction"/>
  1532.   <e:attribute name="select">
  1533.     <e:data-type name="node-set-expression"/>
  1534.   </e:attribute>
  1535.   <e:attribute name="mode">
  1536.     <e:data-type name="qname"/>
  1537.   </e:attribute>
  1538.   <e:choice repeat="zero-or-more">
  1539.     <e:element name="sort"/>
  1540.     <e:element name="with-param"/>
  1541.   </e:choice>
  1542. </e:element-syntax>
  1543.  
  1544. <p>This example creates a block for a <code>chapter</code> element and
  1545. then processes its immediate children.</p>
  1546.  
  1547. <eg><![CDATA[<xsl:template match="chapter">
  1548.   <fo:block>
  1549.     <xsl:apply-templates/>
  1550.   </fo:block>
  1551. </xsl:template>]]></eg>
  1552.  
  1553. <p>In the absence of a <code>select</code> attribute, the
  1554. <code>xsl:apply-templates</code> instruction processes all of the
  1555. children of the current node, including text nodes.  However, text
  1556. nodes that have been stripped as specified in <specref ref="strip"/>
  1557. will not be processed.  If stripping of whitespace nodes has not been
  1558. enabled for an element, then all whitespace in the content of the
  1559. element will be processed as text, and thus whitespace
  1560. between child elements will count in determining the position of a
  1561. child element as returned by the <xfunction>position</xfunction>
  1562. function.</p>
  1563.  
  1564. <p>A <code>select</code> attribute can be used to process nodes
  1565. selected by an expression instead of processing all children.  The
  1566. value of the <code>select</code> attribute is an <termref
  1567. def="dt-expression">expression</termref>.  The expression must
  1568. evaluate to a node-set.  The selected set of nodes is processed in
  1569. document order, unless a sorting specification is present (see
  1570. <specref ref="sorting"/>).  The following example processes all of the
  1571. <code>author</code> children of the <code>author-group</code>:</p>
  1572.  
  1573. <eg><![CDATA[<xsl:template match="author-group">
  1574.   <fo:inline-sequence>
  1575.     <xsl:apply-templates select="author"/>
  1576.   </fo:inline-sequence>
  1577. </xsl:template>]]></eg>
  1578.  
  1579. <p>The following example processes all of the <code>given-name</code>s
  1580. of the <code>author</code>s that are children of
  1581. <code>author-group</code>:</p>
  1582.  
  1583. <eg><![CDATA[<xsl:template match="author-group">
  1584.   <fo:inline-sequence>
  1585.     <xsl:apply-templates select="author/given-name"/>
  1586.   </fo:inline-sequence>
  1587. </xsl:template>]]></eg>
  1588.  
  1589. <p>This example processes all of the <code>heading</code> descendant
  1590. elements of the <code>book</code> element.</p>
  1591.  
  1592. <eg><![CDATA[<xsl:template match="book">
  1593.   <fo:block>
  1594.     <xsl:apply-templates select=".//heading"/>
  1595.   </fo:block>
  1596. </xsl:template>]]></eg>
  1597.  
  1598. <p>It is also possible to process elements that are not descendants of
  1599. the current node.  This example assumes that a <code>department</code>
  1600. element has <code>group</code> children and <code>employee</code>
  1601. descendants. It finds an employee's department and then processes
  1602. the <code>group</code> children of the <code>department</code>.</p>
  1603.  
  1604. <eg><![CDATA[<xsl:template match="employee">
  1605.   <fo:block>
  1606.     Employee <xsl:apply-templates select="name"/> belongs to group
  1607.     <xsl:apply-templates select="ancestor::department/group"/>
  1608.   </fo:block>
  1609. </xsl:template>]]></eg>
  1610.  
  1611. <p>Multiple <code>xsl:apply-templates</code> elements can be used within a
  1612. single template to do simple reordering.  The following example
  1613. creates two HTML tables. The first table is filled with domestic sales
  1614. while the second table is filled with foreign sales.</p>
  1615.  
  1616. <eg><![CDATA[<xsl:template match="product">
  1617.   <table>
  1618.     <xsl:apply-templates select="sales/domestic"/>
  1619.   </table>
  1620.   <table>
  1621.     <xsl:apply-templates select="sales/foreign"/>
  1622.   </table>
  1623. </xsl:template>]]></eg>
  1624.  
  1625. <note>
  1626.  
  1627. <p>It is possible for there to be two matching descendants where one
  1628. is a descendant of the other.  This case is not treated specially:
  1629. both descendants will be processed as usual. For example, given a
  1630. source document</p>
  1631.  
  1632. <eg><![CDATA[<doc><div><div></div></div></doc>]]></eg>
  1633.  
  1634. <p>the rule</p>
  1635.  
  1636. <eg><![CDATA[<xsl:template match="doc">
  1637.   <xsl:apply-templates select=".//div"/>
  1638. </xsl:template>]]></eg>
  1639.  
  1640. <p>will process both the outer <code>div</code> and inner <code>div</code>
  1641. elements.</p>
  1642.  
  1643. </note>
  1644.  
  1645. <note><p>Typically, <code>xsl:apply-templates</code> is used to
  1646. process only nodes that are descendants of the current node.  Such use
  1647. of <code>xsl:apply-templates</code> cannot result in non-terminating
  1648. processing loops.  However, when <code>xsl:apply-templates</code> is
  1649. used to process elements that are not descendants of the current node,
  1650. the possibility arises of non-terminating loops. For example,</p>
  1651.  
  1652. <eg role="error"><![CDATA[<xsl:template match="foo">
  1653.   <xsl:apply-templates select="."/>
  1654. </xsl:template>]]></eg>
  1655.  
  1656. <p>Implementations may be able to detect such loops in some cases, but
  1657. the possibility exists that a stylesheet may enter a non-terminating
  1658. loop that an implementation is unable to detect. This may present a
  1659. denial of service security risk.</p></note>
  1660.  
  1661. </div2>
  1662.  
  1663. <div2 id="conflict">
  1664. <head>Conflict Resolution for Template Rules</head>
  1665.  
  1666. <p>It is possible for a source node to match more than one template
  1667. rule. The template rule to be used is determined as follows:</p>
  1668.  
  1669. <olist>
  1670.  
  1671. <item><p>First, all matching template rules that have lower <termref
  1672. def="dt-import-precedence">import precedence</termref> than the
  1673. matching template rule or rules with the highest import precedence are
  1674. eliminated from consideration.</p></item>
  1675.  
  1676. <item><p>Next, all matching template rules that have lower priority
  1677. than the matching template rule or rules with the highest priority are
  1678. eliminated from consideration.  The priority of a template rule is
  1679. specified by the <code>priority</code> attribute on the template rule.
  1680. The value of this must be a real number (positive or negative),
  1681. matching the production <xnt href="&XPath;#NT-Number">Number</xnt>
  1682. with an optional leading minus sign (<code>-</code>).  <termdef
  1683. id="dt-default-priority" term="Default Priority">The <term>default
  1684. priority</term> is computed as follows:</termdef></p>
  1685.  
  1686. <ulist>
  1687.  
  1688. <item><p>If the pattern contains multiple alternatives separated by
  1689. <code>|</code>, then it is treated equivalently to a set of template
  1690. rules, one for each alternative.</p></item>
  1691.  
  1692. <item><p>If the pattern has the form of a <xnt
  1693. href="&XMLNames;#NT-QName">QName</xnt> preceded by a <nt
  1694. def="NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</nt>
  1695. or has the form
  1696. <code>processing-instruction(</code><xnt href="&XPath;#NT-Literal"
  1697. >Literal</xnt><code>)</code> preceded by a <nt
  1698. def="NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</nt>,
  1699. then the priority is 0.</p></item>
  1700.  
  1701. <item><p>If the pattern has the form <xnt
  1702. href="&XMLNames;#NT-NCName">NCName</xnt><code>:*</code> preceded by a
  1703. <nt
  1704. def="NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</nt>,
  1705. then the priority is -0.25.</p></item>
  1706.  
  1707. <item><p>Otherwise, if the pattern consists of just a <xnt
  1708. href="&XPath;#NT-NodeTest">NodeTest</xnt> preceded by a <nt
  1709. def="NT-ChildOrAttributeAxisSpecifier">ChildOrAttributeAxisSpecifier</nt>,
  1710. then the priority is -0.5.</p></item>
  1711.  
  1712. <item><p>Otherwise, the priority is 0.5.</p></item>
  1713.  
  1714. </ulist>
  1715.  
  1716. <p>Thus, the most common kind of pattern (a pattern that tests for a
  1717. node with a particular type and a particular expanded-name) has
  1718. priority 0. The next less specific kind of pattern (a pattern that
  1719. tests for a node with a particular type and an expanded-name with a
  1720. particular namespace URI) has priority -0.25.  Patterns less specific
  1721. than this (patterns that just tests for nodes with particular types)
  1722. have priority -0.5.  Patterns more specific than the most common kind
  1723. of pattern have priority 0.5.</p>
  1724.  
  1725. </item>
  1726.  
  1727. </olist>
  1728.  
  1729. <p>It is an error if this leaves more than one matching template
  1730. rule.  An XSLT processor may signal the error; if it does not signal
  1731. the error, it must recover by choosing, from amongst the matching
  1732. template rules that are left, the one that occurs last in the
  1733. stylesheet.</p>
  1734.  
  1735. </div2>
  1736.  
  1737. <div2 id="apply-imports">
  1738. <head>Overriding Template Rules</head>
  1739.  
  1740. <e:element-syntax name="apply-imports">
  1741.   <e:in-category name="instruction"/>
  1742.   <e:empty/>
  1743. </e:element-syntax>
  1744.  
  1745. <p>A template rule that is being used to override a template rule in
  1746. an imported stylesheet (see <specref ref="conflict"/>) can use the
  1747. <code>xsl:apply-imports</code> element to invoke the overridden
  1748. template rule.</p>
  1749.  
  1750. <p><termdef id="dt-current-template-rule" term="Current Template
  1751. Rule">At any point in the processing of a stylesheet, there is a
  1752. <term>current template rule</term>.  Whenever a template rule is
  1753. chosen by matching a pattern, the template rule becomes the current
  1754. template rule for the instantiation of the rule's template. When an
  1755. <code>xsl:for-each</code> element is instantiated, the current
  1756. template rule becomes null for the instantiation of the content of the
  1757. <code>xsl:for-each</code> element.</termdef></p>
  1758.  
  1759. <p><code>xsl:apply-imports</code> processes the current node using
  1760. only template rules that were imported into the stylesheet element
  1761. containing the current template rule; the node is processed in the
  1762. current template rule's mode.  It is an error if
  1763. <code>xsl:apply-imports</code> is instantiated when the current
  1764. template rule is null.</p>
  1765.  
  1766. <p>For example, suppose the stylesheet <code>doc.xsl</code> contains a
  1767. template rule for <code>example</code> elements:</p>
  1768.  
  1769. <eg><![CDATA[<xsl:template match="example">
  1770.   <pre><xsl:apply-templates/></pre>
  1771. </xsl:template>]]></eg>
  1772.  
  1773. <p>Another stylesheet could import <code>doc.xsl</code> and modify the
  1774. treatment of <code>example</code> elements as follows:</p>
  1775.  
  1776. <eg><![CDATA[<xsl:import href="doc.xsl"/>
  1777.  
  1778. <xsl:template match="example">
  1779.   <div style="border: solid red">
  1780.      <xsl:apply-imports/>
  1781.   </div>
  1782. </xsl:template>]]></eg>
  1783.  
  1784. <p>The combined effect would be to transform an <code>example</code>
  1785. into an element of the form:</p>
  1786.  
  1787. <eg><![CDATA[<div style="border: solid red"><pre>...</pre></div>]]></eg>
  1788.  
  1789. </div2>
  1790.  
  1791. <div2 id="modes">
  1792. <head>Modes</head>
  1793.  
  1794. <p>Modes allow an element to be processed multiple times, each time
  1795. producing a different result.</p>
  1796.  
  1797. <p>Both <code>xsl:template</code> and <code>xsl:apply-templates</code>
  1798. have an optional <code>mode</code> attribute.  The value of the
  1799. <code>mode</code> attribute is a <xnt
  1800. href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
  1801. in <specref ref="qname"/>. If <code>xsl:template</code> does not have
  1802. a <code>match</code> attribute, it must not have a <code>mode</code>
  1803. attribute.  If an <code>xsl:apply-templates</code> element has a
  1804. <code>mode</code> attribute, then it applies only to those template
  1805. rules from <code>xsl:template</code> elements that have a
  1806. <code>mode</code> attribute with the same value; if an
  1807. <code>xsl:apply-templates</code> element does not have a
  1808. <code>mode</code> attribute, then it applies only to those template
  1809. rules from <code>xsl:template</code> elements that do not have a
  1810. <code>mode</code> attribute.</p>
  1811.  
  1812. </div2>
  1813.  
  1814. <div2 id="built-in-rule">
  1815. <head>Built-in Template Rules</head>
  1816.  
  1817. <p>There is a built-in template rule to allow recursive processing to
  1818. continue in the absence of a successful pattern match by an explicit
  1819. template rule in the stylesheet.  This template rule applies to both
  1820. element nodes and the root node.  The following shows the equivalent
  1821. of the built-in template rule:</p>
  1822.  
  1823. <eg><![CDATA[<xsl:template match="*|/">
  1824.   <xsl:apply-templates/>
  1825. </xsl:template>]]></eg>
  1826.  
  1827. <p>There is also a built-in template rule for each mode, which allows
  1828. recursive processing to continue in the same mode in the absence of a
  1829. successful pattern match by an explicit template rule in the
  1830. stylesheet.  This template rule applies to both element nodes and the
  1831. root node.  The following shows the equivalent of the built-in
  1832. template rule for mode <code><var>m</var></code>.</p>
  1833.  
  1834. <eg><xsl:template match="*|/" mode="<var>m</var>">
  1835.   <xsl:apply-templates mode="<var>m</var>"/>
  1836. </xsl:template></eg>
  1837.  
  1838. <p>There is also a built-in template rule for text and attribute nodes
  1839. that copies text through:</p>
  1840.  
  1841. <eg><![CDATA[<xsl:template match="text()|@*">
  1842.   <xsl:value-of select="."/>
  1843. </xsl:template>]]></eg>
  1844.  
  1845. <p>The built-in template rule for processing instructions and comments
  1846. is to do nothing.</p>
  1847.  
  1848. <eg><![CDATA[<xsl:template match="processing-instruction()|comment()"/>]]></eg>
  1849.  
  1850. <p>The built-in template rule for namespace nodes is also to do
  1851. nothing. There is no pattern that can match a namespace node; so, the
  1852. built-in template rule is the only template rule that is applied for
  1853. namespace nodes.</p>
  1854.  
  1855. <p>The built-in template rules are treated as if they were imported
  1856. implicitly before the stylesheet and so have lower <termref
  1857. def="dt-import-precedence">import precedence</termref> than all other
  1858. template rules.  Thus, the author can override a built-in template
  1859. rule by including an explicit template rule.</p>
  1860.  
  1861. </div2>
  1862.  
  1863.  
  1864. </div1>
  1865.  
  1866. <div1 id="named-templates">
  1867. <head>Named Templates</head>
  1868.  
  1869. <e:element-syntax name="call-template">
  1870.   <e:in-category name="instruction"/>
  1871.   <e:attribute name="name" required="yes">
  1872.     <e:data-type name="qname"/>
  1873.   </e:attribute>
  1874.   <e:element repeat="zero-or-more" name="with-param"/>
  1875. </e:element-syntax>
  1876.  
  1877. <p>Templates can be invoked by name.  An <code>xsl:template</code>
  1878. element with a <code>name</code> attribute specifies a named template.
  1879. The value of the <code>name</code> attribute is a <xnt
  1880. href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
  1881. in <specref ref="qname"/>. If an <code>xsl:template</code> element has
  1882. a <code>name</code> attribute, it may, but need not, also have a
  1883. <code>match</code> attribute.  An <code>xsl:call-template</code>
  1884. element invokes a template by name; it has a required
  1885. <code>name</code> attribute that identifies the template to be
  1886. invoked.  Unlike <code>xsl:apply-templates</code>,
  1887. <code>xsl:call-template</code> does not change the current node or the
  1888. current node list.</p>
  1889.  
  1890. <p>The <code>match</code>, <code>mode</code> and <code>priority</code> attributes on an
  1891. <code>xsl:template</code> element do not affect whether the template
  1892. is invoked by an <code>xsl:call-template</code> element.  Similarly,
  1893. the <code>name</code> attribute on an <code>xsl:template</code>
  1894. element does not affect whether the template is invoked by an
  1895. <code>xsl:apply-templates</code> element.</p>
  1896.  
  1897. <p>It is an error if a stylesheet contains more than one template with
  1898. the same name and same <termref def="dt-import-precedence">import
  1899. precedence</termref>.</p>
  1900.  
  1901. </div1>
  1902.  
  1903.  
  1904. <div1>
  1905. <head>Creating the Result Tree</head>
  1906.  
  1907. <p>This section describes instructions that directly create nodes in
  1908. the result tree.</p>
  1909.  
  1910. <div2>
  1911. <head>Creating Elements and Attributes</head>
  1912.  
  1913. <div3 id="literal-result-element">
  1914. <head>Literal Result Elements</head>
  1915.  
  1916. <p>In a template, an element in the stylesheet that does not belong to
  1917. the XSLT namespace and that is not an extension element (see <specref
  1918. ref="extension-element"/>) is instantiated to create an element node
  1919. with the same <xtermref
  1920. href="&XPath;#dt-expanded-name">expanded-name</xtermref>.  The content
  1921. of the element is a template, which is instantiated to give the
  1922. content of the created element node. The created element node will
  1923. have the attribute nodes that were present on the element node in the
  1924. stylesheet tree, other than attributes with names in the XSLT
  1925. namespace.</p>
  1926.  
  1927. <p>The created element node will also have a copy of the namespace
  1928. nodes that were present on the element node in the stylesheet tree
  1929. with the exception of any namespace node whose string-value is the
  1930. XSLT namespace URI (<code>&XSLT.ns;</code>), a
  1931. namespace URI declared as an extension namespace (see <specref
  1932. ref="extension-element"/>), or a namespace URI designated as an
  1933. excluded namespace.  A namespace URI is designated as an excluded
  1934. namespace by using an <code>exclude-result-prefixes</code> attribute
  1935. on an <code>xsl:stylesheet</code> element or an
  1936. <code>xsl:exclude-result-prefixes</code> attribute on a literal result
  1937. element.  The value of both these attributes is a whitespace-separated
  1938. list of namespace prefixes. The namespace bound to each of the
  1939. prefixes is designated as an excluded namespace.  It is an error if
  1940. there is no namespace bound to the prefix on the element bearing the
  1941. <code>exclude-result-prefixes</code> or
  1942. <code>xsl:exclude-result-prefixes</code> attribute.  The default
  1943. namespace (as declared by <code>xmlns</code>) may be designated as an
  1944. excluded namespace by including <code>#default</code> in the list of
  1945. namespace prefixes.  The designation of a namespace as an excluded
  1946. namespace is effective within the subtree of the stylesheet rooted at
  1947. the element bearing the <code>exclude-result-prefixes</code> or
  1948. <code>xsl:exclude-result-prefixes</code> attribute;
  1949. a subtree rooted at an <code>xsl:stylesheet</code> element
  1950. does not include any stylesheets imported or included by children
  1951. of that <code>xsl:stylesheet</code> element.</p>
  1952.  
  1953. <note><p>When a stylesheet uses a namespace declaration only for the
  1954. purposes of addressing the source tree, specifying the prefix in the
  1955. <code>exclude-result-prefixes</code> attribute will avoid superfluous
  1956. namespace declarations in the result tree.</p></note>
  1957.  
  1958. <p>The value of an attribute of a literal result element is
  1959. interpreted as an <termref def="dt-attribute-value-template">attribute
  1960. value template</termref>: it can contain expressions contained
  1961. in curly braces (<code>{}</code>).</p>
  1962.  
  1963. <p><termdef id="dt-literal-namespace-uri" term="Literal Namespace
  1964. URI">A namespace URI in the stylesheet tree that is being used to
  1965. specify a namespace URI in the result tree is called a <term>literal
  1966. namespace URI</term>.</termdef> This applies to:</p>
  1967.  
  1968. <ulist>
  1969.  
  1970. <item><p>the namespace URI in the expanded-name of a literal
  1971. result element in the stylesheet</p></item>
  1972.  
  1973. <item><p>the namespace URI in the expanded-name of an attribute
  1974. specified on a literal result element in the stylesheet</p></item>
  1975.  
  1976. <item><p>the string-value of a namespace node on a literal result
  1977. element in the stylesheet</p></item>
  1978.  
  1979. </ulist>
  1980.  
  1981. <e:element-syntax name="namespace-alias">
  1982.   <e:in-category name="top-level-element"/>
  1983.   <e:attribute name="stylesheet-prefix" required="yes">
  1984.     <e:data-type name="prefix"/>
  1985.     <e:constant value="#default"/>
  1986.   </e:attribute>
  1987.   <e:attribute name="result-prefix" required="yes">
  1988.     <e:data-type name="prefix"/>
  1989.     <e:constant value="#default"/>
  1990.   </e:attribute>
  1991.   <e:empty/>
  1992. </e:element-syntax>
  1993.  
  1994. <p><termdef id="dt-alias" term="Alias">A stylesheet can use the
  1995. <code>xsl:namespace-alias</code> element to declare that one namespace
  1996. URI is an <term>alias</term> for another namespace URI.</termdef> When
  1997. a <termref def="dt-literal-namespace-uri">literal namespace
  1998. URI</termref> has been declared to be an alias for another namespace
  1999. URI, then the namespace URI in the result tree will be the namespace
  2000. URI that the literal namespace URI is an alias for, instead of the
  2001. literal namespace URI itself.  The <code>xsl:namespace-alias</code>
  2002. element declares that the namespace URI bound to the prefix specified
  2003. by the <code>stylesheet-prefix</code> attribute is an alias for the
  2004. namespace URI bound to the prefix specified by the
  2005. <code>result-prefix</code> attribute.  Thus, the
  2006. <code>stylesheet-prefix</code> attribute specifies the namespace URI
  2007. that will appear in the stylesheet, and the
  2008. <code>result-prefix</code> attribute specifies the corresponding
  2009. namespace URI that will appear in the result tree.  The default
  2010. namespace (as declared by <code>xmlns</code>) may be specified by
  2011. using <code>#default</code> instead of a prefix.  If a namespace URI
  2012. is declared to be an alias for multiple different namespace URIs, then
  2013. the declaration with the highest <termref
  2014. def="dt-import-precedence">import precedence</termref> is used. It is
  2015. an error if there is more than one such declaration.  An XSLT
  2016. processor may signal the error; if it does not signal the error, it
  2017. must recover by choosing, from amongst the declarations with the
  2018. highest import precedence, the one that occurs last in the
  2019. stylesheet.</p>
  2020.  
  2021. <p>When literal result elements are being used to create element,
  2022. attribute, or namespace nodes that use the XSLT namespace URI, the
  2023. stylesheet must use an alias.  For example, the stylesheet</p>
  2024.  
  2025. <eg><xsl:stylesheet
  2026.   version="1.0"
  2027.   xmlns:xsl="&XSLT.ns;"
  2028.   xmlns:fo="&XSLFO.ns;"
  2029.   xmlns:axsl="&XSLTA.ns;"><![CDATA[
  2030.  
  2031. <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
  2032.  
  2033. <xsl:template match="/">
  2034.   <axsl:stylesheet>
  2035.     <xsl:apply-templates/>
  2036.   </axsl:stylesheet>
  2037. </xsl:template>
  2038.  
  2039. <xsl:template match="block">
  2040.   <axsl:template match="{.}">
  2041.      <fo:block><axsl:apply-templates/></fo:block>
  2042.   </axsl:template>
  2043. </xsl:template>
  2044.  
  2045. </xsl:stylesheet>]]></eg>
  2046.  
  2047. <p>will generate an XSLT stylesheet from a document of the form:</p>
  2048.  
  2049. <eg><![CDATA[<elements>
  2050. <block>p</block>
  2051. <block>h1</block>
  2052. <block>h2</block>
  2053. <block>h3</block>
  2054. <block>h4</block>
  2055. </elements>]]></eg>
  2056.  
  2057. <note><p>It may be necessary also to use aliases for namespaces other
  2058. than the XSLT namespace URI.  For example, literal result elements
  2059. belonging to a namespace dealing with digital signatures might cause
  2060. XSLT stylesheets to be mishandled by general-purpose security
  2061. software; using an alias for the namespace would avoid the possibility
  2062. of such mishandling.</p></note>
  2063.  
  2064. </div3>
  2065.  
  2066. <div3>
  2067. <head>Creating Elements with <code>xsl:element</code></head>
  2068.  
  2069. <e:element-syntax name="element">
  2070.   <e:in-category name="instruction"/>
  2071.   <e:attribute name="name" required="yes">
  2072.     <e:attribute-value-template>
  2073.       <e:data-type name="qname"/>
  2074.     </e:attribute-value-template>
  2075.   </e:attribute>
  2076.   <e:attribute name="namespace">
  2077.     <e:attribute-value-template>
  2078.       <e:data-type name="uri-reference"/>
  2079.     </e:attribute-value-template>
  2080.   </e:attribute>
  2081.   <e:attribute name="use-attribute-sets">
  2082.     <e:data-type name="qnames"/>
  2083.   </e:attribute>
  2084.   <e:model name="template"/>
  2085. </e:element-syntax>
  2086.  
  2087. <p>The <code>xsl:element</code> element allows an element to be
  2088. created with a computed name.  The <xtermref
  2089. href="&XPath;#dt-expanded-name">expanded-name</xtermref> of the
  2090. element to be created is specified by a required <code>name</code>
  2091. attribute and an optional <code>namespace</code> attribute.  The
  2092. content of the <code>xsl:element</code> element is a template for the
  2093. attributes and children of the created element.</p>
  2094.  
  2095. <p>The <code>name</code> attribute is interpreted as an <termref
  2096. def="dt-attribute-value-template">attribute value template</termref>.
  2097. It is an error if the string that results from instantiating the
  2098. attribute value template is not a <xnt
  2099. href="&XMLNames;#NT-QName">QName</xnt>.  An XSLT processor may signal
  2100. the error; if it does not signal the error, then it must recover
  2101. by making the the result of instantiating the <code>xsl:element</code>
  2102. element be the sequence of nodes created by instantiating
  2103. the content of the  <code>xsl:element</code> element, excluding
  2104. any initial attribute nodes. If the <code>namespace</code> attribute is
  2105. not present then the <xnt href="&XMLNames;#NT-QName">QName</xnt> is
  2106. expanded into an expanded-name using the namespace declarations in
  2107. effect for the <code>xsl:element</code> element, including any default
  2108. namespace declaration.</p>
  2109.  
  2110. <p>If the <code>namespace</code> attribute is present, then it also is
  2111. interpreted as an <termref def="dt-attribute-value-template">attribute
  2112. value template</termref>. The string that results from instantiating
  2113. the attribute value template should be a URI reference.  It is not an
  2114. error if the string is not a syntactically legal URI reference.  If
  2115. the string is empty, then the expanded-name of the element has a null
  2116. namespace URI.  Otherwise, the string is used as the namespace URI of
  2117. the expanded-name of the element to be created. The local part of the
  2118. <xnt href="&XMLNames;#NT-QName">QName</xnt> specified by the
  2119. <code>name</code> attribute is used as the local part of the
  2120. expanded-name of the element to be created.</p>
  2121.  
  2122. <p>XSLT processors may make use of the prefix of the <xnt
  2123. href="&XMLNames;#NT-QName">QName</xnt> specified in the
  2124. <code>name</code> attribute when selecting the prefix used for
  2125. outputting the created element as XML; however, they are not required
  2126. to do so.</p>
  2127.  
  2128. </div3>
  2129.  
  2130. <div3 id="creating-attributes">
  2131. <head>Creating Attributes with <code>xsl:attribute</code></head>
  2132.  
  2133. <e:element-syntax name="attribute">
  2134.   <e:in-category name="instruction"/>
  2135.   <e:attribute name="name" required="yes">
  2136.     <e:attribute-value-template>
  2137.       <e:data-type name="qname"/>
  2138.     </e:attribute-value-template>
  2139.   </e:attribute>
  2140.   <e:attribute name="namespace">
  2141.     <e:attribute-value-template>
  2142.       <e:data-type name="uri-reference"/>
  2143.     </e:attribute-value-template>
  2144.   </e:attribute>
  2145.   <e:model name="template"/>
  2146. </e:element-syntax>
  2147.  
  2148. <p>The <code>xsl:attribute</code> element can be used to add
  2149. attributes to result elements whether created by literal result
  2150. elements in the stylesheet or by instructions such as
  2151. <code>xsl:element</code>. The <xtermref
  2152. href="&XPath;#dt-expanded-name">expanded-name</xtermref> of the
  2153. attribute to be created is specified by a required <code>name</code>
  2154. attribute and an optional <code>namespace</code> attribute.
  2155. Instantiating an <code>xsl:attribute</code> element adds an attribute
  2156. node to the containing result element node. The content of the
  2157. <code>xsl:attribute</code> element is a template for the value of the
  2158. created attribute.</p>
  2159.  
  2160. <p>The <code>name</code> attribute is interpreted as an <termref
  2161. def="dt-attribute-value-template">attribute value template</termref>.
  2162. It is an error if the string that results from instantiating the
  2163. attribute value template is not a <xnt
  2164. href="&XMLNames;#NT-QName">QName</xnt> or is the string
  2165. <code>xmlns</code>.  An XSLT processor may signal the error; if it
  2166. does not signal the error, it must recover by not adding the attribute
  2167. to the result tree. If the <code>namespace</code> attribute is not
  2168. present, then the <xnt href="&XMLNames;#NT-QName">QName</xnt> is
  2169. expanded into an expanded-name using the namespace declarations in
  2170. effect for the <code>xsl:attribute</code> element, <emph>not</emph>
  2171. including any default namespace declaration.</p>
  2172.  
  2173. <p>If the <code>namespace</code> attribute is present, then it also is
  2174. interpreted as an <termref def="dt-attribute-value-template">attribute
  2175. value template</termref>. The string that results from instantiating
  2176. it should be a URI reference.  It is not an error if the string is not
  2177. a syntactically legal URI reference.  If the string is empty, then the
  2178. expanded-name of the attribute has a null namespace URI.  Otherwise,
  2179. the string is used as the namespace URI of the expanded-name of the
  2180. attribute to be created. The local part of the <xnt
  2181. href="&XMLNames;#NT-QName">QName</xnt> specified by the
  2182. <code>name</code> attribute is used as the local part of the
  2183. expanded-name of the attribute to be created.</p>
  2184.  
  2185. <p>XSLT processors may make use of the prefix of the <xnt
  2186. href="&XMLNames;#NT-QName">QName</xnt> specified in the
  2187. <code>name</code> attribute when selecting the prefix used for
  2188. outputting the created attribute as XML; however, they are not
  2189. required to do so and, if the prefix is <code>xmlns</code>, they must
  2190. not do so. Thus, although it is not an error to do:</p>
  2191.  
  2192. <eg><xsl:attribute name="xmlns:xsl" namespace="whatever">&XSLT.ns;</xsl:attribute></eg>
  2193.  
  2194. <p>it will not result in a namespace declaration being output.</p>
  2195.  
  2196. <p>Adding an attribute to an element replaces any existing attribute
  2197. of that element with the same expanded-name.</p>
  2198.  
  2199. <p>The following are all errors:</p>
  2200.  
  2201. <ulist>
  2202.  
  2203. <item><p>Adding an attribute to an element after children have been
  2204. added to it; implementations may either signal the error or ignore the
  2205. attribute.</p></item>
  2206.  
  2207. <item><p>Adding an attribute to a node that is not an element;
  2208. implementations may either signal the error or ignore the
  2209. attribute.</p></item>
  2210.  
  2211. <item><p>Creating nodes other than text nodes during the
  2212. instantiation of the content of the <code>xsl:attribute</code>
  2213. element; implementations may either signal the error or ignore the
  2214. offending nodes.</p></item>
  2215.  
  2216. </ulist>
  2217.  
  2218. <note><p>When an <code>xsl:attribute</code> contains a text node with
  2219. a newline, then the XML output must contain a character reference.
  2220. For example,</p>
  2221.  
  2222. <eg><![CDATA[<xsl:attribute name="a">x
  2223. y</xsl:attribute>]]></eg>
  2224.  
  2225. <p>will result in the output</p>
  2226.  
  2227. <eg><![CDATA[a="x y"]]></eg>
  2228.  
  2229. <p>(or with any equivalent character reference). The XML output cannot
  2230. be</p>
  2231.  
  2232. <eg><![CDATA[a="x
  2233. y"]]></eg>
  2234.  
  2235. <p>This is because XML 1.0 requires newline characters in attribute
  2236. values to be normalized into spaces but requires character references
  2237. to newline characters not to be normalized.  The attribute values in
  2238. the data model represent the attribute value after normalization.  If
  2239. a newline occurring in an attribute value in the tree were output as a
  2240. newline character rather than as character reference, then the
  2241. attribute value in the tree created by reparsing the XML would contain
  2242. a space not a newline, which would mean that the tree had not been
  2243. output correctly.</p></note>
  2244.  
  2245. </div3>
  2246.  
  2247. <div3 id="attribute-sets">
  2248.  
  2249. <head>Named Attribute Sets</head>
  2250.  
  2251. <e:element-syntax name="attribute-set">
  2252.   <e:in-category name="top-level-element"/>
  2253.   <e:attribute name="name" required="yes">
  2254.     <e:data-type name="qname"/>
  2255.   </e:attribute>
  2256.   <e:attribute name="use-attribute-sets">
  2257.     <e:data-type name="qnames"/>
  2258.   </e:attribute>
  2259.   <e:element repeat="zero-or-more" name="attribute"/>
  2260. </e:element-syntax>
  2261.  
  2262. <p>The <code>xsl:attribute-set</code> element defines a named set of
  2263. attributes.  The <code>name</code> attribute specifies the name of the
  2264. attribute set.  The value of the <code>name</code> attribute is a <xnt
  2265. href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
  2266. in <specref ref="qname"/>. The content of the <code>xsl:attribute-set</code>
  2267. element consists of zero or more <code>xsl:attribute</code> elements
  2268. that specify the attributes in the set.</p>
  2269.  
  2270. <p>Attribute sets are used by specifying a
  2271. <code>use-attribute-sets</code> attribute on <code>xsl:element</code>,
  2272. <code>xsl:copy</code> (see <specref ref="copying"/>) or
  2273. <code>xsl:attribute-set</code> elements.  The value of the
  2274. <code>use-attribute-sets</code> attribute is a whitespace-separated
  2275. list of names of attribute sets.  Each name is specified as a <xnt
  2276. href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
  2277. in <specref ref="qname"/>.  Specifying a
  2278. <code>use-attribute-sets</code> attribute is equivalent to adding
  2279. <code>xsl:attribute</code> elements for each of the attributes in each
  2280. of the named attribute sets to the beginning of the content of the
  2281. element with the <code>use-attribute-sets</code> attribute, in the
  2282. same order in which the names of the attribute sets are specified in
  2283. the <code>use-attribute-sets</code> attribute.  It is an error if use
  2284. of <code>use-attribute-sets</code> attributes on
  2285. <code>xsl:attribute-set</code> elements causes an attribute set to
  2286. directly or indirectly use itself.</p>
  2287.  
  2288. <p>Attribute sets can also be used by specifying an
  2289. <code>xsl:use-attribute-sets</code> attribute on a literal result
  2290. element.  The value of the <code>xsl:use-attribute-sets</code>
  2291. attribute is a whitespace-separated list of names of attribute sets.
  2292. The <code>xsl:use-attribute-sets</code> attribute has the same effect
  2293. as the <code>use-attribute-sets</code> attribute on
  2294. <code>xsl:element</code> with the additional rule that attributes
  2295. specified on the literal result element itself are treated as if they
  2296. were specified by <code>xsl:attribute</code> elements before any
  2297. actual <code>xsl:attribute</code> elements but after any
  2298. <code>xsl:attribute</code> elements implied by the
  2299. <code>xsl:use-attribute-sets</code> attribute.  Thus, for a literal
  2300. result element, attributes from attribute sets named in an
  2301. <code>xsl:use-attribute-sets</code> attribute will be added first, in
  2302. the order listed in the attribute; next, attributes specified on the
  2303. literal result element will be added; finally, any attributes
  2304. specified by <code>xsl:attribute</code> elements will be added.  Since
  2305. adding an attribute to an element replaces any existing attribute of
  2306. that element with the same name, this means that attributes specified
  2307. in attribute sets can be overridden by attributes specified on the
  2308. literal result element itself.</p>
  2309.  
  2310. <p>The template within each <code>xsl:attribute</code> element in an
  2311. <code>xsl:attribute-set</code> element is instantiated each time the
  2312. attribute set is used; it is instantiated using the same current node
  2313. and current node list as is used for instantiating the element bearing
  2314. the <code>use-attribute-sets</code> or
  2315. <code>xsl:use-attribute-sets</code> attribute. However, it is the
  2316. position in the stylesheet of the <code>xsl:attribute</code> element
  2317. rather than of the element bearing the <code>use-attribute-sets</code>
  2318. or <code>xsl:use-attribute-sets</code> attribute that determines which
  2319. variable bindings are visible (see <specref ref="variables"/>); thus,
  2320. only variables and parameters declared by <termref
  2321. def="dt-top-level">top-level</termref> <code>xsl:variable</code> and
  2322. <code>xsl:param</code> elements are visible.</p>
  2323.  
  2324. <p>The following example creates a named attribute set
  2325. <code>title-style</code> and uses it in a template rule.</p>
  2326.  
  2327. <eg><![CDATA[<xsl:template match="chapter/heading">
  2328.   <fo:block quadding="start" xsl:use-attribute-sets="title-style">
  2329.     <xsl:apply-templates/>
  2330.   </fo:block>
  2331. </xsl:template>
  2332.  
  2333. <xsl:attribute-set name="title-style">
  2334.   <xsl:attribute name="font-size">12pt</xsl:attribute>
  2335.   <xsl:attribute name="font-weight">bold</xsl:attribute>
  2336. </xsl:attribute-set>]]></eg>
  2337.  
  2338. <p>Multiple definitions of an attribute set with the same
  2339. expanded-name are merged.  An attribute from a definition that has
  2340. higher <termref def="dt-import-precedence">import precedence</termref>
  2341. takes precedence over an attribute from a definition that has lower
  2342. <termref def="dt-import-precedence">import precedence</termref>.  It
  2343. is an error if there are two attribute sets that have the same
  2344. expanded-name and equal import precedence and that both contain
  2345. the same attribute, unless there is a definition of the attribute set
  2346. with higher <termref def="dt-import-precedence">import
  2347. precedence</termref> that also contains the attribute.  An XSLT
  2348. processor may signal the error; if it does not signal the error, it
  2349. must recover by choosing from amongst the definitions that specify the
  2350. attribute that have the highest import precedence the one that was
  2351. specified last in the stylesheet.  Where the attributes in an
  2352. attribute set were specified is relevant only in merging the
  2353. attributes into the attribute set; it makes no difference when the
  2354. attribute set is used.</p>
  2355.  
  2356. </div3>
  2357.  
  2358. </div2>
  2359.  
  2360. <div2>
  2361.  
  2362. <head>Creating Text</head>
  2363.  
  2364. <p>A template can also contain text nodes.  Each text node in a
  2365. template remaining after whitespace has been stripped as specified in
  2366. <specref ref="strip"/> will create a text node with the same
  2367. string-value in the result tree.  Adjacent text nodes in the result
  2368. tree are automatically merged.</p>
  2369.  
  2370. <p>Note that text is processed at the tree level. Thus, markup of
  2371. <code>&lt;</code> in a template will be represented in the
  2372. stylesheet tree by a text node that includes the character
  2373. <code><</code>. This will create a text node in the result tree
  2374. that contains a <code><</code> character, which will be represented
  2375. by the markup <code>&lt;</code> (or an equivalent character
  2376. reference) when the result tree is externalized as an XML document
  2377. (unless output escaping is disabled as described in <specref
  2378. ref="disable-output-escaping"/>).</p>
  2379.  
  2380. <e:element-syntax name="text">
  2381.   <e:in-category name="instruction"/>
  2382.   <e:attribute name="disable-output-escaping">
  2383.     <e:constant value="yes"/>
  2384.     <e:constant value="no"/>
  2385.   </e:attribute>
  2386.   <e:text/>  
  2387. </e:element-syntax>
  2388.  
  2389. <p>Literal data characters may also be wrapped in an
  2390. <code>xsl:text</code> element.  This wrapping may change what
  2391. whitespace characters are stripped (see <specref ref="strip"/>) but
  2392. does not affect how the characters are handled by the XSLT processor
  2393. thereafter.</p>
  2394.  
  2395. <note><p>The <code>xml:lang</code> and <code>xml:space</code>
  2396. attributes are not treated specially by XSLT. In particular,</p>
  2397.  
  2398. <ulist>
  2399. <item><p>it is the responsibility of the stylesheet author explicitly
  2400. to generate any <code>xml:lang</code> or <code>xml:space</code>
  2401. attributes that are needed in the result;</p></item>
  2402.  
  2403. <item><p>specifying an <code>xml:lang</code> or <code>xml:space</code>
  2404. attribute on an element in the XSLT namespace will not cause any
  2405. <code>xml:lang</code> or <code>xml:space</code> attributes to appear
  2406. in the result.</p></item>
  2407. </ulist>
  2408. </note>
  2409.  
  2410. </div2>
  2411.  
  2412.  
  2413. <div2>
  2414. <head>Creating Processing Instructions</head>
  2415.  
  2416.  
  2417. <e:element-syntax name="processing-instruction">
  2418.   <e:in-category name="instruction"/>
  2419.   <e:attribute name="name" required="yes">
  2420.     <e:attribute-value-template>
  2421.       <e:data-type name="ncname"/>
  2422.     </e:attribute-value-template>
  2423.   </e:attribute>
  2424.   <e:model name="template"/>
  2425. </e:element-syntax>
  2426.  
  2427. <p>The <code>xsl:processing-instruction</code> element is instantiated
  2428. to create a processing instruction node.  The content of the
  2429. <code>xsl:processing-instruction</code> element is a template for the
  2430. string-value of the processing instruction node.  The
  2431. <code>xsl:processing-instruction</code> element has a required
  2432. <code>name</code> attribute that specifies the name of the processing
  2433. instruction node.  The value of the <code>name</code> attribute is
  2434. interpreted as an <termref def="dt-attribute-value-template">attribute
  2435. value template</termref>.</p>
  2436.  
  2437. <p>For example, this</p>
  2438.  
  2439. <eg><![CDATA[<xsl:processing-instruction name="xml-stylesheet">href="book.css" type="text/css"</xsl:processing-instruction>]]></eg>
  2440.  
  2441. <p>would create the processing instruction</p>
  2442.  
  2443. <eg><![CDATA[<?xml-stylesheet href="book.css" type="text/css"?>]]></eg>
  2444.  
  2445. <p>It is an error if the string that results from instantiating the
  2446. <code>name</code> attribute is not both an <xnt
  2447. href="&XMLNames;#NT-NCName">NCName</xnt> and a <xnt
  2448. href="&XML;#NT-PITarget">PITarget</xnt>.  An XSLT processor may signal
  2449. the error; if it does not signal the error, it must recover by not
  2450. adding the processing instruction to the result tree.</p>
  2451.  
  2452. <note><p>This means that <code>xsl:processing-instruction</code>
  2453. cannot be used to output an XML declaration.  The
  2454. <code>xsl:output</code> element should be used instead (see <specref
  2455. ref="output"/>).</p></note>
  2456.  
  2457. <p>It is an error if instantiating the content of
  2458. <code>xsl:processing-instruction</code> creates nodes other than
  2459. text nodes.  An XSLT processor may signal the error; if it does not
  2460. signal the error, it must recover by ignoring the offending nodes
  2461. together with their content.</p>
  2462.  
  2463. <p>It is an error if the result of instantiating the content of the
  2464. <code>xsl:processing-instruction</code> contains the string
  2465. <code>?></code>.  An XSLT processor may signal the error; if it does
  2466. not signal the error, it must recover by inserting a space after any
  2467. occurrence of <code>?</code> that is followed by a <code>></code>.</p>
  2468.  
  2469. </div2>
  2470.  
  2471. <div2>
  2472. <head>Creating Comments</head>
  2473.  
  2474. <e:element-syntax name="comment">
  2475.   <e:in-category name="instruction"/>
  2476.   <e:model name="template"/>
  2477. </e:element-syntax>
  2478.  
  2479. <p>The <code>xsl:comment</code> element is instantiated to create a
  2480. comment node in the result tree.  The content of the
  2481. <code>xsl:comment</code> element is a template for the string-value of
  2482. the comment node.</p>
  2483.  
  2484. <p>For example, this</p>
  2485.  
  2486. <eg><![CDATA[<xsl:comment>This file is automatically generated. Do not edit!</xsl:comment>]]></eg>
  2487.  
  2488. <p>would create the comment</p>
  2489.  
  2490. <eg><![CDATA[<!--This file is automatically generated. Do not edit!-->]]></eg>
  2491.  
  2492. <p>It is an error if instantiating the content of
  2493. <code>xsl:comment</code> creates nodes other than text nodes.  An
  2494. XSLT processor may signal the error; if it does not signal the error,
  2495. it must recover by ignoring the offending nodes together with their
  2496. content.</p>
  2497.  
  2498. <p>It is an error if the result of instantiating the content of the
  2499. <code>xsl:comment</code> contains the string <code>--</code> or ends
  2500. with <code>-</code>.  An XSLT processor may signal the error; if it
  2501. does not signal the error, it must recover by inserting a space after
  2502. any occurrence of <code>-</code> that is followed by another
  2503. <code>-</code> or that ends the comment.</p>
  2504.  
  2505. </div2>
  2506.  
  2507. <div2 id="copying">
  2508. <head>Copying</head>
  2509.  
  2510. <e:element-syntax name="copy">
  2511.   <e:in-category name="instruction"/>
  2512.   <e:attribute name="use-attribute-sets">
  2513.     <e:data-type name="qnames"/>
  2514.   </e:attribute>
  2515.   <e:model name="template"/>
  2516. </e:element-syntax>
  2517.  
  2518. <p>The <code>xsl:copy</code> element provides an easy way of copying
  2519. the current node. Instantiating the <code>xsl:copy</code> element
  2520. creates a copy of the current node.  The namespace nodes of the
  2521. current node are automatically copied as well, but the attributes and
  2522. children of the node are not automatically copied.  The content of the
  2523. <code>xsl:copy</code> element is a template for the attributes and
  2524. children of the created node; the content is instantiated only for
  2525. nodes of types that can have attributes or children (i.e. root
  2526. nodes and element nodes).</p>
  2527.  
  2528. <p>The <code>xsl:copy</code> element may have a
  2529. <code>use-attribute-sets</code> attribute (see <specref
  2530. ref="attribute-sets"/>). This is used only when copying element
  2531. nodes.</p>
  2532.  
  2533. <p>The root node is treated specially because the root node of the
  2534. result tree is created implicitly.  When the current node is the root
  2535. node, <code>xsl:copy</code> will not create a root node, but will just
  2536. use the content template.</p>
  2537.  
  2538. <p>For example, the identity transformation can be written using
  2539. <code>xsl:copy</code> as follows:</p>
  2540.  
  2541. <eg><![CDATA[<xsl:template match="@*|node()">
  2542.   <xsl:copy>
  2543.     <xsl:apply-templates select="@*|node()"/>
  2544.   </xsl:copy>
  2545. </xsl:template>]]></eg>
  2546.  
  2547. <p>When the current node is an attribute, then if it would be an error
  2548. to use <code>xsl:attribute</code> to create an attribute with the same
  2549. name as the current node, then it is also an error to use
  2550. <code>xsl:copy</code> (see <specref ref="creating-attributes"/>).</p>
  2551.  
  2552. <p>The following example shows how <code>xml:lang</code> attributes
  2553. can be easily copied through from source to result. If a stylesheet
  2554. defines the following named template:</p>
  2555.  
  2556. <eg><![CDATA[<xsl:template name="apply-templates-copy-lang">
  2557.  <xsl:for-each select="@xml:lang">
  2558.    <xsl:copy/>
  2559.  </xsl:for-each>
  2560.  <xsl:apply-templates/>
  2561. </xsl:template>]]></eg>
  2562.  
  2563. <p>then it can simply do</p>
  2564.  
  2565. <eg><![CDATA[<xsl:call-template name="apply-templates-copy-lang"/>]]></eg>
  2566.  
  2567. <p>instead of</p>
  2568.  
  2569. <eg><![CDATA[<xsl:apply-templates/>]]></eg>
  2570.  
  2571. <p>when it wants to copy the <code>xml:lang</code> attribute.</p>
  2572.  
  2573. </div2>
  2574.  
  2575. <div2>
  2576. <head>Computing Generated Text</head>
  2577.  
  2578. <p>Within a template, the <code>xsl:value-of</code> element can be
  2579. used to compute generated text, for example by extracting text from
  2580. the source tree or by inserting the value of a variable.  The
  2581. <code>xsl:value-of</code> element does this with an <termref
  2582. def="dt-expression">expression</termref> that is specified as the
  2583. value of the <code>select</code> attribute.  Expressions can
  2584. also be used inside attribute values of literal result elements by
  2585. enclosing the expression in curly braces (<code>{}</code>).</p>
  2586.  
  2587. <div3 id="value-of">
  2588. <head>Generating Text with <code>xsl:value-of</code></head>
  2589.  
  2590. <e:element-syntax name="value-of">
  2591.   <e:in-category name="instruction"/>
  2592.   <e:attribute name="select" required="yes">
  2593.     <e:data-type name="string-expression"/>
  2594.   </e:attribute>
  2595.   <e:attribute name="disable-output-escaping">
  2596.     <e:constant value="yes"/>
  2597.     <e:constant value="no"/>
  2598.   </e:attribute>
  2599.   <e:empty/>
  2600. </e:element-syntax>
  2601.  
  2602. <p>The <code>xsl:value-of</code> element is instantiated to create a
  2603. text node in the result tree.  The required <code>select</code>
  2604. attribute is an <termref def="dt-expression">expression</termref>;
  2605. this expression is evaluated and the resulting object is converted to
  2606. a string as if by a call to the <xfunction>string</xfunction>
  2607. function. The string specifies the string-value of the created text
  2608. node.  If the string is empty, no text node will be created.  The
  2609. created text node will be merged with any adjacent text nodes.</p>
  2610.  
  2611. <p>The <code>xsl:copy-of</code> element can be used to copy a node-set
  2612. over to the result tree without converting it to a string. See <specref
  2613. ref="copy-of"/>.</p>
  2614.  
  2615. <p>For example, the following creates an HTML paragraph from a
  2616. <code>person</code> element with <code>given-name</code> and
  2617. <code>family-name</code> attributes.  The paragraph will contain the value
  2618. of the <code>given-name</code> attribute of the current node followed
  2619. by a space and the value of the <code>family-name</code> attribute of the
  2620. current node.</p>
  2621.  
  2622. <eg><![CDATA[<xsl:template match="person">
  2623.   <p>
  2624.    <xsl:value-of select="@given-name"/>
  2625.    <xsl:text> </xsl:text>
  2626.    <xsl:value-of select="@family-name"/>
  2627.   </p>
  2628. </xsl:template>]]></eg>
  2629.  
  2630. <p>For another example, the following creates an HTML paragraph from a
  2631. <code>person</code> element with <code>given-name</code> and
  2632. <code>family-name</code> children elements.  The paragraph will
  2633. contain the string-value of the first <code>given-name</code> child
  2634. element of the current node followed by a space and the string-value
  2635. of the first <code>family-name</code> child element of the current
  2636. node.</p>
  2637.  
  2638. <eg><![CDATA[<xsl:template match="person">
  2639.   <p>
  2640.    <xsl:value-of select="given-name"/>
  2641.    <xsl:text> </xsl:text>
  2642.    <xsl:value-of select="family-name"/>
  2643.   </p>
  2644. </xsl:template>]]></eg>
  2645.  
  2646. <p>The following precedes each <code>procedure</code> element with a
  2647. paragraph containing the security level of the procedure.  It assumes
  2648. that the security level that applies to a procedure is determined by a
  2649. <code>security</code> attribute on the procedure element or on an
  2650. ancestor element of the procedure. It also assumes that if more than
  2651. one such element has a <code>security</code> attribute then the
  2652. security level is determined by the element that is closest to the
  2653. procedure.</p>
  2654.  
  2655. <eg><![CDATA[<xsl:template match="procedure">
  2656.   <fo:block>
  2657.     <xsl:value-of select="ancestor-or-self::*[@security][1]/@security"/>
  2658.   </fo:block>
  2659.   <xsl:apply-templates/>
  2660. </xsl:template>]]></eg>
  2661.  
  2662. </div3>
  2663.  
  2664. <div3 id="attribute-value-templates">
  2665. <head>Attribute Value Templates</head>
  2666.  
  2667. <p><termdef id="dt-attribute-value-template" term="Attribute Value
  2668. Template">In an attribute value that is interpreted as an
  2669. <term>attribute value template</term>, such as an attribute of a
  2670. literal result element, an <termref
  2671. def="dt-expression">expression</termref> can be used by surrounding
  2672. the expression with curly braces (<code>{}</code>)</termdef>.  The
  2673. attribute value template is instantiated by replacing the expression
  2674. together with surrounding curly braces by the result of evaluating the
  2675. expression and converting the resulting object to a string as if by a
  2676. call to the <xfunction>string</xfunction> function.  Curly braces are
  2677. not recognized in an attribute value in an XSLT stylesheet unless the
  2678. attribute is specifically stated to be one that is interpreted as an
  2679. attribute value template; in an element syntax summary, the value
  2680. of such attributes is surrounded by curly braces.</p>
  2681.  
  2682. <note><p>Not all attributes are interpreted as attribute value
  2683. templates.  Attributes whose value is an expression or pattern,
  2684. attributes of <termref def="dt-top-level">top-level</termref> elements
  2685. and attributes that refer to named XSLT objects are not interpreted as
  2686. attribute value templates. In addition, <code>xmlns</code> attributes
  2687. are not interpreted as attribute value templates; it would not be
  2688. conformant with the XML Namespaces Recommendation to do
  2689. this.</p></note>
  2690.  
  2691. <p>The following example creates an <code>img</code> result element
  2692. from a <code>photograph</code> element in the source; the value of the
  2693. <code>src</code> attribute of the <code>img</code> element is computed
  2694. from the value of the <code>image-dir</code> variable and the
  2695. string-value of the <code>href</code> child of the
  2696. <code>photograph</code> element; the value of the <code>width</code>
  2697. attribute of the <code>img</code> element is computed from the value
  2698. of the <code>width</code> attribute of the <code>size</code> child of
  2699. the <code>photograph</code> element:</p>
  2700.  
  2701. <eg><![CDATA[<xsl:variable name="image-dir">/images</xsl:variable>
  2702.  
  2703. <xsl:template match="photograph">
  2704. <img src="{$image-dir}/{href}" width="{size/@width}"/>
  2705. </xsl:template>]]></eg>
  2706.  
  2707. <p>With this source</p>
  2708.  
  2709. <eg><![CDATA[<photograph>
  2710.   <href>headquarters.jpg</href>
  2711.   <size width="300"/>
  2712. </photograph>]]></eg>
  2713.  
  2714. <p>the result would be</p>
  2715.  
  2716. <eg><![CDATA[<img src="/images/headquarters.jpg" width="300"/>]]></eg>
  2717.  
  2718. <p>When an attribute value template is instantiated, a double left or
  2719. right curly brace outside an expression will be replaced by a single
  2720. curly brace.  It is an error if a right curly brace occurs in an
  2721. attribute value template outside an expression without being followed
  2722. by a second right curly brace.  A right curly brace inside a <xnt
  2723. href="&XPath;#NT-Literal">Literal</xnt> in an expression is not
  2724. recognized as terminating the expression.</p>
  2725.  
  2726. <p>Curly braces are <emph>not</emph> recognized recursively inside
  2727. expressions.  For example:</p>
  2728.  
  2729. <eg role="error"><![CDATA[<a href="#{id({@ref})/title}">]]></eg>
  2730.  
  2731. <p>is <emph>not</emph> allowed.  Instead, use simply:</p>
  2732.  
  2733. <eg><![CDATA[<a href="#{id(@ref)/title}">]]></eg>
  2734.  
  2735. </div3>
  2736.  
  2737. </div2>
  2738.  
  2739. <div2 id="number">
  2740. <head>Numbering</head>
  2741.  
  2742. <e:element-syntax name="number">
  2743.   <e:in-category name="instruction"/>
  2744.   <e:attribute name="level">
  2745.     <e:constant value="single"/>
  2746.     <e:constant value="multiple"/>
  2747.     <e:constant value="any"/>
  2748.   </e:attribute>
  2749.   <e:attribute name="count">
  2750.     <e:data-type name="pattern"/>
  2751.   </e:attribute>
  2752.   <e:attribute name="from">
  2753.     <e:data-type name="pattern"/>
  2754.   </e:attribute>
  2755.   <e:attribute name="value">
  2756.     <e:data-type name="number-expression"/>
  2757.   </e:attribute>
  2758.   <e:attribute name="format">
  2759.     <e:attribute-value-template>
  2760.       <e:data-type name="string"/>
  2761.     </e:attribute-value-template>
  2762.   </e:attribute>
  2763.   <e:attribute name="lang">
  2764.     <e:attribute-value-template>
  2765.       <e:data-type name="nmtoken"/>
  2766.     </e:attribute-value-template>
  2767.   </e:attribute>
  2768.   <e:attribute name="letter-value">
  2769.     <e:attribute-value-template>
  2770.       <e:constant value="alphabetic"/>
  2771.       <e:constant value="traditional"/>
  2772.     </e:attribute-value-template>
  2773.   </e:attribute>
  2774.   <e:attribute name="grouping-separator">
  2775.     <e:attribute-value-template>
  2776.       <e:data-type name="char"/>
  2777.     </e:attribute-value-template>
  2778.   </e:attribute>
  2779.   <e:attribute name="grouping-size">
  2780.     <e:attribute-value-template>
  2781.       <e:data-type name="number"/>
  2782.     </e:attribute-value-template>
  2783.   </e:attribute>
  2784.   <e:empty/>
  2785. </e:element-syntax>
  2786.  
  2787. <p>The <code>xsl:number</code> element is used to insert a formatted
  2788. number into the result tree.  The number to be inserted may be
  2789. specified by an expression. The <code>value</code> attribute contains
  2790. an <termref def="dt-expression">expression</termref>.  The expression
  2791. is evaluated and the resulting object is converted to a number as if
  2792. by a call to the <xfunction>number</xfunction> function.  The number is
  2793. rounded to an integer and then converted to a string using the
  2794. attributes specified in <specref ref="convert"/>; in this
  2795. context, the value of each of these attributes is
  2796. interpreted as an <termref def="dt-attribute-value-template">attribute
  2797. value template</termref>.  After conversion, the resulting string is
  2798. inserted in the result tree. For example, the following example
  2799. numbers a sorted list:</p>
  2800.  
  2801. <eg><![CDATA[<xsl:template match="items">
  2802.   <xsl:for-each select="item">
  2803.     <xsl:sort select="."/>
  2804.     <p>
  2805.       <xsl:number value="position()" format="1. "/>
  2806.       <xsl:value-of select="."/>
  2807.     </p>
  2808.   </xsl:for-each>
  2809. </xsl:template>]]></eg>
  2810.  
  2811. <p>If no <code>value</code> attribute is specified, then the
  2812. <code>xsl:number</code> element inserts a number based on the position
  2813. of the current node in the source tree. The following attributes
  2814. control how the current node is to be numbered:</p>
  2815.  
  2816. <ulist>
  2817.  
  2818. <item><p>The <code>level</code> attribute specifies what levels of the
  2819. source tree should be considered; it has the values
  2820. <code>single</code>, <code>multiple</code> or <code>any</code>. The
  2821. default is <code>single</code>.</p></item>
  2822.  
  2823. <item><p>The <code>count</code> attribute is a pattern that specifies
  2824. what nodes should be counted at those levels.  If <code>count</code>
  2825. attribute is not specified, then it defaults to the pattern that
  2826. matches any node with the same node type as the current node and, if
  2827. the current node has an expanded-name, with the same expanded-name as
  2828. the current node.</p></item>
  2829.  
  2830. <item><p>The <code>from</code> attribute is a pattern that specifies
  2831. where counting starts.</p></item>
  2832.  
  2833. </ulist>
  2834.  
  2835. <p>In addition, the attributes specified in <specref ref="convert"/>
  2836. are used for number to string conversion, as in the case when the
  2837. <code>value</code> attribute is specified.</p>
  2838.  
  2839. <p>The <code>xsl:number</code> element first constructs a list of
  2840. positive integers using the <code>level</code>, <code>count</code> and
  2841. <code>from</code> attributes:</p>
  2842.  
  2843. <ulist>
  2844.  
  2845. <item><p>When <code>level="single"</code>, it goes up to the first
  2846. node in the ancestor-or-self axis that matches
  2847. the <code>count</code> pattern, and constructs a list of length one
  2848. containing one plus the number of preceding siblings of that ancestor
  2849. that match the <code>count</code> pattern. If there is no such
  2850. ancestor, it constructs an empty list.  If the <code>from</code>
  2851. attribute is specified, then the only ancestors that are searched are
  2852. those that are descendants of the nearest ancestor that matches the
  2853. <code>from</code> pattern. Preceding siblings has the same meaning
  2854. here as with the <code>preceding-sibling</code> axis.</p></item>
  2855.  
  2856. <item><p>When <code>level="multiple"</code>, it constructs a list of all
  2857. ancestors of the current node in document order followed by the
  2858. element itself; it then selects from the list those nodes that match
  2859. the <code>count</code> pattern; it then maps each node in the list to
  2860. one plus the number of preceding siblings of that node that match the
  2861. <code>count</code> pattern.  If the <code>from</code> attribute is
  2862. specified, then the only ancestors that are searched are those that
  2863. are descendants of the nearest ancestor that matches the
  2864. <code>from</code> pattern. Preceding siblings has the same meaning
  2865. here as with the <code>preceding-sibling</code> axis.</p></item>
  2866.  
  2867. <item><p>When <code>level="any"</code>, it constructs a list of length
  2868. one containing the number of nodes that match the <code>count</code>
  2869. pattern and belong to the set containing the current node and all
  2870. nodes at any level of the document that are before the current node in
  2871. document order, excluding any namespace and attribute nodes (in other
  2872. words the union of the members of the <code>preceding</code> and
  2873. <code>ancestor-or-self</code> axes). If the <code>from</code>
  2874. attribute is specified, then only nodes after the first node before
  2875. the current node that match the <code>from</code> pattern are
  2876. considered.</p></item>
  2877.  
  2878. </ulist>
  2879.  
  2880. <p>The list of numbers is then converted into a string using the
  2881. attributes specified in <specref ref="convert"/>; in this
  2882. context, the value of each of these attributes is
  2883. interpreted as an <termref def="dt-attribute-value-template">attribute
  2884. value template</termref>.  After conversion, the resulting string is
  2885. inserted in the result tree.</p>
  2886.  
  2887. <p>The following would number the items in an ordered list:</p>
  2888.  
  2889. <eg><![CDATA[<xsl:template match="ol/item">
  2890.   <fo:block>
  2891.     <xsl:number/><xsl:text>. </xsl:text><xsl:apply-templates/>
  2892.   </fo:block>
  2893. <xsl:template>]]></eg>
  2894.  
  2895. <p>The following two rules would number <code>title</code> elements.
  2896. This is intended for a document that contains a sequence of chapters
  2897. followed by a sequence of appendices, where both chapters and
  2898. appendices contain sections, which in turn contain subsections.
  2899. Chapters are numbered 1, 2, 3; appendices are numbered A, B, C;
  2900. sections in chapters are numbered 1.1, 1.2, 1.3; sections in
  2901. appendices are numbered A.1, A.2, A.3.</p>
  2902.  
  2903. <eg><![CDATA[<xsl:template match="title">
  2904.   <fo:block>
  2905.      <xsl:number level="multiple"
  2906.                  count="chapter|section|subsection"
  2907.                  format="1.1 "/>
  2908.      <xsl:apply-templates/>
  2909.   </fo:block>
  2910. </xsl:template>
  2911.  
  2912. <xsl:template match="appendix//title" priority="1">
  2913.   <fo:block>
  2914.      <xsl:number level="multiple"
  2915.                  count="appendix|section|subsection"
  2916.                  format="A.1 "/>
  2917.      <xsl:apply-templates/>
  2918.   </fo:block>
  2919. </xsl:template>]]></eg>
  2920.  
  2921. <p>The following example numbers notes sequentially within a
  2922. chapter:</p>
  2923.  
  2924. <eg><![CDATA[<xsl:template match="note">
  2925.   <fo:block>
  2926.      <xsl:number level="any" from="chapter" format="(1) "/>
  2927.      <xsl:apply-templates/>
  2928.   </fo:block>
  2929. </xsl:template>]]></eg>
  2930.  
  2931. <p>The following example would number <code>H4</code> elements in HTML
  2932. with a three-part label:</p>
  2933.  
  2934. <eg><![CDATA[<xsl:template match="H4">
  2935.  <fo:block>
  2936.    <xsl:number level="any" from="H1" count="H2"/>
  2937.    <xsl:text>.</xsl:text>
  2938.    <xsl:number level="any" from="H2" count="H3"/>
  2939.    <xsl:text>.</xsl:text>
  2940.    <xsl:number level="any" from="H3" count="H4"/>
  2941.    <xsl:text> </xsl:text>
  2942.    <xsl:apply-templates/>
  2943.  </fo:block>
  2944. </xsl:template>]]></eg>
  2945.  
  2946. <div3 id="convert">
  2947. <head>Number to String Conversion Attributes</head>
  2948.  
  2949. <p>The following attributes are used to control conversion of a list
  2950. of numbers into a string. The numbers are integers greater than
  2951. 0. The attributes are all optional.</p>
  2952.  
  2953. <p>The main attribute is <code>format</code>.  The default value for
  2954. the <code>format</code> attribute is <code>1</code>.  The
  2955. <code>format</code> attribute is split into a sequence of tokens where
  2956. each token is a maximal sequence of alphanumeric characters or a
  2957. maximal sequence of non-alphanumeric characters.  Alphanumeric means
  2958. any character that has a Unicode category of Nd, Nl, No, Lu, Ll, Lt,
  2959. Lm or Lo.  The alphanumeric tokens (format tokens) specify the format
  2960. to be used for each number in the list.  If the first token is a
  2961. non-alphanumeric token, then the constructed string will start with
  2962. that token; if the last token is non-alphanumeric token, then the
  2963. constructed string will end with that token.  Non-alphanumeric tokens
  2964. that occur between two format tokens are separator tokens that are
  2965. used to join numbers in the list.  The <var>n</var>th format token
  2966. will be used to format the <var>n</var>th number in the list.  If
  2967. there are more numbers than format tokens, then the last format token
  2968. will be used to format remaining numbers.  If there are no format
  2969. tokens, then a format token of <code>1</code> is used to format all
  2970. numbers.  The format token specifies the string to be used to
  2971. represent the number 1.  Each number after the first will be separated
  2972. from the preceding number by the separator token preceding the format
  2973. token used to format that number, or, if there are no separator
  2974. tokens, then by <code>.</code> (a period character).</p>
  2975.  
  2976. <p>Format tokens are a superset of the allowed values for the
  2977. <code>type</code> attribute for the <code>OL</code> element in HTML
  2978. 4.0 and are interpreted as follows:</p>
  2979.  
  2980. <ulist>
  2981.  
  2982. <item><p>Any token where the last character has a decimal digit value
  2983. of 1 (as specified in the Unicode character property database),
  2984. and the Unicode value of preceding characters is one less than the
  2985. Unicode value of the last character generates a decimal
  2986. representation of the number where each number is at least as long as
  2987. the format token.  Thus, a format token <code>1</code> generates the
  2988. sequence <code>1 2 ... 10 11 12 ...</code>, and a format token
  2989. <code>01</code> generates the sequence <code>01 02 ... 09 10 11 12
  2990. ... 99 100 101</code>.</p></item>
  2991.  
  2992. <item><p>A format token <code>A</code> generates the sequence <code>A
  2993. B C ... Z AA AB AC...</code>.</p></item>
  2994.  
  2995. <item><p>A format token <code>a</code> generates the sequence <code>a
  2996. b c ... z aa ab ac...</code>.</p></item>
  2997.  
  2998. <item><p>A format token <code>i</code> generates the sequence <code>i
  2999. ii iii iv v vi vii viii ix x ...</code>.</p></item>
  3000.  
  3001. <item><p>A format token <code>I</code> generates the sequence <code>I
  3002. II III IV V VI VII VIII IX X ...</code>.</p></item>
  3003.  
  3004. <item><p>Any other format token indicates a numbering sequence that
  3005. starts with that token.  If an implementation does not support a
  3006. numbering sequence that starts with that token, it must use a format
  3007. token of <code>1</code>.</p></item>
  3008.  
  3009. </ulist>
  3010.  
  3011. <p>When numbering with an alphabetic sequence, the <code>lang</code>
  3012. attribute specifies which language's alphabet is to be used; it has
  3013. the same range of values as <code>xml:lang</code> <bibref ref="XML"/>;
  3014. if no <code>lang</code> value is specified, the language should be
  3015. determined from the system environment.  Implementers should document
  3016. for which languages they support numbering.</p>
  3017.  
  3018. <note><p>Implementers should not make any assumptions about how
  3019. numbering works in particular languages and should properly research
  3020. the languages that they wish to support.  The numbering conventions of
  3021. many languages are very different from English.</p></note>
  3022.  
  3023. <p>The <code>letter-value</code> attribute disambiguates between
  3024. numbering sequences that use letters.  In many languages there are two
  3025. commonly used numbering sequences that use letters.  One numbering
  3026. sequence assigns numeric values to letters in alphabetic sequence, and
  3027. the other assigns numeric values to each letter in some other manner
  3028. traditional in that language.  In English, these would correspond to
  3029. the numbering sequences specified by the format tokens <code>a</code>
  3030. and <code>i</code>.  In some languages, the first member of each
  3031. sequence is the same, and so the format token alone would be
  3032. ambiguous.  A value of <code>alphabetic</code> specifies the
  3033. alphabetic sequence; a value of <code>traditional</code> specifies the
  3034. other sequence.  If the <code>letter-value</code> attribute is not
  3035. specified, then it is implementation-dependent how any ambiguity is
  3036. resolved.</p>
  3037.  
  3038. <note><p>It is possible for two conforming XSLT processors not to
  3039. convert a number to exactly the same string.  Some XSLT processors may not
  3040. support some languages.  Furthermore, there may be variations possible
  3041. in the way conversions are performed for any particular language that
  3042. are not specifiable by the attributes on <code>xsl:number</code>.
  3043. Future versions of XSLT may provide additional attributes to provide
  3044. control over these variations.  Implementations may also use
  3045. implementation-specific namespaced attributes on
  3046. <code>xsl:number</code> for this.</p></note>
  3047.  
  3048. <p>The <code>grouping-separator</code> attribute gives the separator
  3049. used as a grouping (e.g. thousands) separator in decimal numbering
  3050. sequences, and the optional <code>grouping-size</code> specifies the
  3051. size (normally 3) of the grouping.  For example,
  3052. <code>grouping-separator=","</code> and <code>grouping-size="3"</code>
  3053. would produce numbers of the form <code>1,000,000</code>.  If only one
  3054. of the <code>grouping-separator</code> and <code>grouping-size</code>
  3055. attributes is specified, then it is ignored.</p>
  3056.  
  3057. <p>Here are some examples of conversion specifications:</p>
  3058.  
  3059. <ulist>
  3060.  
  3061. <item><p><code>format="&#x30A2;"</code> specifies Katakana
  3062. numbering</p></item>
  3063.  
  3064. <item><p><code>format="&#x30A4;"</code> specifies Katakana
  3065. numbering in the <quote>iroha</quote> order</p></item>
  3066.  
  3067. <item><p><code>format="&#x0E51;"</code> specifies numbering with
  3068. Thai digits</p></item>
  3069.  
  3070. <item><p><code>format="&#x05D0;" letter-value="traditional"</code>
  3071. specifies <quote>traditional</quote> Hebrew numbering</p></item>
  3072.  
  3073. <item><p><code>format="&#x10D0;" letter-value="traditional"</code>
  3074. specifies Georgian numbering</p></item>
  3075.  
  3076. <item><p><code>format="&#x03B1;" letter-value="traditional"</code>
  3077. specifies <quote>classical</quote> Greek numbering</p></item>
  3078.  
  3079. <item><p><code>format="&#x0430;" letter-value="traditional"</code>
  3080. specifies Old Slavic numbering</p></item>
  3081.  
  3082. </ulist>
  3083.  
  3084. </div3>
  3085. </div2>
  3086. </div1>
  3087.  
  3088. <div1 id="for-each">
  3089.  
  3090. <head>Repetition</head>
  3091.  
  3092. <e:element-syntax name="for-each">
  3093.   <e:in-category name="instruction"/>
  3094.   <e:attribute name="select" required="yes">
  3095.     <e:data-type name="node-set-expression"/>
  3096.   </e:attribute>
  3097.   <e:sequence>
  3098.     <e:element repeat="zero-or-more" name="sort"/>
  3099.     <e:model name="template"/>
  3100.   </e:sequence>
  3101. </e:element-syntax>
  3102.  
  3103. <p>When the result has a known regular structure, it is useful to be
  3104. able to specify directly the template for selected nodes.  The
  3105. <code>xsl:for-each</code> instruction contains a template, which is
  3106. instantiated for each node selected by the <termref
  3107. def="dt-expression">expression</termref> specified by the
  3108. <code>select</code> attribute. The <code>select</code> attribute is
  3109. required.  The expression must evaluate to a node-set.  The template
  3110. is instantiated with the selected node as the <termref
  3111. def="dt-current-node">current node</termref>, and with a list of all
  3112. of the selected nodes as the <termref
  3113. def="dt-current-node-list">current node list</termref>.  The nodes are
  3114. processed in document order, unless a sorting specification is present
  3115. (see <specref ref="sorting"/>).</p>
  3116.  
  3117. <p>For example, given an XML document with this structure</p>
  3118.  
  3119. <eg><![CDATA[<customers>
  3120.   <customer>
  3121.     <name>...</name>
  3122.     <order>...</order>
  3123.     <order>...</order>
  3124.   </customer>
  3125.   <customer>
  3126.     <name>...</name>
  3127.     <order>...</order>
  3128.     <order>...</order>
  3129.   </customer>
  3130. </customers>]]></eg>
  3131.  
  3132. <p>the following would create an HTML document containing a table with
  3133. a row for each <code>customer</code> element</p>
  3134.  
  3135. <eg><![CDATA[<xsl:template match="/">
  3136.   <html>
  3137.     <head>
  3138.       <title>Customers</title>
  3139.     </head>
  3140.     <body>
  3141.       <table>
  3142.     <tbody>
  3143.       <xsl:for-each select="customers/customer">
  3144.         <tr>
  3145.           <th>
  3146.         <xsl:apply-templates select="name"/>
  3147.           </th>
  3148.           <xsl:for-each select="order">
  3149.         <td>
  3150.           <xsl:apply-templates/>
  3151.         </td>
  3152.           </xsl:for-each>
  3153.         </tr>
  3154.       </xsl:for-each>
  3155.     </tbody>
  3156.       </table>
  3157.     </body>
  3158.   </html>
  3159. </xsl:template>]]></eg>
  3160.  
  3161. </div1>
  3162.  
  3163. <div1>
  3164. <head>Conditional Processing</head>
  3165.  
  3166. <p>There are two instructions in XSLT that support conditional
  3167. processing in a template: <code>xsl:if</code> and
  3168. <code>xsl:choose</code>. The <code>xsl:if</code> instruction provides
  3169. simple if-then conditionality; the <code>xsl:choose</code> instruction
  3170. supports selection of one choice when there are several
  3171. possibilities.</p>
  3172.  
  3173. <div2>
  3174. <head>Conditional Processing with <code>xsl:if</code></head>
  3175.  
  3176. <e:element-syntax name="if">
  3177.   <e:in-category name="instruction"/>
  3178.   <e:attribute name="test" required="yes">
  3179.     <e:data-type name="boolean-expression"/>
  3180.   </e:attribute>
  3181.   <e:model name="template"/>
  3182. </e:element-syntax>
  3183.  
  3184. <p>The <code>xsl:if</code> element has a <code>test</code> attribute,
  3185. which specifies an <termref def="dt-expression">expression</termref>.
  3186. The content is a template.  The expression is evaluated and the
  3187. resulting object is converted to a boolean as if by a call to the
  3188. <xfunction>boolean</xfunction> function.  If the result is true, then
  3189. the content template is instantiated; otherwise, nothing is created.
  3190. In the following example, the names in a group of names are formatted
  3191. as a comma separated list:</p>
  3192.  
  3193. <eg><![CDATA[<xsl:template match="namelist/name">
  3194.   <xsl:apply-templates/>
  3195.   <xsl:if test="not(position()=last())">, </xsl:if>
  3196. </xsl:template>]]></eg>
  3197.  
  3198. <p>The following colors every other table row yellow:</p>
  3199.  
  3200. <eg><![CDATA[<xsl:template match="item">
  3201.   <tr>
  3202.     <xsl:if test="position() mod 2 = 0">
  3203.        <xsl:attribute name="bgcolor">yellow</xsl:attribute>
  3204.     </xsl:if>
  3205.     <xsl:apply-templates/>
  3206.   </tr>
  3207. </xsl:template>]]></eg>
  3208.  
  3209. </div2>
  3210.  
  3211.  
  3212. <div2>
  3213. <head>Conditional Processing with <code>xsl:choose</code></head>
  3214.  
  3215. <e:element-syntax name="choose">
  3216.   <e:in-category name="instruction"/>
  3217.   <e:sequence>
  3218.     <e:element repeat="one-or-more" name="when"/>
  3219.     <e:element repeat="zero-or-one" name="otherwise"/>
  3220.   </e:sequence>
  3221. </e:element-syntax>
  3222.  
  3223. <e:element-syntax name="when">
  3224.   <e:attribute name="test" required="yes">
  3225.     <e:data-type name="boolean-expression"/>
  3226.   </e:attribute>
  3227.   <e:model name="template"/>
  3228. </e:element-syntax>
  3229.  
  3230. <e:element-syntax name="otherwise">
  3231.   <e:model name="template"/>
  3232. </e:element-syntax>
  3233.  
  3234. <p>The <code>xsl:choose</code> element selects one among a number of
  3235. possible alternatives. It consists of a sequence of
  3236. <code>xsl:when</code> elements followed by an optional
  3237. <code>xsl:otherwise</code> element.  Each <code>xsl:when</code>
  3238. element has a single attribute, <code>test</code>, which specifies an
  3239. <termref def="dt-expression">expression</termref>. The content of the
  3240. <code>xsl:when</code> and <code>xsl:otherwise</code> elements is a
  3241. template.  When an <code>xsl:choose</code> element is processed, each
  3242. of the <code>xsl:when</code> elements is tested in turn, by evaluating
  3243. the expression and converting the resulting object to a boolean as if
  3244. by a call to the <xfunction>boolean</xfunction> function.  The content
  3245. of the first, and only the first, <code>xsl:when</code> element whose
  3246. test is true is instantiated.  If no <code>xsl:when</code> is true,
  3247. the content of the <code>xsl:otherwise</code> element is
  3248. instantiated. If no <code>xsl:when</code> element is true, and no
  3249. <code>xsl:otherwise</code> element is present, nothing is created.</p>
  3250.  
  3251. <p>The following example enumerates items in an ordered list using
  3252. arabic numerals, letters, or roman numerals depending on the depth to
  3253. which the ordered lists are nested.</p>
  3254.  
  3255. <eg><![CDATA[<xsl:template match="orderedlist/listitem">
  3256.   <fo:list-item indent-start='2pi'>
  3257.     <fo:list-item-label>
  3258.       <xsl:variable name="level"
  3259.                     select="count(ancestor::orderedlist) mod 3"/>
  3260.       <xsl:choose>
  3261.         <xsl:when test='$level=1'>
  3262.           <xsl:number format="i"/>
  3263.         </xsl:when>
  3264.         <xsl:when test='$level=2'>
  3265.           <xsl:number format="a"/>
  3266.         </xsl:when>
  3267.         <xsl:otherwise>
  3268.           <xsl:number format="1"/>
  3269.         </xsl:otherwise>
  3270.       </xsl:choose>
  3271.       <xsl:text>. </xsl:text>
  3272.     </fo:list-item-label>
  3273.     <fo:list-item-body>
  3274.       <xsl:apply-templates/>
  3275.     </fo:list-item-body>
  3276.   </fo:list-item>
  3277. </xsl:template>]]></eg>
  3278.  
  3279. </div2>
  3280. </div1>
  3281.  
  3282. <div1 id="sorting">
  3283. <head>Sorting</head>
  3284.  
  3285. <e:element-syntax name="sort">
  3286.   <e:attribute name="select">
  3287.     <e:data-type name="string-expression"/>
  3288.   </e:attribute>
  3289.   <e:attribute name="lang">
  3290.     <e:attribute-value-template>
  3291.       <e:data-type name="nmtoken"/>
  3292.     </e:attribute-value-template>
  3293.   </e:attribute>
  3294.   <e:attribute name="data-type">
  3295.     <e:attribute-value-template>
  3296.        <e:constant value="text"/>
  3297.        <e:constant value="number"/>
  3298.        <e:data-type name="qname-but-not-ncname"/>
  3299.     </e:attribute-value-template>
  3300.   </e:attribute>
  3301.   <e:attribute name="order">
  3302.     <e:attribute-value-template>
  3303.        <e:constant value="ascending"/>
  3304.        <e:constant value="descending"/>
  3305.     </e:attribute-value-template>
  3306.   </e:attribute>
  3307.   <e:attribute name="case-order">
  3308.     <e:attribute-value-template>
  3309.        <e:constant value="upper-first"/>
  3310.        <e:constant value="lower-first"/>
  3311.     </e:attribute-value-template>
  3312.   </e:attribute>
  3313.   <e:empty/>
  3314. </e:element-syntax>
  3315.  
  3316. <p>Sorting is specified by adding <code>xsl:sort</code> elements as
  3317. children of an <code>xsl:apply-templates</code> or
  3318. <code>xsl:for-each</code> element.  The first <code>xsl:sort</code>
  3319. child specifies the primary sort key, the second <code>xsl:sort</code>
  3320. child specifies the secondary sort key and so on.  When an
  3321. <code>xsl:apply-templates</code> or <code>xsl:for-each</code> element
  3322. has one or more <code>xsl:sort</code> children, then instead of
  3323. processing the selected nodes in document order, it sorts the nodes
  3324. according to the specified sort keys and then processes them in sorted
  3325. order.  When used in <code>xsl:for-each</code>, <code>xsl:sort</code>
  3326. elements must occur first.  When a template is instantiated by
  3327. <code>xsl:apply-templates</code> and <code>xsl:for-each</code>, the
  3328. <termref def="dt-current-node-list">current node list</termref> list
  3329. consists of the complete list of nodes being processed in sorted
  3330. order.</p>
  3331.  
  3332. <p><code>xsl:sort</code> has a <code>select</code> attribute whose
  3333. value is an <termref def="dt-expression">expression</termref>. For
  3334. each node to be processed, the expression is evaluated with that node
  3335. as the current node and with the complete list of nodes being
  3336. processed in unsorted order as the current node list.
  3337. The resulting object is converted to a string as
  3338. if by a call to the <xfunction>string</xfunction> function; this string
  3339. is used as the sort key for that node. The default value of the
  3340. <code>select</code> attribute is <code>.</code>, which will cause the
  3341. string-value of the current node to be used as the sort key.</p>
  3342.  
  3343. <p>This string serves as a sort key for the node.  The following
  3344. optional attributes on <code>xsl:sort</code> control how the list of
  3345. sort keys are sorted; the values of all of these attributes are
  3346. interpreted as <termref def="dt-attribute-value-template">attribute
  3347. value templates</termref>.</p>
  3348.  
  3349. <ulist>
  3350.  
  3351. <item><p><code>order</code> specifies whether the strings should be
  3352. sorted in ascending or descending order; <code>ascending</code>
  3353. specifies ascending order; <code>descending</code> specifies
  3354. descending order; the default is <code>ascending</code></p></item>
  3355.  
  3356. <item><p><code>lang</code> specifies the language of the sort keys; it
  3357. has the same range of values as <code>xml:lang</code> <bibref
  3358. ref="XML"/>; if no <code>lang</code> value is specified, the language
  3359. should be determined from the system environment</p></item>
  3360.  
  3361. <item><p><code>data-type</code> specifies the data type of the
  3362. strings; the following values are allowed:</p>
  3363.  
  3364. <ulist>
  3365.  
  3366. <item><p><code>text</code> specifies that the sort keys should be
  3367. sorted lexicographically in the culturally correct manner for the
  3368. language specified by <code>lang</code></p></item>
  3369.  
  3370. <item><p><code>number</code> specifies that the sort keys should be
  3371. converted to numbers and then sorted according to the numeric value;
  3372. the sort key is converted to a number as if by a call to the
  3373. <xfunction>number</xfunction> function; the <code>lang</code>
  3374. attribute is ignored</p></item>
  3375.  
  3376. <item><p>a <xnt href="&XMLNames;#NT-QName">QName</xnt> with a prefix
  3377. is expanded into an <xtermref
  3378. href="&XPath;#dt-expanded-name">expanded-name</xtermref> as described
  3379. in <specref ref="qname"/>; the expanded-name identifies the data-type;
  3380. the behavior in this case is not specified by this document</p></item>
  3381.  
  3382. </ulist>
  3383.  
  3384. <p>The default value is <code>text</code>.</p>
  3385.  
  3386. <note><p>The XSL Working Group plans that future versions of XSLT will
  3387. leverage XML Schemas to define further values for this
  3388. attribute.</p></note>
  3389.  
  3390. </item>
  3391.  
  3392. <item><p><code>case-order</code> has the value
  3393. <code>upper-first</code> or <code>lower-first</code>; this applies
  3394. when <code>data-type="text"</code>, and specifies that upper-case
  3395. letters should sort before lower-case letters or vice-versa
  3396. respectively. For example, if <code>lang="en"</code>, then <code>A a B
  3397. b</code> are sorted with <code>case-order="upper-first"</code> and
  3398. <code>a A b B</code> are sorted with
  3399. <code>case-order="lower-first"</code>. The default value is language
  3400. dependent.</p></item>
  3401.  
  3402. </ulist>
  3403.  
  3404. <note><p>It is possible for two conforming XSLT processors not to sort
  3405. exactly the same.  Some XSLT processors may not support some
  3406. languages.  Furthermore, there may be variations possible in the
  3407. sorting of any particular language that are not specified by the
  3408. attributes on <code>xsl:sort</code>, for example, whether Hiragana or
  3409. Katakana is sorted first in Japanese.  Future versions of XSLT may
  3410. provide additional attributes to provide control over these
  3411. variations.  Implementations may also use implementation-specific
  3412. namespaced attributes on <code>xsl:sort</code> for this.</p></note>
  3413.  
  3414. <note><p>It is recommended that implementers consult <bibref
  3415. ref="UNICODE-TR10"/> for information on internationalized
  3416. sorting.</p></note>
  3417.  
  3418. <p>The sort must be stable: in the sorted list of nodes, any sub list
  3419. that has sort keys that all compare equal must be in document
  3420. order.</p>
  3421.  
  3422. <p>For example, suppose an employee database has the form</p>
  3423.  
  3424. <eg><![CDATA[<employees>
  3425.   <employee>
  3426.     <name>
  3427.       <given>James</given>
  3428.       <family>Clark</family>
  3429.     </name>
  3430.     ...
  3431.   </employee>
  3432. </employees>
  3433. ]]></eg>
  3434.   
  3435. <p>Then a list of employees sorted by name could be generated
  3436. using:</p>
  3437.  
  3438. <eg><![CDATA[<xsl:template match="employees">
  3439.   <ul>
  3440.     <xsl:apply-templates select="employee">
  3441.       <xsl:sort select="name/family"/>
  3442.       <xsl:sort select="name/given"/>
  3443.     </xsl:apply-templates>
  3444.   </ul>
  3445. </xsl:template>
  3446.  
  3447. <xsl:template match="employee">
  3448.   <li>
  3449.     <xsl:value-of select="name/given"/>
  3450.     <xsl:text> </xsl:text>
  3451.     <xsl:value-of select="name/family"/>
  3452.   </li>
  3453. </xsl:template>]]></eg>
  3454.  
  3455. </div1>
  3456.  
  3457. <div1 id="variables">
  3458. <head>Variables and Parameters</head>
  3459.  
  3460. <e:element-syntax name="variable">
  3461.   <e:in-category name="top-level-element"/>
  3462.   <e:in-category name="instruction"/>
  3463.   <e:attribute name="name" required="yes">
  3464.     <e:data-type name="qname"/>
  3465.   </e:attribute>
  3466.   <e:attribute name="select">
  3467.     <e:data-type name="expression"/>
  3468.   </e:attribute>
  3469.   <e:model name="template"/>
  3470. </e:element-syntax>
  3471.  
  3472. <e:element-syntax name="param">
  3473.   <e:in-category name="top-level-element"/>
  3474.   <e:attribute name="name" required="yes">
  3475.     <e:data-type name="qname"/>
  3476.   </e:attribute>
  3477.   <e:attribute name="select">
  3478.     <e:data-type name="expression"/>
  3479.   </e:attribute>
  3480.   <e:model name="template"/>
  3481. </e:element-syntax>
  3482.  
  3483. <p>A variable is a name that may be bound to a value.  The value to
  3484. which a variable is bound (the <term>value</term> of the variable) can
  3485. be an object of any of the types that can be returned by expressions.
  3486. There are two elements that can be used to bind variables:
  3487. <code>xsl:variable</code> and <code>xsl:param</code>. The difference
  3488. is that the value specified on the <code>xsl:param</code> variable is
  3489. only a default value for the binding; when the template or stylesheet
  3490. within which the <code>xsl:param</code> element occurs is invoked,
  3491. parameters may be passed that are used in place of the default
  3492. values.</p>
  3493.  
  3494. <p>Both <code>xsl:variable</code> and <code>xsl:param</code> have a
  3495. required <code>name</code> attribute, which specifies the name of the
  3496. variable.  The value of the <code>name</code> attribute is a <xnt
  3497. href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
  3498. in <specref ref="qname"/>.</p>
  3499.  
  3500. <p>For any use of these variable-binding elements, there is a region
  3501. of the stylesheet tree within which the binding is visible; within
  3502. this region, any binding of the variable that was visible on the
  3503. variable-binding element itself is hidden.  Thus, only the innermost
  3504. binding of a variable is visible.  The set of variable bindings in
  3505. scope for an expression consists of those bindings that are visible at
  3506. the point in the stylesheet where the expression occurs.</p>
  3507.  
  3508. <div2>
  3509. <head>Result Tree Fragments</head>
  3510.  
  3511. <p>Variables introduce an additional data-type into the expression
  3512. language.  <termdef id="dt-result-tree-fragment" term="Result Tree
  3513. Fragment">This additional data type is called <term>result tree
  3514. fragment</term>.  A variable may be bound to a result tree fragment
  3515. instead of one of the four basic XPath data-types (string, number,
  3516. boolean, node-set).  A result tree fragment represents a fragment of
  3517. the result tree. A result tree fragment is treated equivalently to a
  3518. node-set that contains just a single root node.</termdef> However, the
  3519. operations permitted on a result tree fragment are a subset of those
  3520. permitted on a node-set.  An operation is permitted on a result tree
  3521. fragment only if that operation would be permitted on a string (the
  3522. operation on the string may involve first converting the string to a
  3523. number or boolean). In particular, it is not permitted to use the
  3524. <code>/</code>, <code>//</code>, and <code>[]</code> operators on
  3525. result tree fragments.  When a permitted operation is performed on a
  3526. result tree fragment, it is performed exactly as it would be on the
  3527. equivalent node-set.</p>
  3528.  
  3529. <p>When a result tree fragment is copied into the result tree (see
  3530. <specref ref="copy-of"/>), then all the nodes that are children of the
  3531. root node in the equivalent node-set are added in sequence to the
  3532. result tree.</p>
  3533.  
  3534. <p>Expressions can only return values of type result tree fragment by
  3535. referencing variables of type result tree fragment or calling
  3536. extension functions that return a result tree fragment or getting a
  3537. system property whose value is a result tree fragment.</p>
  3538.  
  3539. </div2>
  3540.  
  3541. <div2 id="variable-values">
  3542. <head>Values of Variables and Parameters</head>
  3543.  
  3544. <p>A variable-binding element can specify the value of the variable in
  3545. three alternative ways.</p>
  3546.  
  3547. <ulist>
  3548.  
  3549. <item><p>If the variable-binding element has a <code>select</code>
  3550. attribute, then the value of the attribute must be an <termref
  3551. def="dt-expression">expression</termref> and the value of the variable
  3552. is the object that results from evaluating the expression.  In this
  3553. case, the content must be empty.</p></item>
  3554.  
  3555. <item>
  3556.  
  3557. <p>If the variable-binding element does not have a <code>select</code>
  3558. attribute and has non-empty content (i.e. the variable-binding element
  3559. has one or more child nodes), then the content of the
  3560. variable-binding element specifies the value. The content of the
  3561. variable-binding element is a template, which is instantiated to give
  3562. the value of the variable. The value is a result tree fragment
  3563. equivalent to a node-set containing just a single root node having as
  3564. children the sequence of nodes produced by instantiating the template.
  3565. The base URI of the nodes in the result tree fragment is the base URI
  3566. of the variable-binding element.</p>
  3567.  
  3568. <p>It is an error if a member of the sequence of nodes created by
  3569. instantiating the template is an attribute node or a namespace node,
  3570. since a root node cannot have an attribute node or a namespace node as
  3571. a child. An XSLT processor may signal the error; if it does not signal
  3572. the error, it must recover by not adding the attribute node or
  3573. namespace node.</p>
  3574.  
  3575. </item>
  3576.  
  3577. <item>
  3578.  
  3579. <p>If the variable-binding element has empty content and does not have
  3580. a <code>select</code> attribute, then the value of the variable is an
  3581. empty string. Thus</p>
  3582.  
  3583. <eg><![CDATA[<xsl:variable name="x"/>]]></eg>
  3584.  
  3585. <p>is equivalent to</p>
  3586.  
  3587. <eg><![CDATA[<xsl:variable name="x" select="''"/>]]></eg>
  3588.  
  3589. </item>
  3590.  
  3591. </ulist>
  3592.  
  3593. <note><p>When a variable is used to select nodes by position, be careful
  3594. not to do:</p>
  3595.  
  3596. <eg><![CDATA[<xsl:variable name="n">2</xsl:variable>
  3597. ...
  3598. <xsl:value-of select="item[$n]"/>]]></eg>
  3599.  
  3600. <p>This will output the value of the first item element, because the
  3601. variable <code>n</code> will be bound to a result tree fragment, not a
  3602. number. Instead, do either</p>
  3603.  
  3604. <eg><![CDATA[<xsl:variable name="n" select="2"/>
  3605. ...
  3606. <xsl:value-of select="item[$n]"/>]]></eg>
  3607.  
  3608. <p>or</p>
  3609.  
  3610. <eg><![CDATA[<xsl:variable name="n">2</xsl:variable>
  3611. ...
  3612. <xsl:value-of select="item[position()=$n]"/>]]></eg>
  3613. </note>
  3614.  
  3615. <note><p>One convenient way to specify the empty node-set as the default
  3616. value of a parameter is:</p>
  3617.  
  3618. <eg><![CDATA[<xsl:param name="x" select="/.."/>]]></eg>
  3619. </note>
  3620.  
  3621. </div2>
  3622.  
  3623. <div2 id="copy-of">
  3624. <head>Using Values of Variables and Parameters with
  3625. <code>xsl:copy-of</code></head>
  3626.  
  3627. <e:element-syntax name="copy-of">
  3628.   <e:in-category name="instruction"/>
  3629.   <e:attribute name="select" required="yes">
  3630.     <e:data-type name="expression"/>
  3631.   </e:attribute>
  3632.   <e:empty/>
  3633. </e:element-syntax>
  3634.  
  3635. <p>The <code>xsl:copy-of</code> element can be used to insert a result
  3636. tree fragment into the result tree, without first converting it to a
  3637. string as <code>xsl:value-of</code> does (see <specref
  3638. ref="value-of"/>).  The required <code>select</code> attribute
  3639. contains an <termref def="dt-expression">expression</termref>.  When
  3640. the result of evaluating the expression is a result tree fragment, the
  3641. complete fragment is copied into the result tree.  When the result is
  3642. a node-set, all the nodes in the set are copied in document order into
  3643. the result tree; copying an element node copies the attribute nodes,
  3644. namespace nodes and children of the element node as well as the
  3645. element node itself; a root node is copied by copying its children.
  3646. When the result is neither a node-set nor a result tree fragment, the
  3647. result is converted to a string and then inserted into the result
  3648. tree, as with <code>xsl:value-of</code>.</p>
  3649.  
  3650. </div2>
  3651.  
  3652. <div2 id="top-level-variables">
  3653. <head>Top-level Variables and Parameters</head>
  3654.  
  3655. <p>Both <code>xsl:variable</code> and <code>xsl:param</code> are
  3656. allowed as <termref def="dt-top-level">top-level</termref> elements.
  3657. A top-level variable-binding element declares a global variable that
  3658. is visible everywhere.  A top-level <code>xsl:param</code> element
  3659. declares a parameter to the stylesheet; XSLT does not define the
  3660. mechanism by which parameters are passed to the stylesheet.  It is an
  3661. error if a stylesheet contains more than one binding of a top-level
  3662. variable with the same name and same <termref
  3663. def="dt-import-precedence">import precedence</termref>. At the
  3664. top-level, the expression or template specifying the variable value is
  3665. evaluated with the same context as that used to process the root node
  3666. of the source document: the current node is the root node of the
  3667. source document and the current node list is a list containing just
  3668. the root node of the source document.  If the template or expression
  3669. specifying the value of a global variable <var>x</var> references a
  3670. global variable <var>y</var>, then the value for <var>y</var> must
  3671. be computed before the value of <var>x</var>.  It is an error if it
  3672. is impossible to do this for all global variable definitions; in other
  3673. words, it is an error if the definitions are circular.</p>
  3674.  
  3675. <p>This example declares a global variable <code>para-font-size</code>,
  3676. which it references in an attribute value template.</p>
  3677.  
  3678. <eg><![CDATA[<xsl:variable name="para-font-size">12pt</xsl:variable>
  3679.  
  3680. <xsl:template match="para">
  3681.  <fo:block font-size="{$para-font-size}">
  3682.    <xsl:apply-templates/>
  3683.  </fo:block>
  3684. </xsl:template>
  3685. ]]></eg>
  3686.  
  3687. </div2>
  3688.  
  3689. <div2 id="local-variables">
  3690. <head>Variables and Parameters within Templates</head>
  3691.  
  3692. <p>As well as being allowed at the top-level, both
  3693. <code>xsl:variable</code> and <code>xsl:param</code> are also
  3694. allowed in templates.  <code>xsl:variable</code> is allowed anywhere
  3695. within a template that an instruction is allowed.  In this case, the
  3696. binding is visible for all following siblings and their descendants.
  3697. Note that the binding is not visible for the <code>xsl:variable</code>
  3698. element itself.  <code>xsl:param</code> is allowed as a child
  3699. at the beginning of an <code>xsl:template</code> element.  In this
  3700. context, the binding is visible for all following siblings and their
  3701. descendants.  Note that the binding is not visible for the
  3702. <code>xsl:param</code> element itself.</p>
  3703.  
  3704. <p><termdef id="dt-shadows" term="Shadows">A binding
  3705. <term>shadows</term> another binding if the binding occurs at a point
  3706. where the other binding is visible, and the bindings have the same
  3707. name.</termdef> It is an error if a binding established by an
  3708. <code>xsl:variable</code> or <code>xsl:param</code> element within a
  3709. template <termref def="dt-shadows">shadows</termref> another binding
  3710. established by an <code>xsl:variable</code> or <code>xsl:param</code>
  3711. element also within the template.  It is not an error if a binding
  3712. established by an <code>xsl:variable</code> or <code>xsl:param</code>
  3713. element in a template <termref def="dt-shadows">shadows</termref>
  3714. another binding established by an <code>xsl:variable</code> or
  3715. <code>xsl:param</code> <termref def="dt-top-level">top-level</termref>
  3716. element.  Thus, the following is an error:</p>
  3717.  
  3718. <eg role="error"><![CDATA[<xsl:template name="foo">
  3719. <xsl:param name="x" select="1"/>
  3720. <xsl:variable name="x" select="2"/>
  3721. </xsl:template>]]></eg>
  3722.  
  3723. <p>However, the following is allowed:</p>
  3724.  
  3725. <eg><![CDATA[<xsl:param name="x" select="1"/>
  3726. <xsl:template name="foo">
  3727. <xsl:variable name="x" select="2"/>
  3728. </xsl:template>]]></eg>
  3729.  
  3730. <note><p>The nearest equivalent in Java to an <code>xsl:variable</code>
  3731. element in a template is a final local variable declaration with an
  3732. initializer.  For example,</p>
  3733.  
  3734. <eg><![CDATA[<xsl:variable name="x" select="'value'"/>]]></eg>
  3735.  
  3736. <p>has similar semantics to</p>
  3737.  
  3738. <eg>final Object x = "value";</eg>
  3739.  
  3740. <p>XSLT does not provide an equivalent to the Java assignment operator</p>
  3741.  
  3742. <eg>x = "value";</eg>
  3743.  
  3744. <p>because this would make it harder to create an implementation that
  3745. processes a document other than in a batch-like way, starting at the
  3746. beginning and continuing through to the end.</p></note>
  3747.  
  3748. </div2>
  3749.  
  3750. <div2>
  3751. <head>Passing Parameters to Templates</head>
  3752.  
  3753. <e:element-syntax name="with-param">
  3754.   <e:attribute name="name" required="yes">
  3755.     <e:data-type name="qname"/>
  3756.   </e:attribute>
  3757.   <e:attribute name="select">
  3758.     <e:data-type name="expression"/>
  3759.   </e:attribute>
  3760.   <e:model name="template"/>
  3761. </e:element-syntax>
  3762.  
  3763. <p>Parameters are passed to templates using the
  3764. <code>xsl:with-param</code> element.  The required <code>name</code>
  3765. attribute specifies the name of the parameter (the variable the value
  3766. of whose binding is to be replaced).  The value of the
  3767. <code>name</code> attribute is a <xnt
  3768. href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
  3769. in <specref ref="qname"/>.  <code>xsl:with-param</code> is allowed
  3770. within both <code>xsl:call-template</code> and
  3771. <code>xsl:apply-templates</code>.  The value of the parameter is
  3772. specified in the same way as for <code>xsl:variable</code> and
  3773. <code>xsl:param</code>.  The current node and current node list used
  3774. for computing the value specified by <code>xsl:with-param</code>
  3775. element is the same as that used for the
  3776. <code>xsl:apply-templates</code> or <code>xsl:call-template</code>
  3777. element within which it occurs.  It is not an error to pass a
  3778. parameter <var>x</var> to a template that does not have an
  3779. <code>xsl:param</code> element for <var>x</var>; the parameter is
  3780. simply ignored.</p>
  3781.  
  3782. <p>This example defines a named template for a
  3783. <code>numbered-block</code> with an argument to control the format of
  3784. the number.</p>
  3785.  
  3786. <eg><![CDATA[<xsl:template name="numbered-block">
  3787.   <xsl:param name="format">1. </xsl:param>
  3788.   <fo:block>
  3789.     <xsl:number format="{$format}"/>
  3790.     <xsl:apply-templates/>
  3791.   </fo:block>
  3792. </xsl:template>
  3793.  
  3794. <xsl:template match="ol//ol/li">
  3795.   <xsl:call-template name="numbered-block">
  3796.     <xsl:with-param name="format">a. </xsl:with-param>
  3797.   </xsl:call-template>
  3798. </xsl:template>]]></eg>
  3799.  
  3800. </div2>
  3801.  
  3802. </div1>
  3803.  
  3804. <div1 id="add-func">
  3805. <head>Additional Functions</head>
  3806.  
  3807. <p>This section describes XSLT-specific additions to the core XPath
  3808. function library.  Some of these additional functions also make use of
  3809. information specified by <termref def="dt-top-level">top-level</termref>
  3810. elements in the stylesheet; this section also describes these
  3811. elements.</p>
  3812.  
  3813. <div2 id="document">
  3814.  
  3815. <head>Multiple Source Documents</head>
  3816.  
  3817. <proto name="document" return-type="node-set"><arg type="object"/>
  3818. <arg type="node-set" occur="opt"/></proto>
  3819.  
  3820. <p>The <function>document</function> function allows
  3821. access to XML documents other than the main source document.</p>
  3822.  
  3823. <p>When the <function>document</function> function has exactly one
  3824. argument and the argument is a node-set, then the result is the union,
  3825. for each node in the argument node-set, of the result of calling the
  3826. <function>document</function> function with the first argument being
  3827. the <xtermref href="&XPath;#dt-string-value">string-value</xtermref>
  3828. of the node, and the second argument being a node-set with the node as
  3829. its only member. When the <function>document</function> function has
  3830. two arguments and the first argument is a node-set, then the result is
  3831. the union, for each node in the argument node-set, of the result of
  3832. calling the <function>document</function> function with the first
  3833. argument being the <xtermref
  3834. href="&XPath;#dt-string-value">string-value</xtermref> of the node,
  3835. and with the second argument being the second argument passed to the
  3836. <function>document</function> function.</p>
  3837.  
  3838. <p>When the first argument to the <function>document</function>
  3839. function is not a node-set, the first argument is converted to a
  3840. string as if by a call to the <xfunction>string</xfunction> function.
  3841. This string is treated as a URI reference; the resource identified by
  3842. the URI is retrieved. The data resulting from the retrieval action is
  3843. parsed as an XML document and a tree is constructed in accordance with
  3844. the data model (see <specref ref="data-model"/>).  If there is an
  3845. error retrieving the resource, then the XSLT processor may signal an
  3846. error; if it does not signal an error, it must recover by returning an
  3847. empty node-set.  One possible kind of retrieval error is that the XSLT
  3848. processor does not support the URI scheme used by the URI.  An XSLT
  3849. processor is not required to support any particular URI schemes.  The
  3850. documentation for an XSLT processor should specify which URI schemes
  3851. the XSLT processor supports.</p>
  3852.  
  3853. <p>If the URI reference does not contain a fragment identifier, then a
  3854. node-set containing just the root node of the document is returned.
  3855. If the URI reference does contain a fragment identifier, the function
  3856. returns a node-set containing the nodes in the tree identified by the
  3857. fragment identifier of the URI reference. The semantics of the
  3858. fragment identifier is dependent on the media type of the result of
  3859. retrieving the URI.  If there is an error in processing the fragment
  3860. identifier, the XSLT processor may signal the error; if it does not
  3861. signal the error, it must recover by returning an empty node-set.
  3862. Possible errors include:</p>
  3863.  
  3864. <ulist>
  3865.  
  3866. <item><p>The fragment identifier identifies something that cannot be
  3867. represented by an XSLT node-set (such as a range of characters within
  3868. a text node).</p></item>
  3869.  
  3870. <item><p>The XSLT processor does not support fragment identifiers for
  3871. the media-type of the retrieval result.  An XSLT processor is not
  3872. required to support any particular media types.  The documentation for
  3873. an XSLT processor should specify for which media types the XSLT
  3874. processor supports fragment identifiers.</p></item>
  3875.  
  3876. </ulist>
  3877.  
  3878. <p>The data resulting from the retrieval action is parsed as an XML
  3879. document regardless of the media type of the retrieval result; if the
  3880. top-level media type is <code>text</code>, then it is parsed in the
  3881. same way as if the media type were <code>text/xml</code>; otherwise,
  3882. it is parsed in the same way as if the media type were
  3883. <code>application/xml</code>.</p>
  3884.  
  3885. <note><p>Since there is no top-level <code>xml</code> media type, data
  3886. with a media type other than <code>text/xml</code> or
  3887. <code>application/xml</code> may in fact be XML.</p></note>
  3888.  
  3889. <p>The URI reference may be relative. The base URI (see <specref
  3890. ref="base-uri"/>) of the node in the second argument node-set that is
  3891. first in document order is used as the base URI for resolving the
  3892. relative URI into an absolute URI.  If the second argument is omitted,
  3893. then it defaults to the node in the stylesheet that contains the
  3894. expression that includes the call to the <function>document</function>
  3895. function.  Note that a zero-length URI reference is a reference to the
  3896. document relative to which the URI reference is being resolved; thus
  3897. <code>document("")</code> refers to the root node of the stylesheet;
  3898. the tree representation of the stylesheet is exactly the same as if
  3899. the XML document containing the stylesheet was the initial source
  3900. document.</p>
  3901.  
  3902. <p>Two documents are treated as the same document if they are
  3903. identified by the same URI. The URI used for the comparison is the
  3904. absolute URI into which any relative URI was resolved and does not
  3905. include any fragment identifier.  One root node is treated as the same
  3906. node as another root node if the two nodes are from the same document.
  3907. Thus, the following expression will always be true:</p>
  3908.  
  3909. <eg>generate-id(document("foo.xml"))=generate-id(document("foo.xml"))</eg>
  3910.  
  3911. <p>The <function>document</function> function gives rise to the
  3912. possibility that a node-set may contain nodes from more than one
  3913. document.  With such a node-set, the relative document order of two
  3914. nodes in the same document is the normal <xtermref
  3915. href="&XPath;#dt-document-order">document order</xtermref> defined by
  3916. XPath <bibref ref="XPATH"/>.  The relative document order of two nodes
  3917. in different documents is determined by an implementation-dependent
  3918. ordering of the documents containing the two nodes.  There are no
  3919. constraints on how the implementation orders documents other than that
  3920. it must do so consistently: an implementation must always use the same
  3921. order for the same set of documents.</p>
  3922.  
  3923. </div2>
  3924.  
  3925. <div2 id="key">
  3926. <head>Keys</head>
  3927.  
  3928. <p>Keys provide a way to work with documents that contain an implicit
  3929. cross-reference structure.  The <code>ID</code>, <code>IDREF</code>
  3930. and <code>IDREFS</code> attribute types in XML provide a mechanism to
  3931. allow XML documents to make their cross-reference explicit.  XSLT
  3932. supports this through the XPath <xfunction>id</xfunction> function.
  3933. However, this mechanism has a number of limitations:</p>
  3934.  
  3935. <ulist>
  3936.  
  3937. <item><p>ID attributes must be declared as such in the DTD.  If an ID
  3938. attribute is declared as an ID attribute only in the external DTD
  3939. subset, then it will be recognized as an ID attribute only if the XML
  3940. processor reads the external DTD subset.  However, XML does not require
  3941. XML processors to read the external DTD, and they may well choose not
  3942. to do so, especially if the document is declared
  3943. <code>standalone="yes"</code>.</p></item>
  3944.  
  3945. <item><p>A document can contain only a single set of unique IDs.
  3946. There cannot be separate independent sets of unique IDs.</p></item>
  3947.  
  3948. <item><p>The ID of an element can only be specified in an attribute;
  3949. it cannot be specified by the content of the element, or by a child
  3950. element.</p></item>
  3951.  
  3952. <item><p>An ID is constrained to be an XML name.  For example, it
  3953. cannot contain spaces.</p></item>
  3954.  
  3955. <item><p>An element can have at most one ID.</p></item>
  3956.  
  3957. <item><p>At most one element can have a particular ID.</p></item>
  3958.  
  3959. </ulist>
  3960.  
  3961. <p>Because of these limitations XML documents sometimes contain a
  3962. cross-reference structure that is not explicitly declared by
  3963. ID/IDREF/IDREFS attributes.</p>
  3964.  
  3965. <p>A key is a triple containing:</p>
  3966.  
  3967. <olist>
  3968.  
  3969. <item><p>the node which has the key</p></item>
  3970.  
  3971. <item><p>the name of the key (an <xtermref
  3972. href="&XPath;#dt-expanded-name">expanded-name</xtermref>)</p></item>
  3973.  
  3974. <item><p>the value of the key (a string)</p></item>
  3975.  
  3976. </olist>
  3977.  
  3978. <p>A stylesheet declares a set of keys for each document using the
  3979. <code>xsl:key</code> element.  When this set of keys contains a member
  3980. with node <var>x</var>, name <var>y</var> and value
  3981. <var>z</var>, we say that node <var>x</var> has a key with name
  3982. <var>y</var> and value <var>z</var>.</p>
  3983.  
  3984. <p>Thus, a key is a kind of generalized ID, which is not subject to the
  3985. same limitations as an XML ID:</p>
  3986.  
  3987. <ulist>
  3988.  
  3989. <item><p>Keys are declared in the stylesheet using
  3990. <code>xsl:key</code> elements.</p></item>
  3991.  
  3992. <item><p>A key has a name as well as a value; each key name may be
  3993. thought of as distinguishing a separate, independent space of
  3994. identifiers.</p></item>
  3995.  
  3996. <item><p>The value of a named key for an element may be specified in
  3997. any convenient place; for example, in an attribute, in a child element
  3998. or in content.  An XPath expression is used to specify where to find
  3999. the value for a particular named key.</p></item>
  4000.  
  4001. <item><p>The value of a key can be an arbitrary string; it is not
  4002. constrained to be a name.</p></item>
  4003.  
  4004. <item><p>There can be multiple keys in a document with the same node,
  4005. same key name, but different key values.</p></item>
  4006.  
  4007. <item><p>There can be multiple keys in a document with the same key
  4008. name, same key value, but different nodes.</p></item>
  4009.  
  4010. </ulist>
  4011.  
  4012. <e:element-syntax name="key">
  4013.   <e:in-category name="top-level-element"/>
  4014.   <e:attribute name="name" required="yes">
  4015.     <e:data-type name="qname"/>
  4016.   </e:attribute>
  4017.   <e:attribute name="match" required="yes">
  4018.     <e:data-type name="pattern"/>
  4019.   </e:attribute>
  4020.   <e:attribute name="use" required="yes">
  4021.     <e:data-type name="expression"/>
  4022.   </e:attribute>
  4023.   <e:empty/>
  4024. </e:element-syntax>
  4025.  
  4026. <p>The <code>xsl:key</code> element is used to declare keys.  The
  4027. <code>name</code> attribute specifies the name of the key.  The value
  4028. of the <code>name</code> attribute is a <xnt
  4029. href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
  4030. in <specref ref="qname"/>. The <code>match</code> attribute is a <nt
  4031. def="NT-Pattern">Pattern</nt>; an <code>xsl:key</code> element gives
  4032. information about the keys of any node that matches the pattern
  4033. specified in the match attribute.  The <code>use</code> attribute is
  4034. an <termref def="dt-expression">expression</termref> specifying the
  4035. values of the key; the expression is evaluated once for each node that
  4036. matches the pattern.  If the result is a node-set, then for each node
  4037. in the node-set, the node that matches the pattern has a key of the
  4038. specified name whose value is the string-value of the node in the
  4039. node-set; otherwise, the result is converted to a string, and the node
  4040. that matches the pattern has a key of the specified name with value
  4041. equal to that string.  Thus, a node <var>x</var> has a key with name
  4042. <var>y</var> and value <var>z</var> if and only if there is an
  4043. <code>xsl:key</code> element such that:</p>
  4044.  
  4045. <ulist>
  4046.  
  4047. <item><p><var>x</var> matches the pattern specified in the
  4048. <code>match</code> attribute of the <code>xsl:key</code> element;</p></item>
  4049.  
  4050. <item><p>the value of the <code>name</code> attribute of the
  4051. <code>xsl:key</code> element is equal to <var>y</var>;
  4052. and</p></item>
  4053.  
  4054. <item><p>when the expression specified in the <code>use</code>
  4055. attribute of the <code>xsl:key</code> element is evaluated with
  4056. <var>x</var> as the current node and with a node list containing
  4057. just <var>x</var> as the current node list resulting in an object
  4058. <var>u</var>, then either <var>z</var> is equal to the result of
  4059. converting <var>u</var> to a string as if by a call to the
  4060. <xfunction>string</xfunction> function, or <var>u</var> is a
  4061. node-set and <var>z</var> is equal to the string-value of one or
  4062. more of the nodes in <var>u</var>.</p></item>
  4063.  
  4064. </ulist>
  4065.  
  4066. <p>Note also that there may be more than one <code>xsl:key</code>
  4067. element that matches a given node; all of the matching
  4068. <code>xsl:key</code> elements are used, even if they do not have the
  4069. same <termref def="dt-import-precedence">import
  4070. precedence</termref>.</p>
  4071.  
  4072. <p>It is an error for the value of either the <code>use</code>
  4073. attribute or the <code>match</code> attribute to contain a <xnt
  4074. href="&XPath;#NT-VariableReference">VariableReference</xnt>.</p>
  4075.  
  4076. <proto name="key" return-type="node-set"><arg type="string"/><arg type="object"/></proto>
  4077.  
  4078. <p>The <function>key</function> function does for keys what the
  4079. <xfunction>id</xfunction> function does for IDs.  The first argument
  4080. specifies the name of the key. The value of the argument must be a
  4081. <xnt href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as
  4082. described in <specref ref="qname"/>. When the second argument to the
  4083. <function>key</function> function is of type node-set, then the result
  4084. is the union of the result of applying the <function>key</function>
  4085. function to the string <xtermref
  4086. href="&XPath;#dt-value">value</xtermref> of each of the nodes in the
  4087. argument node-set.  When the second argument to
  4088. <function>key</function> is of any other type, the argument is
  4089. converted to a string as if by a call to the
  4090. <xfunction>string</xfunction> function; it returns a node-set
  4091. containing the nodes in the same document as the context node that
  4092. have a value for the named key equal to this string.</p>
  4093.  
  4094. <p>For example, given a declaration</p>
  4095.  
  4096. <eg><![CDATA[<xsl:key name="idkey" match="div" use="@id"/>]]></eg>
  4097.  
  4098. <p>an expression <code>key("idkey",@ref)</code> will return the same
  4099. node-set as <code>id(@ref)</code>, assuming that the only ID attribute
  4100. declared in the XML source document is:</p>
  4101.  
  4102. <eg><![CDATA[<!ATTLIST div id ID #IMPLIED>]]></eg>
  4103.  
  4104. <p>and that the <code>ref</code> attribute of the current node
  4105. contains no whitespace.</p>
  4106.  
  4107. <p>Suppose a document describing a function library uses a
  4108. <code>prototype</code> element to define functions</p>
  4109.  
  4110. <eg><![CDATA[<prototype name="key" return-type="node-set">
  4111. <arg type="string"/>
  4112. <arg type="object"/>
  4113. </prototype>]]></eg>
  4114.  
  4115. <p>and a <code>function</code> element to refer to function names</p>
  4116.  
  4117. <eg><![CDATA[<function>key</function>]]></eg>
  4118.  
  4119. <p>Then the stylesheet could generate hyperlinks between the
  4120. references and definitions as follows:</p>
  4121.  
  4122. <eg><![CDATA[<xsl:key name="func" match="prototype" use="@name"/>
  4123.  
  4124. <xsl:template match="function">
  4125. <b>
  4126.   <a href="#{generate-id(key('func',.))}">
  4127.     <xsl:apply-templates/>
  4128.   </a>
  4129. </b>
  4130. </xsl:template>
  4131.  
  4132. <xsl:template match="prototype">
  4133. <p><a name="{generate-id()}">
  4134. <b>Function: </b>
  4135. ...
  4136. </a></p>
  4137. </xsl:template>]]></eg>
  4138.  
  4139. <p>The <function>key</function> can be used to retrieve a key from a
  4140. document other than the document containing the context node.  For
  4141. example, suppose a document contains bibliographic references in the
  4142. form <code><![CDATA[<bibref>XSLT</bibref>]]></code>, and there is a
  4143. separate XML document <code>bib.xml</code> containing a bibliographic
  4144. database with entries in the form:</p>
  4145.  
  4146. <eg><![CDATA[<entry name="XSLT">...</entry>]]></eg>
  4147.  
  4148. <p>Then the stylesheet could use the following to transform the
  4149. <code>bibref</code> elements:</p>
  4150.  
  4151. <eg><![CDATA[<xsl:key name="bib" match="entry" use="@name"/>
  4152.  
  4153. <xsl:template match="bibref">
  4154.   <xsl:variable name="name" select="."/>
  4155.   <xsl:for-each select="document('bib.xml')">
  4156.     <xsl:apply-templates select="key('bib',$name)"/>
  4157.   </xsl:for-each>
  4158. </xsl:template>]]></eg>
  4159.  
  4160. </div2>
  4161.  
  4162. <div2 id="format-number">
  4163. <head>Number Formatting</head>
  4164.  
  4165. <proto name="format-number" return-type="string"><arg type="number"/><arg type="string"/><arg occur="opt" type="string"/></proto>
  4166.  
  4167. <p>The <function>format-number</function> function converts its first
  4168. argument to a string using the format pattern string specified by the
  4169. second argument and the decimal-format named by the third argument, or
  4170. the default decimal-format, if there is no third argument.  The format
  4171. pattern string is in the syntax specified by the JDK 1.1 <loc href=
  4172. "http://java.sun.com/products/jdk/1.1/docs/api/java.text.DecimalFormat.html"
  4173. >DecimalFormat</loc> class. The format pattern string is in a
  4174. localized notation: the decimal-format determines what characters have
  4175. a special meaning in the pattern (with the exception of the quote
  4176. character, which is not localized).  The format pattern must not
  4177. contain the currency sign (#x00A4); support for this feature was added
  4178. after the initial release of JDK 1.1.  The decimal-format name must be
  4179. a <xnt href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as
  4180. described in <specref ref="qname"/>.  It is an error if the stylesheet
  4181. does not contain a declaration of the decimal-format with the specified
  4182. <xtermref href="&XPath;#dt-expanded-name">expanded-name</xtermref>.</p>
  4183.  
  4184. <note><p>Implementations are not required to use the JDK 1.1
  4185. implementation, nor are implementations required to be implemented in
  4186. Java.</p></note>
  4187.  
  4188. <note><p>Stylesheets can use other facilities in XPath to control
  4189. rounding.</p></note>
  4190.  
  4191. <e:element-syntax name="decimal-format">
  4192.   <e:in-category name="top-level-element"/>
  4193.   
  4194.   <e:attribute name="name">
  4195.     <e:data-type name="qname"/>
  4196.   </e:attribute>
  4197.   <e:attribute name="decimal-separator">
  4198.     <e:data-type name="char"/>
  4199.   </e:attribute>
  4200.   <e:attribute name="grouping-separator">
  4201.     <e:data-type name="char"/>
  4202.   </e:attribute>
  4203.   <e:attribute name="infinity">
  4204.     <e:data-type name="string"/>
  4205.   </e:attribute>
  4206.   <e:attribute name="minus-sign">
  4207.     <e:data-type name="char"/>
  4208.   </e:attribute>
  4209.   <e:attribute name="NaN">
  4210.     <e:data-type name="string"/>
  4211.   </e:attribute>
  4212.   <e:attribute name="percent">
  4213.     <e:data-type name="char"/>
  4214.   </e:attribute>
  4215.   <e:attribute name="per-mille">
  4216.     <e:data-type name="char"/>
  4217.   </e:attribute>
  4218.   <e:attribute name="zero-digit">
  4219.     <e:data-type name="char"/>
  4220.   </e:attribute>
  4221.   <e:attribute name="digit">
  4222.     <e:data-type name="char"/>
  4223.   </e:attribute>
  4224.   <e:attribute name="pattern-separator">
  4225.     <e:data-type name="char"/>
  4226.   </e:attribute>
  4227.   <e:empty/>
  4228. </e:element-syntax>
  4229.  
  4230. <p>The <code>xsl:decimal-format</code> element declares a
  4231. decimal-format, which controls the interpretation of a format pattern
  4232. used by the <function>format-number</function> function.  If there is
  4233. a <code>name</code> attribute, then the element declares a named
  4234. decimal-format; otherwise, it declares the default decimal-format.
  4235. The value of the <code>name</code> attribute is a <xnt
  4236. href="&XMLNames;#NT-QName">QName</xnt>, which is expanded as described
  4237. in <specref ref="qname"/>.  It is an error to declare either the
  4238. default decimal-format or a decimal-format with a given name more than
  4239. once (even with different <termref def="dt-import-precedence">import
  4240. precedence</termref>), unless it is declared every time with the same
  4241. value for all attributes (taking into account any default values).</p>
  4242.  
  4243. <p>The other attributes on <code>xsl:decimal-format</code> correspond
  4244. to the methods on the JDK 1.1 <loc href=
  4245. "http://java.sun.com/products/jdk/1.1/docs/api/java.text.DecimalFormatSymbols.html"
  4246. >DecimalFormatSymbols</loc> class.  For each
  4247. <code>get</code>/<code>set</code> method pair there is an attribute
  4248. defined for the <code>xsl:decimal-format</code> element.</p>
  4249.  
  4250. <p>The following attributes both control the interpretation of
  4251. characters in the format pattern and specify characters that may
  4252. appear in the result of formatting the number:</p>
  4253.  
  4254. <ulist>
  4255.  
  4256. <item><p><code>decimal-separator</code> specifies the character used
  4257. for the decimal sign; the default value is the period character
  4258. (<code>.</code>)</p></item>
  4259.  
  4260. <item><p><code>grouping-separator</code> specifies the character used
  4261. as a grouping (e.g. thousands) separator; the default value is the
  4262. comma character (<code>,</code>)</p></item>
  4263.  
  4264. <item><p><code>percent</code> specifies the character used as a
  4265. percent sign; the default value is the percent character
  4266. (<code>%</code>)</p></item>
  4267.  
  4268. <item><p><code>per-mille</code> specifies the character used as a per
  4269. mille sign; the default value is the Unicode per-mille character
  4270. (#x2030)</p></item>
  4271.  
  4272. <item><p><code>zero-digit</code> specifies the character used as the
  4273. digit zero; the default value is the digit zero
  4274. (<code>0</code>)</p></item>
  4275.  
  4276. </ulist>
  4277.  
  4278. <p>The following attributes control the interpretation of characters
  4279. in the format pattern:</p>
  4280.  
  4281. <ulist>
  4282.  
  4283. <item><p><code>digit</code> specifies the character used for a digit
  4284. in the format pattern; the default value is the number sign character
  4285. (<code>#</code>)</p></item>
  4286.  
  4287. <item><p><code>pattern-separator</code> specifies the character used
  4288. to separate positive and negative sub patterns in a pattern; the
  4289. default value is the semi-colon character (<code>;</code>)</p></item>
  4290.  
  4291. </ulist>
  4292.  
  4293. <p>The following attributes specify characters or strings that may
  4294. appear in the result of formatting the number:</p>
  4295.  
  4296. <ulist>
  4297.  
  4298. <item><p><code>infinity</code> specifies the string used to represent
  4299. infinity; the default value is the string
  4300. <code>Infinity</code></p></item>
  4301.  
  4302. <item><p><code>NaN</code> specifies the string used to represent the
  4303. NaN value; the default value is the string <code>NaN</code></p></item>
  4304.  
  4305. <item><p><code>minus-sign</code> specifies the character used as the
  4306. default minus sign; the default value is the hyphen-minus character
  4307. (<code>-</code>, #x2D)</p></item>
  4308.  
  4309. </ulist>
  4310.  
  4311. </div2>
  4312.  
  4313. <div2 id="misc-func">
  4314. <head>Miscellaneous Additional Functions</head>
  4315.  
  4316. <proto name="current" return-type="node-set"></proto>
  4317.  
  4318. <p>The <function>current</function> function returns a node-set that
  4319. has the <termref def="dt-current-node">current node</termref> as its
  4320. only member.  For an outermost expression (an expression not occurring
  4321. within another expression), the current node is always the same as the
  4322. context node.  Thus,</p>
  4323.  
  4324. <eg><![CDATA[<xsl:value-of select="current()"/>]]></eg>
  4325.  
  4326. <p>means the same as</p>
  4327.  
  4328. <eg><![CDATA[<xsl:value-of select="."/>]]></eg>
  4329.  
  4330. <p>However, within square brackets the current node is usually
  4331. different from the context node. For example,</p>
  4332.  
  4333. <eg><![CDATA[<xsl:apply-templates select="//glossary/item[@name=current()/@ref]"/>]]></eg>
  4334.  
  4335. <p>will process all <code>item</code> elements that have a
  4336. <code>glossary</code> parent element and that have a <code>name</code>
  4337. attribute with value equal to the value of the current node's
  4338. <code>ref</code> attribute. This is different from</p>
  4339.  
  4340. <eg><![CDATA[<xsl:apply-templates select="//glossary/item[@name=./@ref]"/>]]></eg>
  4341.  
  4342. <p>which means the same as</p>
  4343.  
  4344. <eg><![CDATA[<xsl:apply-templates select="//glossary/item[@name=@ref]"/>]]></eg>
  4345.  
  4346. <p>and so would process all <code>item</code> elements that have a
  4347. <code>glossary</code> parent element and that have a <code>name</code>
  4348. attribute and a <code>ref</code> attribute with the same value.</p>
  4349.  
  4350. <p>It is an error to use the <function>current</function> function in
  4351. a <termref def="dt-pattern">pattern</termref>.</p>
  4352.  
  4353. <proto name="unparsed-entity-uri" return-type="string"><arg type="string"/></proto>
  4354.  
  4355. <p>The <function>unparsed-entity-uri</function> returns the URI of the
  4356. unparsed entity with the specified name in the same document as the
  4357. context node (see <specref ref="unparsed-entities"/>).  It returns the
  4358. empty string if there is no such entity.</p>
  4359.  
  4360. <proto name="generate-id" return-type="string"><arg occur="opt" type="node-set"/></proto>
  4361.  
  4362. <p>The <function>generate-id</function> function returns a string that
  4363. uniquely identifies the node in the argument node-set that is first in
  4364. document order.  The unique identifier must consist of ASCII
  4365. alphanumeric characters and must start with an alphabetic character.
  4366. Thus, the string is syntactically an XML name.  An implementation is
  4367. free to generate an identifier in any convenient way provided that it
  4368. always generates the same identifier for the same node and that
  4369. different identifiers are always generated from different nodes. An
  4370. implementation is under no obligation to generate the same identifiers
  4371. each time a document is transformed.  There is no guarantee that a
  4372. generated unique identifier will be distinct from any unique IDs
  4373. specified in the source document.  If the argument node-set is empty,
  4374. the empty string is returned. If the argument is omitted, it defaults
  4375. to the context node.</p>
  4376.  
  4377. <proto name="system-property" return-type="object"><arg type="string"/></proto>
  4378.  
  4379. <p>The argument must evaluate to a string that is a <xnt
  4380. href="&XMLNames;#NT-QName">QName</xnt>.  The <xnt
  4381. href="&XMLNames;#NT-QName">QName</xnt> is expanded into a name using
  4382. the namespace declarations in scope for the expression. The
  4383. <function>system-property</function> function returns an object
  4384. representing the value of the system property identified by the name.
  4385. If there is no such system property, the empty string should be
  4386. returned.</p>
  4387.  
  4388. <p>Implementations must provide the following system properties, which
  4389. are all in the XSLT namespace:</p>
  4390.  
  4391. <slist>
  4392.  
  4393. <sitem><code>xsl:version</code>, a number giving the version of XSLT
  4394. implemented by the processor; for XSLT processors implementing the
  4395. version of XSLT specified by this document, this is the number
  4396. 1.0</sitem>
  4397.  
  4398. <sitem><code>xsl:vendor</code>, a string identifying the vendor of the
  4399. XSLT processor</sitem>
  4400.  
  4401. <sitem><code>xsl:vendor-url</code>, a string containing a URL
  4402. identifying the vendor of the XSLT processor; typically this is the
  4403. host page (home page) of the vendor's Web site.</sitem>
  4404.  
  4405. </slist>
  4406.  
  4407. </div2>
  4408.  
  4409. </div1>
  4410.  
  4411. <div1 id="message">
  4412. <head>Messages</head>
  4413.  
  4414. <e:element-syntax name="message">
  4415.   <e:in-category name="instruction"/>
  4416.   <e:attribute name="terminate">
  4417.     <e:constant value="yes"/>
  4418.     <e:constant value="no"/>
  4419.   </e:attribute>
  4420.   <e:model name="template"/>
  4421. </e:element-syntax>
  4422.  
  4423. <p>The <code>xsl:message</code> instruction sends a message in a way
  4424. that is dependent on the XSLT processor.  The content of the
  4425. <code>xsl:message</code> instruction is a template.  The
  4426. <code>xsl:message</code> is instantiated by instantiating the content
  4427. to create an XML fragment.  This XML fragment is the content of the
  4428. message.</p>
  4429.  
  4430. <note><p>An XSLT processor might implement <code>xsl:message</code> by
  4431. popping up an alert box or by writing to a log file.</p></note>
  4432.  
  4433. <p>If the <code>terminate</code> attribute has the value
  4434. <code>yes</code>, then the XSLT processor should terminate processing
  4435. after sending the message.  The default value is <code>no</code>.</p>
  4436.  
  4437. <p>One convenient way to do localization is to put the localized
  4438. information (message text, etc.) in an XML document, which becomes an
  4439. additional input file to the stylesheet.  For example, suppose
  4440. messages for a language <code><var>L</var></code> are stored in an XML
  4441. file <code>resources/<var>L</var>.xml</code> in the form:</p>
  4442.  
  4443. <eg><![CDATA[<messages>
  4444.   <message name="problem">A problem was detected.</message>
  4445.   <message name="error">An error was detected.</message>
  4446. </messages>
  4447. ]]></eg>
  4448.  
  4449. <p>Then a stylesheet could use the following approach to localize
  4450. messages:</p>
  4451.  
  4452. <eg><![CDATA[<xsl:param name="lang" select="en"/>
  4453. <xsl:variable name="messages"
  4454.   select="document(concat('resources/', $lang, '.xml'))/messages"/>
  4455.  
  4456. <xsl:template name="localized-message">
  4457.   <xsl:param name="name"/>
  4458.   <xsl:message>
  4459.     <xsl:value-of select="$messages/message[@name=$name]"/>
  4460.   </xsl:message>
  4461. </xsl:template>
  4462.  
  4463. <xsl:template name="problem">
  4464.   <xsl:call-template name="localized-message"/>
  4465.     <xsl:with-param name="name">problem</xsl:with-param>
  4466.   </xsl:call-template>
  4467. </xsl:template>]]></eg>
  4468.  
  4469. </div1>
  4470.  
  4471. <div1 id="extension">
  4472. <head>Extensions</head>
  4473.  
  4474. <p>XSLT allows two kinds of extension, extension elements and
  4475. extension functions.</p>
  4476.  
  4477. <p>This version of XSLT does not provide a mechanism for defining
  4478. implementations of extensions.  Therefore, an XSLT stylesheet that must
  4479. be portable between XSLT implementations cannot rely on particular
  4480. extensions being available.  XSLT provides mechanisms that allow an
  4481. XSLT stylesheet to determine whether the XSLT processor by which it is
  4482. being processed has implementations of particular extensions
  4483. available, and to specify what should happen if those extensions are
  4484. not available.  If an XSLT stylesheet is careful to make use of these
  4485. mechanisms, it is possible for it to take advantage of extensions and
  4486. still work with any XSLT implementation.</p>
  4487.  
  4488. <div2 id="extension-element">
  4489. <head>Extension Elements</head>
  4490.  
  4491. <p><termdef id="dt-extension-namespace" term="Extension Namespace">The
  4492. element extension mechanism allows namespaces to be designated as
  4493. <term>extension namespace</term>s. When a namespace is designated as
  4494. an extension namespace and an element with a name from that namespace
  4495. occurs in a template, then the element is treated as an instruction
  4496. rather than as a literal result element.</termdef> The namespace
  4497. determines the semantics of the instruction.</p>
  4498.  
  4499. <note><p>Since an element that is a child of an
  4500. <code>xsl:stylesheet</code> element is not occurring <emph>in a
  4501. template</emph>, non-XSLT <termref
  4502. def="dt-top-level">top-level</termref> elements are not extension
  4503. elements as defined here, and nothing in this section applies to
  4504. them.</p></note>
  4505.  
  4506. <p>A namespace is designated as an extension namespace by using an
  4507. <code>extension-element-prefixes</code> attribute on an
  4508. <code>xsl:stylesheet</code> element or an
  4509. <code>xsl:extension-element-prefixes</code> attribute on a literal
  4510. result element or extension element.
  4511. The value of both these attributes is a
  4512. whitespace-separated list of namespace prefixes. The namespace bound
  4513. to each of the prefixes is designated as an extension namespace.  It
  4514. is an error if there is no namespace bound to the prefix on the
  4515. element bearing the <code>extension-element-prefixes</code> or
  4516. <code>xsl:extension-element-prefixes</code> attribute.  The default
  4517. namespace (as declared by <code>xmlns</code>) may be designated as an
  4518. extension namespace by including <code>#default</code> in the list of
  4519. namespace prefixes.  The designation of a namespace as an extension
  4520. namespace is effective within the subtree of the stylesheet rooted at
  4521. the element bearing the <code>extension-element-prefixes</code> or
  4522. <code>xsl:extension-element-prefixes</code> attribute;
  4523. a subtree rooted at an <code>xsl:stylesheet</code> element
  4524. does not include any stylesheets imported or included by children
  4525. of that <code>xsl:stylesheet</code> element.</p>
  4526.  
  4527. <p>If the XSLT processor does not have an implementation of a
  4528. particular extension element available, then the
  4529. <function>element-available</function> function must return false for
  4530. the name of the element.  When such an extension element is
  4531. instantiated, then the XSLT processor must perform fallback for the
  4532. element as specified in <specref ref="fallback"/>.  An XSLT processor
  4533. must not signal an error merely because a template contains an
  4534. extension element for which no implementation is available.</p>
  4535.  
  4536. <p>If the XSLT processor has an implementation of a particular
  4537. extension element available, then the
  4538. <function>element-available</function> function must return true for
  4539. the name of the element.</p>
  4540.  
  4541. </div2>
  4542.  
  4543. <div2>
  4544. <head>Extension Functions</head>
  4545.  
  4546. <p>If a <xnt href="&XPath;#NT-FunctionName">FunctionName</xnt> in a
  4547. <xnt href="&XPath;#NT-FunctionCall">FunctionCall</xnt> expression is
  4548. not an <xnt href="&XMLNames;#NT-NCName">NCName</xnt> (i.e. if it
  4549. contains a colon), then it is treated as a call to an extension
  4550. function.  The <xnt href="&XPath;#NT-FunctionName">FunctionName</xnt>
  4551. is expanded to a name using the namespace declarations from the
  4552. evaluation context.</p>
  4553.  
  4554. <p>If the XSLT processor does not have an implementation of an
  4555. extension function of a particular name available, then the
  4556. <function>function-available</function> function must return false for
  4557. that name.  If such an extension function occurs in an expression and
  4558. the extension function is actually called, the XSLT processor must
  4559. signal an error.  An XSLT processor must not signal an error merely
  4560. because an expression contains an extension function for which no
  4561. implementation is available.</p>
  4562.  
  4563. <p>If the XSLT processor has an implementation of an extension
  4564. function of a particular name available, then the
  4565. <function>function-available</function> function must return
  4566. true for that name. If such an extension is called, then the XSLT
  4567. processor must call the implementation passing it the function call
  4568. arguments; the result returned by the implementation is returned as
  4569. the result of the function call.</p>
  4570.  
  4571. </div2>
  4572.  
  4573. </div1>
  4574.  
  4575. <div1 id="fallback">
  4576. <head>Fallback</head>
  4577.  
  4578. <e:element-syntax name="fallback">
  4579.   <e:in-category name="instruction"/>
  4580.   <e:model name="template"/>
  4581. </e:element-syntax>
  4582.  
  4583. <p>Normally, instantiating an <code>xsl:fallback</code> element does
  4584. nothing.  However, when an XSLT processor performs fallback for an
  4585. instruction element, if the instruction element has one or more
  4586. <code>xsl:fallback</code> children, then the content of each of the
  4587. <code>xsl:fallback</code> children must be instantiated in sequence;
  4588. otherwise, an error must be signaled. The content of an
  4589. <code>xsl:fallback</code> element is a template.</p>
  4590.  
  4591. <p>The following functions can be used with the
  4592. <code>xsl:choose</code> and <code>xsl:if</code> instructions to
  4593. explicitly control how a stylesheet should behave if particular
  4594. elements or functions are not available.</p>
  4595.  
  4596. <proto name="element-available" return-type="boolean"><arg
  4597. type="string"/></proto>
  4598.  
  4599. <p>The argument must evaluate to a string that is a <xnt
  4600. href="&XMLNames;#NT-QName">QName</xnt>.  The <xnt
  4601. href="&XMLNames;#NT-QName">QName</xnt> is expanded into an <xtermref
  4602. href="&XPath;#dt-expanded-name">expanded-name</xtermref> using the
  4603. namespace declarations in scope for the expression. The
  4604. <function>element-available</function> function returns true if and
  4605. only if the expanded-name is the name of an instruction.  If the
  4606. expanded-name has a namespace URI equal to the XSLT namespace URI,
  4607. then it refers to an element defined by XSLT.  Otherwise, it refers to
  4608. an extension element. If the expanded-name has a null namespace URI,
  4609. the <function>element-available</function> function will return
  4610. false.</p>
  4611.  
  4612. <proto name="function-available" return-type="boolean"><arg
  4613. type="string"/></proto>
  4614.  
  4615. <p>The argument must evaluate to a string that is a <xnt
  4616. href="&XMLNames;#NT-QName">QName</xnt>.  The <xnt
  4617. href="&XMLNames;#NT-QName">QName</xnt> is expanded into an <xtermref
  4618. href="&XPath;#dt-expanded-name">expanded-name</xtermref> using the
  4619. namespace declarations in scope for the expression. The
  4620. <function>function-available</function> function returns true if and
  4621. only if the expanded-name is the name of a function in the function
  4622. library. If the expanded-name has a non-null namespace URI, then it
  4623. refers to an extension function; otherwise, it refers to a function
  4624. defined by XPath or XSLT.</p>
  4625.  
  4626. </div1>
  4627.  
  4628. <div1 id="output">
  4629. <head>Output</head>
  4630.  
  4631. <e:element-syntax name="output">
  4632.   <e:in-category name="top-level-element"/>
  4633.   <e:attribute name="method">
  4634.     <e:constant value="xml"/>
  4635.     <e:constant value="html"/>
  4636.     <e:constant value="text"/>
  4637.     <e:data-type name="qname-but-not-ncname"/>
  4638.   </e:attribute>
  4639.   <e:attribute name="version">
  4640.     <e:data-type name="nmtoken"/>
  4641.   </e:attribute>
  4642.   <e:attribute name="encoding">
  4643.     <e:data-type name="string"/>
  4644.   </e:attribute>
  4645.   <e:attribute name="omit-xml-declaration">
  4646.     <e:constant value="yes"/>
  4647.     <e:constant value="no"/>
  4648.   </e:attribute>
  4649.   <e:attribute name="standalone">
  4650.     <e:constant value="yes"/>
  4651.     <e:constant value="no"/>
  4652.   </e:attribute>
  4653.   <e:attribute name="doctype-public">
  4654.     <e:data-type name="string"/>
  4655.   </e:attribute>
  4656.   <e:attribute name="doctype-system">
  4657.     <e:data-type name="string"/>
  4658.   </e:attribute>
  4659.   <e:attribute name="cdata-section-elements">
  4660.     <e:data-type name="qnames"/>
  4661.   </e:attribute>
  4662.   <e:attribute name="indent">
  4663.     <e:constant value="yes"/>
  4664.     <e:constant value="no"/>
  4665.   </e:attribute>
  4666.   <e:attribute name="media-type">
  4667.     <e:data-type name="string"/>
  4668.   </e:attribute>
  4669.   <e:empty/>
  4670. </e:element-syntax>
  4671.  
  4672. <p>An XSLT processor may output the result tree as a sequence of
  4673. bytes, although it is not required to be able to do so (see <specref
  4674. ref="conformance"/>). The <code>xsl:output</code> element allows
  4675. stylesheet authors to specify how they wish the result tree to be
  4676. output. If an XSLT processor outputs the result tree, it should do so
  4677. as specified by the <code>xsl:output</code> element; however, it is
  4678. not required to do so.</p>
  4679.  
  4680. <p>The <code>xsl:output</code> element is only allowed as a <termref
  4681. def="dt-top-level">top-level</termref> element.</p>
  4682.  
  4683. <p>The <code>method</code> attribute on <code>xsl:output</code>
  4684. identifies the overall method that should be used for outputting the
  4685. result tree.  The value must be a <xnt
  4686. href="&XMLNames;#NT-QName">QName</xnt>.  If the <xnt
  4687. href="&XMLNames;#NT-QName">QName</xnt> does not have a prefix, then it
  4688. identifies a method specified in this document and must be one of
  4689. <code>xml</code>, <code>html</code> or <code>text</code>.  If the <xnt
  4690. href="&XMLNames;#NT-QName">QName</xnt> has a prefix, then the <xnt
  4691. href="&XMLNames;#NT-QName">QName</xnt> is expanded into an <xtermref
  4692. href="&XPath;#dt-expanded-name">expanded-name</xtermref> as described
  4693. in <specref ref="qname"/>; the expanded-name identifies the output
  4694. method; the behavior in this case is not specified by this
  4695. document.</p>
  4696.  
  4697. <p>The default for the <code>method</code> attribute is chosen as
  4698. follows.  If</p>
  4699.  
  4700. <ulist>
  4701.  
  4702. <item><p>the root node of the result tree has an element
  4703. child,</p></item>
  4704.  
  4705. <item><p>the expanded-name of the first element child of the root node
  4706. (i.e. the document element) of the result tree has local part
  4707. <code>html</code> (in any combination of upper and lower case) and a
  4708. null namespace URI, and</p></item>
  4709.  
  4710. <item><p>any text nodes preceding the first element child of the root
  4711. node of the result tree contain only whitespace characters,</p></item>
  4712.  
  4713. </ulist>
  4714.  
  4715. <p>then the default output method is <code>html</code>; otherwise, the
  4716. default output method is <code>xml</code>.  The default output method
  4717. should be used if there are no <code>xsl:output</code> elements or if
  4718. none of the <code>xsl:output</code> elements specifies a value for the
  4719. <code>method</code> attribute.</p>
  4720.  
  4721. <p>The other attributes on <code>xsl:output</code> provide parameters
  4722. for the output method.  The following attributes are allowed:</p>
  4723.  
  4724. <ulist>
  4725.  
  4726. <item><p><code>version</code> specifies the version of the output
  4727. method</p></item>
  4728.  
  4729. <item><p><code>indent</code> specifies whether the XSLT processor may
  4730. add additional whitespace when outputting the result tree; the value
  4731. must be <code>yes</code> or <code>no</code></p></item>
  4732.  
  4733. <item><p><code>encoding</code> specifies the preferred character
  4734. encoding that the XSLT processor should use to encode sequences of
  4735. characters as sequences of bytes; the value of the attribute should be
  4736. treated case-insensitively; the value must contain only characters in
  4737. the range #x21 to #x7E (i.e. printable ASCII characters); the value
  4738. should either be a <code>charset</code> registered with the Internet
  4739. Assigned Numbers Authority <bibref ref="IANA"/>, <bibref
  4740. ref="RFC2278"/> or start with <code>X-</code></p></item>
  4741.  
  4742. <item><p><code>media-type</code> specifies the media type (MIME
  4743. content type) of the data that results from outputting the result
  4744. tree; the <code>charset</code> parameter should not be specified
  4745. explicitly; instead, when the top-level media type is
  4746. <code>text</code>, a <code>charset</code> parameter should be added
  4747. according to the character encoding actually used by the output
  4748. method</p></item>
  4749.  
  4750. <item><p><code>doctype-system</code> specifies the system identifier
  4751. to be used in the document type declaration</p></item>
  4752.  
  4753. <item><p><code>doctype-public</code> specifies the public identifier
  4754. to be used in the document type declaration</p></item>
  4755.  
  4756. <item><p><code>omit-xml-declaration</code> specifies whether the XSLT
  4757. processor should output an XML declaration; the value must be
  4758. <code>yes</code> or <code>no</code></p></item>
  4759.  
  4760. <item><p><code>standalone</code> specifies whether the XSLT processor
  4761. should output a standalone document declaration; the value must be
  4762. <code>yes</code> or <code>no</code></p></item>
  4763.  
  4764. <item><p><code>cdata-section-elements</code> specifies a list of the
  4765. names of elements whose text node children should be output using
  4766. CDATA sections</p></item>
  4767.  
  4768. </ulist>
  4769.  
  4770. <p>The detailed semantics of each attribute will be described
  4771. separately for each output method for which it is applicable.  If the
  4772. semantics of an attribute are not described for an output method, then
  4773. it is not applicable to that output method.</p>
  4774.  
  4775. <p>A stylesheet may contain multiple <code>xsl:output</code> elements
  4776. and may include or import stylesheets that also contain
  4777. <code>xsl:output</code> elements.  All the <code>xsl:output</code>
  4778. elements occurring in a stylesheet are merged into a single effective
  4779. <code>xsl:output</code> element. For the
  4780. <code>cdata-section-elements</code> attribute, the effective value is
  4781. the union of the specified values.  For other attributes, the
  4782. effective value is the specified value with the highest <termref
  4783. def="dt-import-precedence">import precedence</termref>. It is an error
  4784. if there is more than one such value for an attribute.  An XSLT
  4785. processor may signal the error; if it does not signal the error, if
  4786. should recover by using the value that occurs last in the stylesheet.
  4787. The values of attributes are defaulted after the
  4788. <code>xsl:output</code> elements have been merged; different output
  4789. methods may have different default values for an attribute.</p>
  4790.  
  4791. <div2>
  4792. <head>XML Output Method</head>
  4793.  
  4794. <p>The <code>xml</code> output method outputs the result tree as a
  4795. well-formed XML external general parsed entity. If the root node of
  4796. the result tree has a single element node child and no text node
  4797. children, then the entity should also be a well-formed XML document
  4798. entity. When the entity is referenced within a trivial XML document
  4799. wrapper like this</p>
  4800.  
  4801. <eg><![CDATA[
  4802. <!DOCTYPE doc [
  4803. <!ENTITY e SYSTEM "]]><var>entity-URI</var><![CDATA[">
  4804. ]>
  4805. <doc>&e;</doc>]]></eg>
  4806.  
  4807. <p>where <code><var>entity-URI</var></code> is a URI for the entity,
  4808. then the wrapper
  4809. document as a whole should be a well-formed XML document conforming to
  4810. the XML Namespaces Recommendation <bibref ref="XMLNAMES"/>.  In
  4811. addition, the output should be such that if a new tree was constructed
  4812. by parsing the wrapper as an XML document as specified in <specref
  4813. ref="data-model"/>, and then removing the document element, making its
  4814. children instead be children of the root node, then the new tree would
  4815. be the same as the result tree, with the following possible
  4816. exceptions:</p>
  4817.  
  4818. <ulist>
  4819.  
  4820. <item><p>The order of attributes in the two trees may be
  4821. different.</p></item>
  4822.  
  4823. <item><p>The new tree may contain namespace nodes that were not
  4824. present in the result tree.</p>
  4825. <note><p>An XSLT processor may need to add
  4826. namespace declarations in the course of outputting the result tree as
  4827. XML.</p></note>
  4828. </item>
  4829.  
  4830. </ulist>
  4831.  
  4832. <p>If the XSLT processor generated a document type declaration because
  4833. of the <code>doctype-system</code> attribute, then the above
  4834. requirements apply to the entity with the generated document type
  4835. declaration removed.</p>
  4836.  
  4837. <p>The <code>version</code> attribute specifies the version of XML to
  4838. be used for outputting the result tree.  If the XSLT processor does
  4839. not support this version of XML, it should use a version of XML that
  4840. it does support.  The version output in the XML declaration (if an XML
  4841. declaration is output) should correspond to the version of XML that
  4842. the processor used for outputting the result tree. The value of the
  4843. <code>version</code> attribute should match the <xnt
  4844. href="&XML;#NT-VersionNum">VersionNum</xnt> production of the XML
  4845. Recommendation <bibref ref="XML"/>. The default value is
  4846. <code>1.0</code>.</p>
  4847.  
  4848. <p>The <code>encoding</code> attribute specifies the preferred
  4849. encoding to use for outputting the result tree.  XSLT processors are
  4850. required to respect values of <code>UTF-8</code> and
  4851. <code>UTF-16</code>.  For other values, if the XSLT processor does not
  4852. support the specified encoding it may signal an error; if it does not
  4853. signal an error it should use <code>UTF-8</code> or
  4854. <code>UTF-16</code> instead.  The XSLT processor must not use an
  4855. encoding whose name does not match the <xnt
  4856. href="&XML;#NT-EncName">EncName</xnt> production of the XML
  4857. Recommendation <bibref ref="XML"/>.  If no <code>encoding</code>
  4858. attribute is specified, then the XSLT processor should use either
  4859. <code>UTF-8</code> or <code>UTF-16</code>.  It is possible that the
  4860. result tree will contain a character that cannot be represented in the
  4861. encoding that the XSLT processor is using for output.  In this case,
  4862. if the character occurs in a context where XML recognizes character
  4863. references (i.e. in the value of an attribute node or text node), then
  4864. the character should be output as a character reference; otherwise
  4865. (for example if the character occurs in the name of an element) the
  4866. XSLT processor should signal an error.</p>
  4867.  
  4868. <p>If the <code>indent</code> attribute has the value
  4869. <code>yes</code>, then the <code>xml</code> output method may output
  4870. whitespace in addition to the whitespace in the result tree (possibly
  4871. based on whitespace stripped from either the source document or the
  4872. stylesheet) in order to indent the result nicely; if the
  4873. <code>indent</code> attribute has the value <code>no</code>, it should
  4874. not output any additional whitespace. The default value is
  4875. <code>no</code>.  The <code>xml</code> output method should use an
  4876. algorithm to output additional whitespace that ensures that the result
  4877. if whitespace were to be stripped from the output using the process
  4878. described in <specref ref="strip"/> with the set of
  4879. whitespace-preserving elements consisting of just
  4880. <code>xsl:text</code> would be the same when additional whitespace is
  4881. output as when additional whitespace is not output.</p>
  4882.  
  4883. <note><p>It is usually not safe to use <code>indent="yes"</code> with
  4884. document types that include element types with mixed content.</p></note>
  4885.  
  4886. <p>The <code>cdata-section-elements</code> attribute contains a
  4887. whitespace-separated list of <xnt
  4888. href="&XMLNames;#NT-QName">QName</xnt>s.  Each <xnt
  4889. href="&XMLNames;#NT-QName">QName</xnt> is expanded into an
  4890. expanded-name using the namespace declarations in effect on the
  4891. <code>xsl:output</code> element in which the <xnt
  4892. href="&XMLNames;#NT-QName">QName</xnt> occurs; if there is a default
  4893. namespace, it is used for <xnt href="&XMLNames;#NT-QName">QName</xnt>s
  4894. that do not have a prefix.  The expansion is performed before the
  4895. merging of multiple <code>xsl:output</code> elements into a single
  4896. effective <code>xsl:output</code> element. If the expanded-name of the
  4897. parent of a text node is a member of the list, then the text node
  4898. should be output as a CDATA section. For example,</p>
  4899.  
  4900. <eg><![CDATA[<xsl:output cdata-section-elements="example"/>]]></eg>
  4901.  
  4902. <p>would cause a literal result element written in the stylesheet as</p>
  4903.  
  4904. <eg><![CDATA[<example><foo></example>]]></eg>
  4905.  
  4906. <p>or as</p>
  4907.  
  4908. <eg><example><![CDATA[<foo>]]></example></eg>
  4909.  
  4910. <p>to be output as</p>
  4911.  
  4912. <eg><example><![CDATA[<foo>]]></example></eg>
  4913.  
  4914. <p>If the text node contains the sequence of characters
  4915. <code>]]></code>, then the currently open CDATA section should be
  4916. closed following the <code>]]</code> and a new CDATA section opened
  4917. before the <code>></code>. For example, a literal result element
  4918. written in the stylesheet as</p>
  4919.  
  4920. <eg><example>]]&gt;</example></eg>
  4921.  
  4922. <p>would be output as</p>
  4923.  
  4924. <eg><example><![CDATA[]]]]><![CDATA[>]]></example></eg>
  4925.  
  4926. <p>If the text node contains a character that is not representable in
  4927. the character encoding being used to output the result tree, then the
  4928. currently open CDATA section should be closed before the character,
  4929. the character should be output using a character reference or entity
  4930. reference, and a new CDATA section should be opened for any further
  4931. characters in the text node.</p>
  4932.  
  4933. <p>CDATA sections should not be used except for text nodes that the
  4934. <code>cdata-section-elements</code> attribute explicitly specifies
  4935. should be output using CDATA sections.</p>
  4936.  
  4937. <p>The <code>xml</code> output method should output an XML declaration
  4938. unless the <code>omit-xml-declaration</code> attribute has the value
  4939. <code>yes</code>. The XML declaration should include both version
  4940. information and an encoding declaration. If the
  4941. <code>standalone</code> attribute is specified, it should include a
  4942. standalone document declaration with the same value as the value as
  4943. the value of the <code>standalone</code> attribute.  Otherwise, it
  4944. should not include a standalone document declaration; this ensures
  4945. that it is both a XML declaration (allowed at the beginning of a
  4946. document entity) and a text declaration (allowed at the beginning of
  4947. an external general parsed entity).</p>
  4948.  
  4949. <p>If the <code>doctype-system</code> attribute is specified, the
  4950. <code>xml</code> output method should output a document type
  4951. declaration immediately before the first element.  The name following
  4952. <code><!DOCTYPE</code> should be the name of the first element.  If
  4953. <code>doctype-public</code> attribute is also specified, then the
  4954. <code>xml</code> output method should output <code>PUBLIC</code>
  4955. followed by the public identifier and then the system identifier;
  4956. otherwise, it should output <code>SYSTEM</code> followed by the system
  4957. identifier.  The internal subset should be empty.  The
  4958. <code>doctype-public</code> attribute should be ignored unless the
  4959. <code>doctype-system</code> attribute is specified.</p>
  4960.  
  4961. <p>The <code>media-type</code> attribute is applicable for the
  4962. <code>xml</code> output method.  The default value for the
  4963. <code>media-type</code> attribute is <code>text/xml</code>.</p>
  4964.  
  4965. </div2>
  4966.  
  4967. <div2>
  4968. <head>HTML Output Method</head>
  4969.  
  4970. <p>The <code>html</code> output method outputs the result tree as
  4971. HTML; for example,</p>
  4972.  
  4973. <eg><xsl:stylesheet version="1.0"
  4974.                 xmlns:xsl="&XSLT.ns;"><![CDATA[
  4975.  
  4976. <xsl:output method="html"/>
  4977.  
  4978. <xsl:template match="/">
  4979.   <html>
  4980.    <xsl:apply-templates/>
  4981.   </html>
  4982. </xsl:template>
  4983.  
  4984. ...
  4985.  
  4986. </xsl:stylesheet>]]></eg>
  4987.  
  4988. <p>The <code>version</code> attribute indicates the version of the
  4989. HTML.  The default value is <code>4.0</code>, which specifies that the
  4990. result should be output as HTML conforming to the HTML 4.0
  4991. Recommendation <bibref ref="HTML"/>.</p>
  4992.  
  4993. <p>The <code>html</code> output method should not output an element
  4994. differently from the <code>xml</code> output method unless the
  4995. expanded-name of the element has a null namespace URI; an element
  4996. whose expanded-name has a non-null namespace URI should be output as
  4997. XML.  If the expanded-name of the element has a null namespace URI,
  4998. but the local part of the expanded-name is not recognized as the name
  4999. of an HTML element, the element should output in the same way as a
  5000. non-empty, inline element such as <code>span</code>.</p>
  5001.  
  5002. <p>The <code>html</code> output method should not output an end-tag
  5003. for empty elements.  For HTML 4.0, the empty elements are
  5004. <code>area</code>, <code>base</code>, <code>basefont</code>,
  5005. <code>br</code>, <code>col</code>, <code>frame</code>,
  5006. <code>hr</code>, <code>img</code>, <code>input</code>,
  5007. <code>isindex</code>, <code>link</code>, <code>meta</code> and
  5008. <code>param</code>. For example, an element written as
  5009. <code><br/></code> or <code><br></br></code> in the
  5010. stylesheet should be output as <code><br></code>.</p>
  5011.  
  5012. <p>The <code>html</code> output method should recognize the names of
  5013. HTML elements regardless of case.  For example, elements named
  5014. <code>br</code>, <code>BR</code> or <code>Br</code> should all be
  5015. recognized as the HTML <code>br</code> element and output without an
  5016. end-tag.</p>
  5017.  
  5018. <p>The <code>html</code> output method should not perform escaping for
  5019. the content of the <code>script</code> and <code>style</code>
  5020. elements. For example, a literal result element written in the
  5021. stylesheet as</p>
  5022.  
  5023. <eg><![CDATA[<script>if (a < b) foo()</script>]]></eg>
  5024.  
  5025. <p>or</p>
  5026.  
  5027. <eg><![CDATA[<script><![CDATA[if (a < b) foo()]]]]><![CDATA[></script>]]></eg>
  5028.  
  5029. <p>should be output as</p>
  5030.  
  5031. <eg><![CDATA[<script>if (a < b) foo()</script>]]></eg>
  5032.  
  5033. <p>The <code>html</code> output method should not escape
  5034. <code><</code> characters occurring in attribute values.</p>
  5035.  
  5036. <p>If the <code>indent</code> attribute has the value
  5037. <code>yes</code>, then the <code>html</code> output method may add or
  5038. remove whitespace as it outputs the result tree, so long as it does
  5039. not change how an HTML user agent would render the output.  The
  5040. default value is <code>yes</code>.</p>
  5041.  
  5042. <p>The <code>html</code> output method should escape non-ASCII
  5043. characters in URI attribute values using the method recommended in
  5044. <loc
  5045. href="http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.2.1">Section
  5046. B.2.1</loc> of the HTML 4.0 Recommendation.</p>
  5047.  
  5048. <p>The <code>html</code> output method may output a character using a
  5049. character entity reference, if one is defined for it in the version of
  5050. HTML that the output method is using.</p>
  5051.  
  5052. <p>The <code>html</code> output method should terminate processing
  5053. instructions with <code>></code> rather than
  5054. <code>?></code>.</p>
  5055.  
  5056. <p>The <code>html</code> output method should output boolean
  5057. attributes (that is attributes with only a single allowed value that
  5058. is equal to the name of the attribute) in minimized form. For example,
  5059. a start-tag written in the stylesheet as</p>
  5060.  
  5061. <eg><![CDATA[<OPTION selected="selected">]]></eg>
  5062.  
  5063. <p>should be output as</p>
  5064.  
  5065. <eg><![CDATA[<OPTION selected>]]></eg>
  5066.  
  5067. <p>The <code>html</code> output method should not escape a
  5068. <code>&</code> character occurring in an attribute value
  5069. immediately followed by a <code>{</code> character (see <loc
  5070. href="http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.7.1.1">Section
  5071. B.7.1</loc> of the HTML 4.0 Recommendation). For example, a start-tag
  5072. written in the stylesheet as</p>
  5073.  
  5074. <eg><![CDATA[<BODY bgcolor='&{{randomrbg}};'>]]></eg>
  5075.  
  5076. <p>should be output as</p>
  5077.  
  5078. <eg><![CDATA[<BODY bgcolor='&{randomrbg};'>]]></eg>
  5079.  
  5080. <p>The <code>encoding</code> attribute specifies the preferred
  5081. encoding to be used. If there is a <code>HEAD</code> element, then the
  5082. <code>html</code> output method should add a <code>META</code> element
  5083. immediately after the start-tag of the <code>HEAD</code> element
  5084. specifying the character encoding actually used. For example,</p>
  5085.  
  5086. <eg><![CDATA[<HEAD>
  5087. <META http-equiv="Content-Type" content="text/html; charset=EUC-JP">
  5088. ...]]></eg>
  5089.  
  5090. <p>It is possible that the result tree will contain a character that
  5091. cannot be represented in the encoding that the XSLT processor is using
  5092. for output.  In this case, if the character occurs in a context where
  5093. HTML recognizes character references, then the character should be
  5094. output as a character entity reference or decimal numeric character
  5095. reference; otherwise (for example, in a
  5096. <code>script</code> or <code>style</code> element or in a comment),
  5097. the XSLT processor should signal an error.</p>
  5098.  
  5099. <p>If the <code>doctype-public</code> or <code>doctype-system</code>
  5100. attributes are specified, then the <code>html</code> output method
  5101. should output a document type declaration immediately before the first
  5102. element.  The name following <code><!DOCTYPE</code> should be
  5103. <code>HTML</code> or <code>html</code>.  If the
  5104. <code>doctype-public</code> attribute is specified, then the output
  5105. method should output <code>PUBLIC</code> followed by the specified
  5106. public identifier; if the <code>doctype-system</code> attribute is
  5107. also specified, it should also output the specified system identifier
  5108. following the public identifier.  If the <code>doctype-system</code>
  5109. attribute is specified but the <code>doctype-public</code> attribute
  5110. is not specified, then the output method should output
  5111. <code>SYSTEM</code> followed by the specified system identifier.</p>
  5112.  
  5113. <p>The <code>media-type</code> attribute is applicable for the
  5114. <code>html</code> output method.  The default value is
  5115. <code>text/html</code>.</p>
  5116.  
  5117. </div2>
  5118.  
  5119. <div2>
  5120. <head>Text Output Method</head>
  5121.  
  5122. <p>The <code>text</code> output method outputs the result tree by
  5123. outputting the string-value of every text node in the result tree in
  5124. document order without any escaping.</p>
  5125.  
  5126. <p>The <code>media-type</code> attribute is applicable for the
  5127. <code>text</code> output method.  The default value for the
  5128. <code>media-type</code> attribute is <code>text/plain</code>.</p>
  5129.  
  5130. <p>The <code>encoding</code> attribute identifies the encoding that
  5131. the <code>text</code> output method should use to convert sequences of
  5132. characters to sequences of bytes.  The default is system-dependent. If
  5133. the result tree contains a character that cannot be represented in the
  5134. encoding that the XSLT processor is using for output, the XSLT
  5135. processor should signal an error.</p>
  5136.  
  5137. </div2>
  5138.  
  5139. <div2 id="disable-output-escaping">
  5140. <head>Disabling Output Escaping</head>
  5141.  
  5142. <p>Normally, the <code>xml</code> output method escapes & and <
  5143. (and possibly other characters) when outputting text nodes.  This
  5144. ensures that the output is well-formed XML. However, it is sometimes
  5145. convenient to be able to produce output that is almost, but not quite
  5146. well-formed XML; for example, the output may include ill-formed
  5147. sections which are intended to be transformed into well-formed XML by
  5148. a subsequent non-XML aware process.  For this reason, XSLT provides a
  5149. mechanism for disabling output escaping. An <code>xsl:value-of</code>
  5150. or <code>xsl:text</code> element may have a
  5151. <code>disable-output-escaping</code> attribute; the allowed values are
  5152. <code>yes</code> or <code>no</code>; the default is <code>no</code>;
  5153. if the value is <code>yes</code>, then a text node generated by
  5154. instantiating the <code>xsl:value-of</code> or <code>xsl:text</code>
  5155. element should be output without any escaping. For example,</p>
  5156.  
  5157. <eg><![CDATA[<xsl:text disable-output-escaping="yes"><</xsl:text>]]></eg>
  5158.  
  5159. <p>should generate the single character <code><</code>.</p>
  5160.  
  5161. <p>It is an error for output escaping to be disabled for a text node
  5162. that is used for something other than a text node in the result tree.
  5163. Thus, it is an error to disable output escaping for an
  5164. <code>xsl:value-of</code> or <code>xsl:text</code> element that is
  5165. used to generate the string-value of a comment, processing instruction
  5166. or attribute node; it is also an error to convert a <termref
  5167. def="dt-result-tree-fragment">result tree fragment</termref> to a
  5168. number or a string if the result tree fragment contains a text node for
  5169. which escaping was disabled.  In both cases, an XSLT processor may
  5170. signal the error; if it does not signal the error, it must recover by
  5171. ignoring the <code>disable-output-escaping</code> attribute.</p>
  5172.  
  5173. <p>The <code>disable-output-escaping</code> attribute may be used with
  5174. the <code>html</code> output method as well as with the
  5175. <code>xml</code> output method.  The <code>text</code> output method
  5176. ignores the <code>disable-output-escaping</code> attribute, since it
  5177. does not perform any output escaping.</p>
  5178.  
  5179. <p>An XSLT processor will only be able to disable output escaping if
  5180. it controls how the result tree is output. This may not always be the
  5181. case.  For example, the result tree may be used as the source tree for
  5182. another XSLT transformation instead of being output.  An XSLT
  5183. processor is not required to support disabling output escaping.  If an
  5184. <code>xsl:value-of</code> or <code>xsl:text</code> specifies that
  5185. output escaping should be disabled and the XSLT processor does not
  5186. support this, the XSLT processor may signal an error; if it does not
  5187. signal an error, it must recover by not disabling output escaping.</p>
  5188.  
  5189. <p>If output escaping is disabled for a character that is not
  5190. representable in the encoding that the XSLT processor is using for
  5191. output, then the XSLT processor may signal an error; if it does not
  5192. signal an error, it must recover by not disabling output escaping.</p>
  5193.  
  5194. <p>Since disabling output escaping may not work with all XSLT
  5195. processors and can result in XML that is not well-formed, it should be
  5196. used only when there is no alternative.</p>
  5197.  
  5198.  
  5199. </div2>
  5200.  
  5201. </div1>
  5202.  
  5203. <div1 id="conformance">
  5204. <head>Conformance</head>
  5205.  
  5206. <p>A conforming XSLT processor must be able to use a stylesheet to
  5207. transform a source tree into a result tree as specified in this
  5208. document.  A conforming XSLT processor need not be able to output the
  5209. result in XML or in any other form.</p>
  5210.  
  5211. <note><p>Vendors of XSLT processors are strongly encouraged to provide
  5212. a way to verify that their processor is behaving conformingly by
  5213. allowing the result tree to be output as XML or by providing access to
  5214. the result tree through a standard API such as the DOM or
  5215. SAX.</p></note>
  5216.  
  5217. <p>A conforming XSLT processor must signal any errors except for those
  5218. that this document specifically allows an XSLT processor not to
  5219. signal. A conforming XSLT processor may but need not recover from any
  5220. errors that it signals.</p>
  5221.  
  5222. <p>A conforming XSLT processor may impose limits on the processing
  5223. resources consumed by the processing of a stylesheet.</p>
  5224.  
  5225. </div1>
  5226.  
  5227. <div1 id="notation">
  5228. <head>Notation</head>
  5229.  
  5230. <p>The specification of each XSLT-defined element type is preceded by
  5231. a summary of its syntax in the form of a model for elements of that
  5232. element type.  The meaning of syntax summary notation is as
  5233. follows:</p>
  5234.  
  5235. <ulist>
  5236.  
  5237. <item><p>An attribute is required if and only if its name is in
  5238. bold.</p></item>
  5239.  
  5240. <item><p>The string that occurs in the place of an attribute value
  5241. specifies the allowed values of the attribute.  If this is surrounded
  5242. by curly braces, then the attribute value is treated as an <termref
  5243. def="dt-attribute-value-template">attribute value template</termref>,
  5244. and the string occurring within curly braces specifies the allowed
  5245. values of the result of instantiating the attribute value template.
  5246. Alternative allowed values are separated by <code>|</code>.  A quoted
  5247. string indicates a value equal to that specific string. An unquoted,
  5248. italicized name specifies a particular type of value.</p></item>
  5249.  
  5250. <item><p>If the element is allowed not to be empty, then the element
  5251. contains a comment specifying the allowed content.  The allowed
  5252. content is specified in a similar way to an element type declaration
  5253. in XML; <emph>template</emph> means that any mixture of text nodes,
  5254. literal result elements, extension elements, and XSLT elements from
  5255. the <code>instruction</code> category is allowed;
  5256. <emph>top-level-elements</emph> means that any mixture of XSLT
  5257. elements from the <code>top-level-element</code> category is
  5258. allowed.</p></item>
  5259.  
  5260. <item><p>The element is prefaced by comments indicating if it belongs
  5261. to the <code>instruction</code> category or
  5262. <code>top-level-element</code> category or both.  The category of an
  5263. element just affects whether it is allowed in the content of elements
  5264. that allow a <emph>template</emph> or
  5265. <emph>top-level-elements</emph>.</p></item>
  5266.  
  5267. </ulist>
  5268.  
  5269. </div1>
  5270.  
  5271. </body>
  5272.  
  5273. <back>
  5274. <div1>
  5275. <head>References</head>
  5276. <div2>
  5277. <head>Normative References</head>
  5278.  
  5279. <blist>
  5280.  
  5281. <bibl id="XML" key="XML">World Wide Web Consortium. <emph>Extensible
  5282. Markup Language (XML) 1.0.</emph> W3C Recommendation. See <loc
  5283. href="http://www.w3.org/TR/1998/REC-xml-19980210">http://www.w3.org/TR/1998/REC-xml-19980210</loc></bibl>
  5284.  
  5285. <bibl id="XMLNAMES" key="XML Names">World Wide Web
  5286. Consortium. <emph>Namespaces in XML.</emph> W3C Recommendation. See
  5287. <loc
  5288. href="http://www.w3.org/TR/REC-xml-names">http://www.w3.org/TR/REC-xml-names</loc></bibl>
  5289.  
  5290. <bibl id="XPATH" key="XPath">World Wide Web Consortium. <emph>XML Path
  5291. Language.</emph> W3C Recommendation. See <loc
  5292. href="&XPath;">http://www.w3.org/TR/xpath</loc></bibl>
  5293.  
  5294. </blist>
  5295. </div2>
  5296. <div2>
  5297. <head>Other References</head>
  5298.  
  5299. <blist>
  5300.  
  5301. <bibl id="CSS2" key="CSS2">World Wide Web Consortium.  <emph>Cascading
  5302. Style Sheets, level 2 (CSS2)</emph>.  W3C Recommendation.  See <loc
  5303. href="http://www.w3.org/TR/1998/REC-CSS2-19980512"
  5304. >http://www.w3.org/TR/1998/REC-CSS2-19980512</loc></bibl>
  5305.  
  5306. <bibl id="DSSSL" key="DSSSL">International Organization
  5307. for Standardization, International Electrotechnical Commission.
  5308. <emph>ISO/IEC 10179:1996.  Document Style Semantics and Specification
  5309. Language (DSSSL)</emph>.  International Standard.</bibl>
  5310.  
  5311. <bibl id="HTML" key="HTML">World Wide Web Consortium. <emph>HTML 4.0
  5312. specification</emph>. W3C Recommendation. See <loc
  5313. href="http://www.w3.org/TR/REC-html40"
  5314. >http://www.w3.org/TR/REC-html40</loc></bibl>
  5315.  
  5316. <bibl id="IANA" key="IANA">Internet Assigned Numbers
  5317. Authority. <emph>Character Sets</emph>. See <loc
  5318. href="ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets"
  5319. >ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets</loc>.</bibl>
  5320.  
  5321. <bibl id="RFC2278" key="RFC2278">N. Freed, J. Postel.  <emph>IANA
  5322. Charset Registration Procedures</emph>.  IETF RFC 2278. See <loc
  5323. href="http://www.ietf.org/rfc/rfc2278.txt"
  5324. >http://www.ietf.org/rfc/rfc2278.txt</loc>.</bibl>
  5325.  
  5326. <bibl id="RFC2376" key="RFC2376">E. Whitehead, M. Murata.  <emph>XML
  5327. Media Types</emph>. IETF RFC 2376. See <loc
  5328. href="http://www.ietf.org/rfc/rfc2376.txt"
  5329. >http://www.ietf.org/rfc/rfc2376.txt</loc>.</bibl>
  5330.  
  5331. <bibl id="RFC2396" key="RFC2396">T. Berners-Lee, R. Fielding, and
  5332. L. Masinter.  <emph>Uniform Resource Identifiers (URI): Generic
  5333. Syntax</emph>. IETF RFC 2396. See <loc
  5334. href="http://www.ietf.org/rfc/rfc2396.txt">http://www.ietf.org/rfc/rfc2396.txt</loc>.</bibl>
  5335.  
  5336. <bibl id="UNICODE-TR10" key="UNICODE TR10">Unicode Consortium.
  5337. <emph>Unicode Technical Report #10. Unicode Collation
  5338. Algorithm</emph>.  Unicode Technical Report.  See <loc
  5339. href="http://www.unicode.org/unicode/reports/tr10/index.html"
  5340. >http://www.unicode.org/unicode/reports/tr10/index.html</loc>.</bibl>
  5341.  
  5342. <bibl id="XHTML" key="XHTML">World Wide Web Consortium. <emph>XHTML
  5343. 1.0: The Extensible HyperText Markup Language.</emph> W3C Proposed
  5344. Recommendation. See <loc href="http://www.w3.org/TR/xhtml1"
  5345. >http://www.w3.org/TR/xhtml1</loc></bibl>
  5346.  
  5347. <bibl id="XPTR" key="XPointer">World Wide Web
  5348. Consortium. <emph>XML Pointer Language (XPointer).</emph> W3C Working
  5349. Draft. See <loc href="http://www.w3.org/TR/xptr"
  5350. >http://www.w3.org/TR/xptr</loc></bibl>
  5351.  
  5352. <bibl id="XMLSTYLE" key="XML Stylesheet">World Wide Web
  5353. Consortium. <emph>Associating stylesheets with XML documents.</emph>
  5354. W3C Recommendation. See <loc
  5355. href="http://www.w3.org/TR/xml-stylesheet"
  5356. >http://www.w3.org/TR/xml-stylesheet</loc></bibl>
  5357.  
  5358. <bibl id="XSL" key="XSL">World Wide Web Consortium.  <emph>Extensible
  5359. Stylesheet Language (XSL).</emph>  W3C Working Draft.  See <loc
  5360. href="http://www.w3.org/TR/WD-xsl"
  5361.      >http://www.w3.org/TR/WD-xsl</loc></bibl>
  5362.  
  5363. </blist>
  5364.  
  5365. </div2>
  5366. </div1>
  5367.  
  5368. <div1 id="element-syntax-summary">
  5369. <head>Element Syntax Summary</head>
  5370.  
  5371. <e:element-syntax-summary/>
  5372.  
  5373. </div1>
  5374.  
  5375. <inform-div1 id="dtd">
  5376. <head>DTD Fragment for XSLT Stylesheets</head>
  5377.  
  5378. <note><p>This DTD Fragment is not normative because XML 1.0 DTDs do
  5379. not support XML Namespaces and thus cannot correctly describe the
  5380. allowed structure of an XSLT stylesheet.</p></note>
  5381.  
  5382. <p>The following entity can be used to construct a DTD for XSLT
  5383. stylesheets that create instances of a particular result DTD.  Before
  5384. referencing the entity, the stylesheet DTD must define a
  5385. <code>result-elements</code> parameter entity listing the allowed
  5386. result element types.  For example:</p>
  5387.  
  5388. <eg><![CDATA[<!ENTITY % result-elements "
  5389.   | fo:inline-sequence
  5390.   | fo:block
  5391. ">]]></eg>
  5392.  
  5393. <p>Such result elements should be declared to have
  5394. <code>xsl:use-attribute-sets</code> and
  5395. <code>xsl:extension-element-prefixes</code> attributes.  The following
  5396. entity declares the <code>result-element-atts</code> parameter for
  5397. this purpose. The content that XSLT allows for result elements is the
  5398. same as it allows for the XSLT elements that are declared in the
  5399. following entity with a content model of <code>%template;</code>.  The
  5400. DTD may use a more restrictive content model than
  5401. <code>%template;</code> to reflect the constraints of the result
  5402. DTD.</p>
  5403.  
  5404. <p>The DTD may define the <code>non-xsl-top-level</code> parameter
  5405. entity to allow additional top-level elements from namespaces other
  5406. than the XSLT namespace.</p>
  5407.  
  5408. <p>The use of the <code>xsl:</code> prefix in this DTD does not imply
  5409. that XSLT stylesheets are required to use this prefix.  Any of the
  5410. elements declared in this DTD may have attributes whose name starts
  5411. with <code>xmlns:</code> or is equal to <code>xmlns</code> in addition
  5412. to the attributes declared in this DTD.</p>
  5413.  
  5414. <eg><![CDATA[<!ENTITY % char-instructions "
  5415.   | xsl:apply-templates
  5416.   | xsl:call-template
  5417.   | xsl:apply-imports
  5418.   | xsl:for-each
  5419.   | xsl:value-of
  5420.   | xsl:copy-of
  5421.   | xsl:number
  5422.   | xsl:choose
  5423.   | xsl:if
  5424.   | xsl:text
  5425.   | xsl:copy
  5426.   | xsl:variable
  5427.   | xsl:message
  5428.   | xsl:fallback
  5429. ">
  5430.  
  5431. <!ENTITY % instructions "
  5432.   %char-instructions;
  5433.   | xsl:processing-instruction
  5434.   | xsl:comment
  5435.   | xsl:element
  5436.   | xsl:attribute
  5437. ">
  5438.  
  5439. <!ENTITY % char-template "
  5440.  (#PCDATA
  5441.   %char-instructions;)*
  5442. ">
  5443.  
  5444. <!ENTITY % template "
  5445.  (#PCDATA
  5446.   %instructions;
  5447.   %result-elements;)*
  5448. ">
  5449.  
  5450. <!-- Used for the type of an attribute value that is a URI reference.-->
  5451. <!ENTITY % URI "CDATA">
  5452.  
  5453. <!-- Used for the type of an attribute value that is a pattern.-->
  5454. <!ENTITY % pattern "CDATA">
  5455.  
  5456. <!-- Used for the type of an attribute value that is an
  5457.      attribute value template.-->
  5458. <!ENTITY % avt "CDATA">
  5459.  
  5460. <!-- Used for the type of an attribute value that is a QName; the prefix
  5461.      gets expanded by the XSLT processor. -->
  5462. <!ENTITY % qname "NMTOKEN">
  5463.  
  5464. <!-- Like qname but a whitespace-separated list of QNames. -->
  5465. <!ENTITY % qnames "NMTOKENS">
  5466.  
  5467. <!-- Used for the type of an attribute value that is an expression.-->
  5468. <!ENTITY % expr "CDATA">
  5469.  
  5470. <!-- Used for the type of an attribute value that consists
  5471.      of a single character.-->
  5472. <!ENTITY % char "CDATA">
  5473.  
  5474. <!-- Used for the type of an attribute value that is a priority. -->
  5475. <!ENTITY % priority "NMTOKEN">
  5476.  
  5477. <!ENTITY % space-att "xml:space (default|preserve) #IMPLIED">
  5478.  
  5479. <!-- This may be overridden to customize the set of elements allowed
  5480. at the top-level. -->
  5481.  
  5482. <!ENTITY % non-xsl-top-level "">
  5483.  
  5484. <!ENTITY % top-level "
  5485.  (xsl:import*,
  5486.   (xsl:include
  5487.   | xsl:strip-space
  5488.   | xsl:preserve-space
  5489.   | xsl:output
  5490.   | xsl:key
  5491.   | xsl:decimal-format
  5492.   | xsl:attribute-set
  5493.   | xsl:variable
  5494.   | xsl:param
  5495.   | xsl:template
  5496.   | xsl:namespace-alias
  5497.   %non-xsl-top-level;)*)
  5498. ">
  5499.  
  5500. <!ENTITY % top-level-atts '
  5501.   extension-element-prefixes CDATA #IMPLIED
  5502.   exclude-result-prefixes CDATA #IMPLIED
  5503.   id ID #IMPLIED
  5504.   version NMTOKEN #REQUIRED
  5505.   xmlns:xsl CDATA #FIXED "]]>&XSLT.ns;<![CDATA["
  5506.   %space-att;
  5507. '>
  5508.  
  5509. <!-- This entity is defined for use in the ATTLIST declaration
  5510. for result elements. -->
  5511.  
  5512. <!ENTITY % result-element-atts '
  5513.   xsl:extension-element-prefixes CDATA #IMPLIED
  5514.   xsl:exclude-result-prefixes CDATA #IMPLIED
  5515.   xsl:use-attribute-sets %qnames; #IMPLIED
  5516.   xsl:version NMTOKEN #IMPLIED
  5517. '>
  5518.  
  5519. <!ELEMENT xsl:stylesheet %top-level;>
  5520. <!ATTLIST xsl:stylesheet %top-level-atts;>
  5521.  
  5522. <!ELEMENT xsl:transform %top-level;>
  5523. <!ATTLIST xsl:transform %top-level-atts;>
  5524.  
  5525. <!ELEMENT xsl:import EMPTY>
  5526. <!ATTLIST xsl:import href %URI; #REQUIRED>
  5527.  
  5528. <!ELEMENT xsl:include EMPTY>
  5529. <!ATTLIST xsl:include href %URI; #REQUIRED>
  5530.  
  5531. <!ELEMENT xsl:strip-space EMPTY>
  5532. <!ATTLIST xsl:strip-space elements CDATA #REQUIRED>
  5533.  
  5534. <!ELEMENT xsl:preserve-space EMPTY>
  5535. <!ATTLIST xsl:preserve-space elements CDATA #REQUIRED>
  5536.  
  5537. <!ELEMENT xsl:output EMPTY>
  5538. <!ATTLIST xsl:output
  5539.   method %qname; #IMPLIED
  5540.   version NMTOKEN #IMPLIED
  5541.   encoding CDATA #IMPLIED
  5542.   omit-xml-declaration (yes|no) #IMPLIED
  5543.   standalone (yes|no) #IMPLIED
  5544.   doctype-public CDATA #IMPLIED
  5545.   doctype-system CDATA #IMPLIED
  5546.   cdata-section-elements %qnames; #IMPLIED
  5547.   indent (yes|no) #IMPLIED
  5548.   media-type CDATA #IMPLIED
  5549. >
  5550.  
  5551. <!ELEMENT xsl:key EMPTY>
  5552. <!ATTLIST xsl:key
  5553.   name %qname; #REQUIRED
  5554.   match %pattern; #REQUIRED
  5555.   use %expr; #REQUIRED
  5556. >
  5557.  
  5558. <!ELEMENT xsl:decimal-format EMPTY>
  5559. <!ATTLIST xsl:decimal-format
  5560.   name %qname; #IMPLIED
  5561.   decimal-separator %char; "."
  5562.   grouping-separator %char; ","
  5563.   infinity CDATA "Infinity"
  5564.   minus-sign %char; "-"
  5565.   NaN CDATA "NaN"
  5566.   percent %char; "%"
  5567.   per-mille %char; "‰"
  5568.   zero-digit %char; "0"
  5569.   digit %char; "#"
  5570.   pattern-separator %char; ";"
  5571. >
  5572.  
  5573. <!ELEMENT xsl:namespace-alias EMPTY>
  5574. <!ATTLIST xsl:namespace-alias
  5575.   stylesheet-prefix CDATA #REQUIRED
  5576.   result-prefix CDATA #REQUIRED
  5577. >
  5578.  
  5579. <!ELEMENT xsl:template
  5580.  (#PCDATA
  5581.   %instructions;
  5582.   %result-elements;
  5583.   | xsl:param)*
  5584. >
  5585.  
  5586. <!ATTLIST xsl:template
  5587.   match %pattern; #IMPLIED
  5588.   name %qname; #IMPLIED
  5589.   priority %priority; #IMPLIED
  5590.   mode %qname; #IMPLIED
  5591.   %space-att;
  5592. >
  5593.  
  5594. <!ELEMENT xsl:value-of EMPTY>
  5595. <!ATTLIST xsl:value-of
  5596.   select %expr; #REQUIRED
  5597.   disable-output-escaping (yes|no) "no"
  5598. >
  5599.  
  5600. <!ELEMENT xsl:copy-of EMPTY>
  5601. <!ATTLIST xsl:copy-of select %expr; #REQUIRED>
  5602.  
  5603. <!ELEMENT xsl:number EMPTY>
  5604. <!ATTLIST xsl:number
  5605.    level (single|multiple|any) "single"
  5606.    count %pattern; #IMPLIED
  5607.    from %pattern; #IMPLIED
  5608.    value %expr; #IMPLIED
  5609.    format %avt; '1'
  5610.    lang %avt; #IMPLIED
  5611.    letter-value %avt; #IMPLIED
  5612.    grouping-separator %avt; #IMPLIED
  5613.    grouping-size %avt; #IMPLIED
  5614. >
  5615.  
  5616. <!ELEMENT xsl:apply-templates (xsl:sort|xsl:with-param)*>
  5617. <!ATTLIST xsl:apply-templates
  5618.   select %expr; "node()"
  5619.   mode %qname; #IMPLIED
  5620. >
  5621.  
  5622. <!ELEMENT xsl:apply-imports EMPTY>
  5623.  
  5624. <!-- xsl:sort cannot occur after any other elements or
  5625. any non-whitespace character -->
  5626.  
  5627. <!ELEMENT xsl:for-each
  5628.  (#PCDATA
  5629.   %instructions;
  5630.   %result-elements;
  5631.   | xsl:sort)*
  5632. >
  5633.  
  5634. <!ATTLIST xsl:for-each
  5635.   select %expr; #REQUIRED
  5636.   %space-att;
  5637. >
  5638.  
  5639. <!ELEMENT xsl:sort EMPTY>
  5640. <!ATTLIST xsl:sort
  5641.   select %expr; "."
  5642.   lang %avt; #IMPLIED
  5643.   data-type %avt; "text"
  5644.   order %avt; "ascending"
  5645.   case-order %avt; #IMPLIED
  5646. >
  5647.  
  5648. <!ELEMENT xsl:if %template;>
  5649. <!ATTLIST xsl:if
  5650.   test %expr; #REQUIRED
  5651.   %space-att;
  5652. >
  5653.  
  5654. <!ELEMENT xsl:choose (xsl:when+, xsl:otherwise?)>
  5655. <!ATTLIST xsl:choose %space-att;>
  5656.  
  5657. <!ELEMENT xsl:when %template;>
  5658. <!ATTLIST xsl:when
  5659.   test %expr; #REQUIRED
  5660.   %space-att;
  5661. >
  5662.  
  5663. <!ELEMENT xsl:otherwise %template;>
  5664. <!ATTLIST xsl:otherwise %space-att;>
  5665.  
  5666. <!ELEMENT xsl:attribute-set (xsl:attribute)*>
  5667. <!ATTLIST xsl:attribute-set
  5668.   name %qname; #REQUIRED
  5669.   use-attribute-sets %qnames; #IMPLIED
  5670. >
  5671.  
  5672. <!ELEMENT xsl:call-template (xsl:with-param)*>
  5673. <!ATTLIST xsl:call-template
  5674.   name %qname; #REQUIRED
  5675. >
  5676.  
  5677. <!ELEMENT xsl:with-param %template;>
  5678. <!ATTLIST xsl:with-param
  5679.   name %qname; #REQUIRED
  5680.   select %expr; #IMPLIED
  5681. >
  5682.  
  5683. <!ELEMENT xsl:variable %template;>
  5684. <!ATTLIST xsl:variable 
  5685.   name %qname; #REQUIRED
  5686.   select %expr; #IMPLIED
  5687. >
  5688.  
  5689. <!ELEMENT xsl:param %template;>
  5690. <!ATTLIST xsl:param 
  5691.   name %qname; #REQUIRED
  5692.   select %expr; #IMPLIED
  5693. >
  5694.  
  5695. <!ELEMENT xsl:text (#PCDATA)>
  5696. <!ATTLIST xsl:text
  5697.   disable-output-escaping (yes|no) "no"
  5698. >
  5699.  
  5700. <!ELEMENT xsl:processing-instruction %char-template;>
  5701. <!ATTLIST xsl:processing-instruction 
  5702.   name %avt; #REQUIRED
  5703.   %space-att;
  5704. >
  5705.  
  5706. <!ELEMENT xsl:element %template;>
  5707. <!ATTLIST xsl:element 
  5708.   name %avt; #REQUIRED
  5709.   namespace %avt; #IMPLIED
  5710.   use-attribute-sets %qnames; #IMPLIED
  5711.   %space-att;
  5712. >
  5713.  
  5714. <!ELEMENT xsl:attribute %char-template;>
  5715. <!ATTLIST xsl:attribute 
  5716.   name %avt; #REQUIRED
  5717.   namespace %avt; #IMPLIED
  5718.   %space-att;
  5719. >
  5720.  
  5721. <!ELEMENT xsl:comment %char-template;>
  5722. <!ATTLIST xsl:comment %space-att;>
  5723.  
  5724. <!ELEMENT xsl:copy %template;>
  5725. <!ATTLIST xsl:copy
  5726.   %space-att;
  5727.   use-attribute-sets %qnames; #IMPLIED
  5728. >
  5729.  
  5730. <!ELEMENT xsl:message %template;>
  5731. <!ATTLIST xsl:message
  5732.   %space-att;
  5733.   terminate (yes|no) "no"
  5734. >
  5735.  
  5736. <!ELEMENT xsl:fallback %template;>
  5737. <!ATTLIST xsl:fallback %space-att;>]]></eg>
  5738.  
  5739. </inform-div1>
  5740.  
  5741. <inform-div1>
  5742. <head>Examples</head>
  5743.  
  5744. <div2>
  5745. <head>Document Example</head>
  5746.  
  5747. <p>This example is a stylesheet for transforming documents that
  5748. conform to a simple DTD into XHTML <bibref ref="XHTML"/>.  The DTD
  5749. is:</p>
  5750.  
  5751. <eg><![CDATA[<!ELEMENT doc (title, chapter*)>
  5752. <!ELEMENT chapter (title, (para|note)*, section*)>
  5753. <!ELEMENT section (title, (para|note)*)>
  5754. <!ELEMENT title (#PCDATA|emph)*>
  5755. <!ELEMENT para (#PCDATA|emph)*>
  5756. <!ELEMENT note (#PCDATA|emph)*>
  5757. <!ELEMENT emph (#PCDATA|emph)*>]]></eg>
  5758.  
  5759. <p>The stylesheet is:</p>
  5760.  
  5761. <eg><xsl:stylesheet version="1.0"
  5762.                 xmlns:xsl="&XSLT.ns;"
  5763.                 xmlns="&XHTML.ns;"><![CDATA[
  5764.  
  5765. <xsl:strip-space elements="doc chapter section"/>
  5766. <xsl:output
  5767.    method="xml"
  5768.    indent="yes"
  5769.    encoding="iso-8859-1"
  5770. />
  5771.  
  5772. <xsl:template match="doc">
  5773.  <html>
  5774.    <head>
  5775.      <title>
  5776.        <xsl:value-of select="title"/>
  5777.      </title>
  5778.    </head>
  5779.    <body>
  5780.      <xsl:apply-templates/>
  5781.    </body>
  5782.  </html>
  5783. </xsl:template>
  5784.  
  5785. <xsl:template match="doc/title">
  5786.   <h1>
  5787.     <xsl:apply-templates/>
  5788.   </h1>
  5789. </xsl:template>
  5790.  
  5791. <xsl:template match="chapter/title">
  5792.   <h2>
  5793.     <xsl:apply-templates/>
  5794.   </h2>
  5795. </xsl:template>
  5796.  
  5797. <xsl:template match="section/title">
  5798.   <h3>
  5799.     <xsl:apply-templates/>
  5800.   </h3>
  5801. </xsl:template>
  5802.  
  5803. <xsl:template match="para">
  5804.   <p>
  5805.     <xsl:apply-templates/>
  5806.   </p>
  5807. </xsl:template>
  5808.  
  5809. <xsl:template match="note">
  5810.   <p class="note">
  5811.     <b>NOTE: </b>
  5812.     <xsl:apply-templates/>
  5813.   </p>
  5814. </xsl:template>
  5815.  
  5816. <xsl:template match="emph">
  5817.   <em>
  5818.     <xsl:apply-templates/>
  5819.   </em>
  5820. </xsl:template>
  5821.  
  5822. </xsl:stylesheet>]]></eg>
  5823.  
  5824. <p>With the following input document</p>
  5825.  
  5826. <eg><![CDATA[<!DOCTYPE doc SYSTEM "doc.dtd">
  5827. <doc>
  5828. <title>Document Title</title>
  5829. <chapter>
  5830. <title>Chapter Title</title>
  5831. <section>
  5832. <title>Section Title</title>
  5833. <para>This is a test.</para>
  5834. <note>This is a note.</note>
  5835. </section>
  5836. <section>
  5837. <title>Another Section Title</title>
  5838. <para>This is <emph>another</emph> test.</para>
  5839. <note>This is another note.</note>
  5840. </section>
  5841. </chapter>
  5842. </doc>]]></eg>
  5843.  
  5844. <p>it would produce the following result</p>
  5845.  
  5846. <eg><?xml version="1.0" encoding="iso-8859-1"?>
  5847. <html xmlns="&XHTML.ns;"><![CDATA[
  5848. <head>
  5849. <title>Document Title</title>
  5850. </head>
  5851. <body>
  5852. <h1>Document Title</h1>
  5853. <h2>Chapter Title</h2>
  5854. <h3>Section Title</h3>
  5855. <p>This is a test.</p>
  5856. <p class="note">
  5857. <b>NOTE: </b>This is a note.</p>
  5858. <h3>Another Section Title</h3>
  5859. <p>This is <em>another</em> test.</p>
  5860. <p class="note">
  5861. <b>NOTE: </b>This is another note.</p>
  5862. </body>
  5863. </html>]]></eg>
  5864.  
  5865. </div2>
  5866.  
  5867. <div2 id="data-example">
  5868. <head>Data Example</head>
  5869.  
  5870. <p>This is an example of transforming some data represented in XML
  5871. using three different XSLT stylesheets to produce three different
  5872. representations of the data, HTML, SVG and VRML.</p>
  5873.  
  5874. <p>The input data is:</p>
  5875.  
  5876. <eg><![CDATA[<sales>
  5877.  
  5878.         <division id="North">
  5879.                 <revenue>10</revenue>
  5880.                 <growth>9</growth>
  5881.                 <bonus>7</bonus>
  5882.         </division>
  5883.  
  5884.         <division id="South">
  5885.                 <revenue>4</revenue>
  5886.                 <growth>3</growth>
  5887.                 <bonus>4</bonus>
  5888.         </division>
  5889.  
  5890.         <division id="West">
  5891.                 <revenue>6</revenue>
  5892.                 <growth>-1.5</growth>
  5893.                 <bonus>2</bonus>
  5894.         </division>
  5895.  
  5896. </sales>]]></eg>
  5897.  
  5898. <p>The following stylesheet, which uses the simplified syntax
  5899. described in <specref ref="result-element-stylesheet"/>, transforms
  5900. the data into HTML:</p>
  5901.  
  5902. <eg><html xsl:version="1.0"
  5903.       xmlns:xsl="&XSLT.ns;"<![CDATA[
  5904.       lang="en">
  5905.     <head>
  5906.     <title>Sales Results By Division</title>
  5907.     </head>
  5908.     <body>
  5909.     <table border="1">
  5910.         <tr>
  5911.         <th>Division</th>
  5912.         <th>Revenue</th>
  5913.         <th>Growth</th>
  5914.         <th>Bonus</th>
  5915.         </tr>
  5916.         <xsl:for-each select="sales/division">
  5917.         <!-- order the result by revenue -->
  5918.         <xsl:sort select="revenue"
  5919.               data-type="number"
  5920.               order="descending"/>
  5921.         <tr>
  5922.             <td>
  5923.             <em><xsl:value-of select="@id"/></em>
  5924.             </td>
  5925.             <td>
  5926.             <xsl:value-of select="revenue"/>
  5927.             </td>
  5928.             <td>
  5929.             <!-- highlight negative growth in red -->
  5930.             <xsl:if test="growth < 0">
  5931.                  <xsl:attribute name="style">
  5932.                  <xsl:text>color:red</xsl:text>
  5933.                  </xsl:attribute>
  5934.             </xsl:if>
  5935.             <xsl:value-of select="growth"/>
  5936.             </td>
  5937.             <td>
  5938.             <xsl:value-of select="bonus"/>
  5939.             </td>
  5940.         </tr>
  5941.         </xsl:for-each>
  5942.     </table>
  5943.     </body>
  5944. </html>]]></eg>
  5945.  
  5946. <p>The HTML output is:</p>
  5947.  
  5948. <eg><![CDATA[<html lang="en">
  5949. <head>
  5950. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5951. <title>Sales Results By Division</title>
  5952. </head>
  5953. <body>
  5954. <table border="1">
  5955. <tr>
  5956. <th>Division</th><th>Revenue</th><th>Growth</th><th>Bonus</th>
  5957. </tr>
  5958. <tr>
  5959. <td><em>North</em></td><td>10</td><td>9</td><td>7</td>
  5960. </tr>
  5961. <tr>
  5962. <td><em>West</em></td><td>6</td><td style="color:red">-1.5</td><td>2</td>
  5963. </tr>
  5964. <tr>
  5965. <td><em>South</em></td><td>4</td><td>3</td><td>4</td>
  5966. </tr>
  5967. </table>
  5968. </body>
  5969. </html>]]></eg>
  5970.  
  5971. <p>The following stylesheet transforms the data into SVG:</p>
  5972.  
  5973. <eg><xsl:stylesheet version="1.0"
  5974.                 xmlns:xsl="&XSLT.ns;"<![CDATA[
  5975.                 xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">
  5976.  
  5977. <xsl:output method="xml" indent="yes" media-type="image/svg"/>
  5978.  
  5979. <xsl:template match="/">
  5980.  
  5981. <svg width = "3in" height="3in">
  5982.     <g style = "stroke: #000000"> 
  5983.         <!-- draw the axes -->
  5984.         <line x1="0" x2="150" y1="150" y2="150"/>
  5985.         <line x1="0" x2="0" y1="0" y2="150"/>
  5986.         <text x="0" y="10">Revenue</text>
  5987.         <text x="150" y="165">Division</text>
  5988.         <xsl:for-each select="sales/division">
  5989.         <!-- define some useful variables -->
  5990.  
  5991.         <!-- the bar's x position -->
  5992.         <xsl:variable name="pos"
  5993.                       select="(position()*40)-30"/>
  5994.  
  5995.         <!-- the bar's height -->
  5996.         <xsl:variable name="height"
  5997.                       select="revenue*10"/>
  5998.  
  5999.         <!-- the rectangle -->
  6000.         <rect x="{$pos}" y="{150-$height}"
  6001.                   width="20" height="{$height}"/>
  6002.  
  6003.         <!-- the text label -->
  6004.         <text x="{$pos}" y="165">
  6005.             <xsl:value-of select="@id"/>
  6006.         </text> 
  6007.  
  6008.         <!-- the bar value -->
  6009.         <text x="{$pos}" y="{145-$height}">
  6010.             <xsl:value-of select="revenue"/>
  6011.         </text>
  6012.         </xsl:for-each>
  6013.     </g>
  6014. </svg>
  6015.  
  6016. </xsl:template>
  6017. </xsl:stylesheet>]]></eg>
  6018.  
  6019. <p>The SVG output is:</p>
  6020.  
  6021. <eg><![CDATA[<svg width="3in" height="3in"
  6022.      xmlns="http://www.w3.org/Graphics/SVG/svg-19990412.dtd">
  6023.     <g style="stroke: #000000">
  6024.     <line x1="0" x2="150" y1="150" y2="150"/>
  6025.     <line x1="0" x2="0" y1="0" y2="150"/>
  6026.     <text x="0" y="10">Revenue</text>
  6027.     <text x="150" y="165">Division</text>
  6028.     <rect x="10" y="50" width="20" height="100"/>
  6029.     <text x="10" y="165">North</text>
  6030.     <text x="10" y="45">10</text>
  6031.     <rect x="50" y="110" width="20" height="40"/>
  6032.     <text x="50" y="165">South</text>
  6033.     <text x="50" y="105">4</text>
  6034.     <rect x="90" y="90" width="20" height="60"/>
  6035.     <text x="90" y="165">West</text>
  6036.     <text x="90" y="85">6</text>
  6037.     </g>
  6038. </svg>]]></eg>
  6039.  
  6040. <p>The following stylesheet transforms the data into VRML:</p>
  6041.  
  6042. <eg><xsl:stylesheet version="1.0"
  6043.                 xmlns:xsl="&XSLT.ns;"><![CDATA[
  6044.  
  6045. <!-- generate text output as mime type model/vrml, using default charset -->
  6046. <xsl:output method="text" encoding="UTF-8" media-type="model/vrml"/>  
  6047.  
  6048.         <xsl:template match="/">#VRML V2.0 utf8 
  6049.  
  6050. # externproto definition of a single bar element 
  6051. EXTERNPROTO bar [ 
  6052.   field SFInt32 x  
  6053.   field SFInt32 y  
  6054.   field SFInt32 z  
  6055.   field SFString name  
  6056.   ] 
  6057.   "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl" 
  6058.  
  6059. # inline containing the graph axes 
  6060. Inline {  
  6061.         url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wrl" 
  6062.         } 
  6063.         
  6064.                 <xsl:for-each select="sales/division">
  6065. bar {
  6066.         x <xsl:value-of select="revenue"/>
  6067.         y <xsl:value-of select="growth"/>
  6068.         z <xsl:value-of select="bonus"/>
  6069.         name "<xsl:value-of select="@id"/>" 
  6070.         }
  6071.                 </xsl:for-each>
  6072.         
  6073.         </xsl:template> 
  6074.  
  6075. </xsl:stylesheet>]]></eg>
  6076.  
  6077. <p>The VRML output is:</p>
  6078.  
  6079. <eg><![CDATA[#VRML V2.0 utf8 
  6080.  
  6081. # externproto definition of a single bar element 
  6082. EXTERNPROTO bar [ 
  6083.   field SFInt32 x  
  6084.   field SFInt32 y  
  6085.   field SFInt32 z  
  6086.   field SFString name  
  6087.   ] 
  6088.   "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl" 
  6089.  
  6090. # inline containing the graph axes 
  6091. Inline {  
  6092.         url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wrl" 
  6093.         } 
  6094.         
  6095.                 
  6096. bar {
  6097.         x 10
  6098.         y 9
  6099.         z 7
  6100.         name "North" 
  6101.         }
  6102.                 
  6103. bar {
  6104.         x 4
  6105.         y 3
  6106.         z 4
  6107.         name "South" 
  6108.         }
  6109.                 
  6110. bar {
  6111.         x 6
  6112.         y -1.5
  6113.         z 2
  6114.         name "West" 
  6115.         }]]></eg>
  6116.  
  6117. </div2>
  6118.  
  6119. </inform-div1>
  6120.  
  6121. <inform-div1>
  6122. <head>Acknowledgements</head>
  6123. <p>The following have contributed to authoring this draft:</p>
  6124. <slist>
  6125. <sitem>Daniel Lipkin, Saba</sitem>
  6126. <sitem>Jonathan Marsh, Microsoft</sitem>
  6127. <sitem>Henry Thompson, University of Edinburgh</sitem>
  6128. <sitem>Norman Walsh, Arbortext</sitem>
  6129. <sitem>Steve Zilles, Adobe</sitem>
  6130. </slist>
  6131.  
  6132. <p>This specification was developed and approved for publication by the
  6133. W3C XSL Working Group (WG). WG approval of this specification does not
  6134. necessarily imply that all WG members voted for its approval. The
  6135. current members of the XSL WG are:</p>
  6136.  
  6137. <orglist>
  6138. <member>
  6139. <name>Sharon Adler</name>
  6140. <affiliation>IBM</affiliation>
  6141. <role>Co-Chair</role>
  6142. </member>
  6143. <member>
  6144. <name>Anders Berglund</name>
  6145. <affiliation>IBM</affiliation>
  6146. </member>
  6147. <member>
  6148. <name>Perin Blanchard</name>
  6149. <affiliation>Novell</affiliation>
  6150. </member>
  6151. <member>
  6152. <name>Scott Boag</name>
  6153. <affiliation>Lotus</affiliation> 
  6154. </member>
  6155. <member>
  6156. <name>Larry Cable</name>
  6157. <affiliation>Sun</affiliation>
  6158. </member>
  6159. <member>
  6160. <name>Jeff Caruso</name>
  6161. <affiliation>Bitstream</affiliation>
  6162. </member>
  6163. <member>
  6164. <name>James Clark</name>
  6165. </member>
  6166. <member>
  6167. <name>Peter Danielsen</name>
  6168. <affiliation>Bell Labs</affiliation>
  6169. </member>
  6170. <member>
  6171. <name>Don Day</name>
  6172. <affiliation>IBM</affiliation>
  6173. </member>
  6174. <member>
  6175. <name>Stephen Deach</name>
  6176. <affiliation>Adobe</affiliation>
  6177. </member>
  6178. <member>
  6179. <name>Dwayne Dicks</name>
  6180. <affiliation>SoftQuad</affiliation>
  6181. </member>
  6182. <member>
  6183. <name>Andrew Greene</name>
  6184. <affiliation>Bitstream</affiliation>
  6185. </member>
  6186. <member>
  6187. <name>Paul Grosso</name>
  6188. <affiliation>Arbortext</affiliation>
  6189. </member>
  6190. <member>
  6191. <name>Eduardo Gutentag</name>
  6192. <affiliation>Sun</affiliation>
  6193. </member>
  6194. <member>
  6195. <name>Juliane Harbarth</name>
  6196. <affiliation>Software AG</affiliation>
  6197. </member>
  6198. <member>
  6199. <name>Mickey Kimchi</name>
  6200. <affiliation>Enigma</affiliation>
  6201. </member>
  6202. <member>
  6203. <name>Chris Lilley</name>
  6204. <affiliation>W3C</affiliation>
  6205. </member>
  6206. <member>
  6207. <name>Chris Maden</name>
  6208. <affiliation>Exemplary Technologies</affiliation>
  6209. </member>
  6210. <member>
  6211. <name>Jonathan Marsh</name>
  6212. <affiliation>Microsoft</affiliation>
  6213. </member>
  6214. <member>
  6215. <name>Alex Milowski</name> 
  6216. <affiliation>Lexica</affiliation>
  6217. </member>
  6218. <member>
  6219. <name>Steve Muench</name>
  6220. <affiliation>Oracle</affiliation>
  6221. </member>
  6222. <member>
  6223. <name>Scott Parnell</name>
  6224. <affiliation>Xerox</affiliation>
  6225. </member>
  6226. <member>
  6227. <name>Vincent Quint</name>
  6228. <affiliation>W3C</affiliation>
  6229. </member>
  6230. <member>
  6231. <name>Dan Rapp</name>
  6232. <affiliation>Novell</affiliation>
  6233. </member>
  6234. <member>
  6235. <name>Gregg Reynolds</name>
  6236. <affiliation>Datalogics</affiliation>
  6237. </member>
  6238. <member>
  6239. <name>Jonathan Robie</name>
  6240. <affiliation>Software AG</affiliation>
  6241. </member>
  6242. <member>
  6243. <name>Mark Scardina</name>
  6244. <affiliation>Oracle</affiliation>
  6245. </member>
  6246. <member>
  6247. <name>Henry Thompson</name>
  6248. <affiliation>University of Edinburgh</affiliation>
  6249. </member>
  6250. <member>
  6251. <name>Philip Wadler</name>
  6252. <affiliation>Bell Labs</affiliation>
  6253. </member>
  6254. <member>
  6255. <name>Norman Walsh</name>
  6256. <affiliation>Arbortext</affiliation>
  6257. </member>
  6258. <member>
  6259. <name>Sanjiva Weerawarana</name>
  6260. <affiliation>IBM</affiliation>
  6261. </member>
  6262. <member>
  6263. <name>Steve Zilles</name>
  6264. <affiliation>Adobe</affiliation>
  6265. <role>Co-Chair</role>
  6266. </member>
  6267. </orglist>
  6268.  
  6269. </inform-div1>
  6270.  
  6271. <inform-div1>
  6272. <head>Changes from Proposed Recommendation</head>
  6273.  
  6274. <p>The following are the changes since the Proposed Recommendation:</p>
  6275.  
  6276. <ulist>
  6277.  
  6278. <item><p>The <code>xsl:version</code> attribute is required on a
  6279. literal result element used as a stylesheet (see <specref
  6280. ref="result-element-stylesheet"/>).</p></item>
  6281.  
  6282. <item><p>The <code>data-type</code> attribute on <code>xsl:sort</code>
  6283. can use a prefixed name to specify a data-type not defined by
  6284. XSLT (see <specref ref="sorting"/>).</p></item>
  6285.  
  6286. </ulist>
  6287.  
  6288. </inform-div1>
  6289.  
  6290. <inform-div1>
  6291. <head>Features under Consideration for Future Versions of XSLT</head>
  6292.  
  6293. <p>The following features are under consideration for versions of XSLT
  6294. after XSLT 1.0:</p>
  6295.  
  6296. <ulist>
  6297.  
  6298. <item><p>a conditional expression;</p></item>
  6299.  
  6300. <item><p>support for XML Schema datatypes and archetypes;</p></item>
  6301.  
  6302. <item><p>support for something like style rules in the original XSL
  6303. submission;</p></item>
  6304.  
  6305. <item><p>an attribute to control the default namespace for names
  6306. occurring in XSLT attributes;</p></item>
  6307.  
  6308. <item><p>support for entity references;</p></item>
  6309.  
  6310. <item><p>support for DTDs in the data model;</p></item>
  6311.  
  6312. <item><p>support for notations in the data model;</p></item>
  6313.  
  6314. <item><p>a way to get back from an element to the elements that
  6315. reference it (e.g. by IDREF attributes);</p></item>
  6316.  
  6317. <item><p>an easier way to get an ID or key in another document;</p></item>
  6318.  
  6319. <item><p>support for regular expressions for matching against any or
  6320. all of text nodes, attribute values, attribute names, element type
  6321. names;</p></item>
  6322.  
  6323. <item><p>case-insensitive comparisons;</p></item>
  6324.  
  6325. <item><p>normalization of strings before comparison, for example for
  6326. compatibility characters;</p></item>
  6327.  
  6328. <item><p>a function <code>string resolve(node-set)</code> function
  6329. that treats the value of the argument as a relative URI and turns it
  6330. into an absolute URI using the base URI of the node;</p></item>
  6331.  
  6332. <item><p>multiple result documents;</p></item>
  6333.  
  6334. <item><p>defaulting the <code>select</code> attribute on
  6335. <code>xsl:value-of</code> to the current node;</p></item>
  6336.  
  6337. <item><p>an attribute on <code>xsl:attribute</code> to control how the
  6338. attribute value is normalized;</p></item>
  6339.  
  6340. <item><p>additional attributes on <code>xsl:sort</code> to provide
  6341. further control over sorting, such as relative order of
  6342. scripts;</p></item>
  6343.  
  6344. <item><p>a way to put the text of a resource identified by a URI into
  6345. the result tree;</p></item>
  6346.  
  6347. <item><p>allow unions in steps (e.g. <code>foo/(bar|baz)</code>);</p></item>
  6348.  
  6349. <item><p>allow for result tree fragments all operations that are
  6350. allowed for node-sets;</p></item>
  6351.  
  6352. <item><p>a way to group together consecutive nodes having duplicate
  6353. subelements or attributes;</p></item>
  6354.  
  6355. <item><p>features to make handling of the HTML <code>style</code>
  6356. attribute more convenient.</p></item>
  6357.  
  6358. </ulist>
  6359.  
  6360. </inform-div1>
  6361.  
  6362. </back>
  6363. </spec>
  6364.