xref: /aosp_15_r20/external/apache-xml/test/tests/contrib/xsltc/mk/mk055.xml (revision 1212f9a0ffdc28482b8821715d2222bf16dc14e2)
1<?xml version="1.0" encoding="iso-8859-1"?>
2<!-- $Id$ -->
3<!DOCTYPE spec SYSTEM "spec.dtd" [
4<!ENTITY XML "http://www.w3.org/TR/REC-xml">
5<!ENTITY XMLNames "http://www.w3.org/TR/REC-xml-names">
6<!ENTITY year "1999">
7<!ENTITY month "November">
8<!ENTITY MM "11">
9<!ENTITY day "16">
10<!ENTITY DD "16">
11<!ENTITY YYYYMMDD "&year;&MM;&DD;">
12<!ENTITY LEV "REC">
13<!-- DTD customizations -->
14<!ELEMENT proto (arg*)>
15<!ATTLIST proto
16  name NMTOKEN #REQUIRED
17  return-type (number|string|boolean|node-set|object) #REQUIRED
18>
19<!ELEMENT arg EMPTY>
20<!ATTLIST arg
21  type (number|string|boolean|node-set|object) #REQUIRED
22  occur (opt|rep) #IMPLIED
23>
24<!ELEMENT function (#PCDATA)>
25<!ENTITY % local.illus.class "|proto">
26<!ENTITY % local.tech.class "|function">
27]>
28<spec>
29<header>
30<title>XML Path Language (XPath)</title>
31<version>Version 1.0</version>
32<w3c-designation>&LEV;-xpath-&YYYYMMDD;</w3c-designation>
33<w3c-doctype>W3C Recommendation</w3c-doctype>
34<pubdate><day>&day;</day><month>&month;</month><year>&year;</year></pubdate>
35<publoc>
36<loc href="http://www.w3.org/TR/&year;/&LEV;-xpath-&YYYYMMDD;"
37          >http://www.w3.org/TR/&year;/&LEV;-xpath-&YYYYMMDD;</loc>
38<loc role="available-format"
39href="http://www.w3.org/TR/&year;/&LEV;-xpath-&YYYYMMDD;.xml">XML</loc>
40<loc role="available-format"
41href="http://www.w3.org/TR/&year;/&LEV;-xpath-&YYYYMMDD;.html">HTML</loc>
42<!--
43<loc href="http://www.w3.org/TR/&year;/&LEV;-xpath-&YYYYMMDD;.pdf"
44          >http://www.w3.org/TR/&year;/&LEV;-xpath-&YYYYMMDD;.pdf</loc>
45-->
46</publoc>
47<latestloc>
48<loc href="http://www.w3.org/TR/xpath"
49          >http://www.w3.org/TR/xpath</loc>
50</latestloc>
51<prevlocs>
52<loc href="http://www.w3.org/TR/1999/PR-xpath-19991008"
53          >http://www.w3.org/TR/1999/PR-xpath-19991008</loc>
54<loc href="http://www.w3.org/1999/08/WD-xpath-19990813"
55          >http://www.w3.org/1999/08/WD-xpath-19990813</loc>
56<loc href="http://www.w3.org/1999/07/WD-xpath-19990709"
57          >http://www.w3.org/1999/07/WD-xpath-19990709</loc>
58<loc href="http://www.w3.org/TR/1999/WD-xslt-19990421"
59          >http://www.w3.org/TR/1999/WD-xslt-19990421</loc>
60</prevlocs>
61<authlist>
62<author>
63<name>James Clark</name>
64<email href="mailto:[email protected]">[email protected]</email>
65</author>
66<author>
67<name>Steve DeRose</name>
68<affiliation>Inso Corp. and Brown University</affiliation>
69<email href="mailto:[email protected]">[email protected]</email>
70</author>
71</authlist>
72
73<status>
74
75<p>This document has been reviewed by W3C Members and other interested
76parties and has been endorsed by the Director as a W3C <loc
77href="http://www.w3.org/Consortium/Process/#RecsW3C">Recommendation</loc>. It
78is a stable document and may be used as reference material or cited as
79a normative reference from other documents. W3C's role in making the
80Recommendation is to draw attention to the specification and to
81promote its widespread deployment. This enhances the functionality and
82interoperability of the Web.</p>
83
84<p>The list of known errors in this specification is available at
85<loc href="http://www.w3.org/&year;/&MM;/&LEV;-xpath-&YYYYMMDD;-errata"
86>http://www.w3.org/&year;/&MM;/&LEV;-xpath-&YYYYMMDD;-errata</loc>.</p>
87
88<p>Comments on this specification may be sent to <loc
89href="mailto:[email protected]"
90>[email protected]</loc>; <loc
91href="http://lists.w3.org/Archives/Public/www-xpath-comments">archives</loc>
92of the comments are available.</p>
93
94<p>The English version of this specification is the only normative
95version. However, for translations of this document, see <loc
96href="http://www.w3.org/Style/XSL/translations.html"
97>http://www.w3.org/Style/XSL/translations.html</loc>.</p>
98
99<p>A list of current W3C Recommendations and other technical documents
100can be found at <loc
101href="http://www.w3.org/TR">http://www.w3.org/TR</loc>.</p>
102
103<p>This specification is joint work of the XSL Working Group and the
104XML Linking Working Group and so is part of the <loc
105href="http://www.w3.org/Style/Activity">W3C Style activity</loc> and
106of the <loc href="http://www.w3.org/XML/Activity">W3C XML
107activity</loc>.</p>
108
109</status>
110
111<abstract><p>XPath is a language for addressing parts of an XML
112document, designed to be used by both XSLT and
113XPointer.</p></abstract>
114
115<langusage>
116<language id="EN">English</language>
117<language id="ebnf">EBNF</language>
118</langusage>
119<revisiondesc>
120<slist>
121<sitem>See RCS log for revision history.</sitem>
122</slist>
123</revisiondesc>
124</header>
125<body>
126
127<div1>
128<head>Introduction</head>
129
130<p>XPath is the result of an effort to provide a common syntax and
131semantics for functionality shared between XSL Transformations <bibref
132ref="XSLT"/> and XPointer <bibref ref="XPTR"/>.  The primary purpose
133of XPath is to address parts of an XML <bibref ref="XML"/> document.
134In support of this primary purpose, it also provides basic facilities
135for manipulation of strings, numbers and booleans.  XPath uses a
136compact, non-XML syntax to facilitate use of XPath within URIs and XML
137attribute values.  XPath operates on the abstract, logical structure
138of an XML document, rather than its surface syntax.  XPath gets its
139name from its use of a path notation as in URLs for navigating through
140the hierarchical structure of an XML document.</p>
141
142<p>In addition to its use for addressing, XPath is also designed so
143that it has a natural subset that can be used for matching (testing
144whether or not a node matches a pattern); this use of XPath is
145described in <xspecref href="http://www.w3.org/TR/WD-xslt#patterns"
146>XSLT</xspecref>.</p>
147
148<p>XPath models an XML document as a tree of nodes.  There are
149different types of nodes, including element nodes, attribute nodes and
150text nodes.  XPath defines a way to compute a <termref
151def="dt-string-value">string-value</termref> for each type of node.
152Some types of nodes also have names.  XPath fully supports XML
153Namespaces <bibref ref="XMLNAMES"/>.  Thus, the name of a node is
154modeled as a pair consisting of a local part and a possibly null
155namespace URI; this is called an <termref
156def="dt-expanded-name">expanded-name</termref>.  The data model is
157described in detail in <specref ref="data-model"/>.</p>
158
159<p>The primary syntactic construct in XPath is the expression.  An
160expression matches the production <nt def="NT-Expr">Expr</nt>.  An
161expression is evaluated to yield an object, which has one of the
162following four basic types:</p>
163
164<slist>
165
166<sitem>node-set (an unordered collection of nodes without duplicates)</sitem>
167
168<sitem>boolean (true or false)</sitem>
169
170<sitem>number (a floating-point number)</sitem>
171
172<sitem>string (a sequence of UCS characters)</sitem>
173
174</slist>
175
176<p>Expression evaluation occurs with respect to a context.  XSLT and
177XPointer specify how the context is determined for XPath expressions
178used in XSLT and XPointer respectively.  The context consists of:</p>
179
180<slist>
181
182<sitem>a node (<termdef id="dt-context-node" term="Context Node">the
183<term>context node</term></termdef>)</sitem>
184
185<sitem>a pair of non-zero positive integers (<termdef
186id="dt-context-position" term="Context Position">the <term>context
187position</term></termdef> and <termdef id="dt-context-size"
188term="Context Size">the <term>context size</term></termdef>)</sitem>
189
190<sitem>a set of variable bindings</sitem>
191
192<sitem>a function library</sitem>
193
194<sitem>the set of namespace declarations in scope for the
195expression</sitem>
196
197</slist>
198
199<p>The context position is always less than or equal to the
200context size.</p>
201
202<p>The variable bindings consist of a mapping from variable names to
203variable values.  The value of a variable is an object, which can be of
204any of the types that are possible for the value of an expression,
205and may also be of additional types not specified here.</p>
206
207<p>The function library consists of a mapping from function names to
208functions.  Each function takes zero or more arguments and returns a
209single result.  This document defines a core function library that all
210XPath implementations must support (see <specref ref="corelib"/>).
211For a function in the core function library, arguments and result are
212of the four basic types.  Both XSLT and XPointer extend XPath by
213defining additional functions; some of these functions operate on the
214four basic types; others operate on additional data types defined by
215XSLT and XPointer.</p>
216
217<p>The namespace declarations consist of a mapping from prefixes to
218namespace URIs.</p>
219
220<p>The variable bindings, function library and namespace declarations
221used to evaluate a subexpression are always the same as those used to
222evaluate the containing expression.  The context node, context
223position, and context size used to evaluate a subexpression are
224sometimes different from those used to evaluate the containing
225expression. Several kinds of expressions change the context node; only
226predicates change the context position and context size (see <specref
227ref="predicates"/>).  When the evaluation of a kind of expression is
228described, it will always be explicitly stated if the context node,
229context position, and context size change for the evaluation of
230subexpressions; if nothing is said about the context node, context
231position, and context size, they remain unchanged for the
232evaluation of subexpressions of that kind of expression.</p>
233
234<p>XPath expressions often occur in XML attributes.  The grammar
235specified in this section applies to the attribute value after XML 1.0
236normalization.  So, for example, if the grammar uses the character
237<code>&lt;</code>, this must not appear in the XML source as
238<code>&lt;</code> but must be quoted according to XML 1.0 rules by,
239for example, entering it as <code>&amp;lt;</code>. Within expressions,
240literal strings are delimited by single or double quotation marks,
241which are also used to delimit XML attributes. To avoid a quotation
242mark in an expression being interpreted by the XML processor as
243terminating the attribute value the quotation mark can be entered as a
244character reference (<code>&amp;quot;</code> or
245<code>&amp;apos;</code>).  Alternatively, the expression can use single
246quotation marks if the XML attribute is delimited with double
247quotation marks or vice-versa.</p>
248
249<p>One important kind of expression is a location path.  A location
250path selects a set of nodes relative to the context node.  The result
251of evaluating an expression that is a location path is the node-set
252containing the nodes selected by the location path.  Location paths
253can recursively contain expressions that are used to filter sets of
254nodes.  A location path matches the production <nt
255def="NT-LocationPath">LocationPath</nt>.</p>
256
257<p>In the following grammar, the non-terminals <xnt
258href="&XMLNames;#NT-QName">QName</xnt> and <xnt
259href="&XMLNames;#NT-NCName">NCName</xnt> are defined in <bibref
260ref="XMLNAMES"/>, and <xnt href="&XML;#NT-S">S</xnt> is defined in
261<bibref ref="XML"/>.  The grammar uses the same EBNF notation as
262<bibref ref="XML"/> (except that grammar symbols always have initial
263capital letters).</p>
264
265<p>Expressions are parsed by first dividing the character string to be
266parsed into tokens and then parsing the resulting sequence of tokens.
267Whitespace can be freely used between tokens.  The tokenization
268process is described in <specref ref="exprlex"/>.</p>
269
270</div1>
271
272<div1 id="location-paths">
273<head>Location Paths</head>
274
275<p>Although location paths are not the most general grammatical
276construct in the language (a <nt
277def="NT-LocationPath">LocationPath</nt> is a special case of an <nt
278def="NT-Expr">Expr</nt>), they are the most important construct and
279will therefore be described first.</p>
280
281<p>Every location path can be expressed using a straightforward but
282rather verbose syntax.  There are also a number of syntactic
283abbreviations that allow common cases to be expressed concisely.  This
284section will explain the semantics of location paths using the
285unabbreviated syntax.  The abbreviated syntax will then be explained
286by showing how it expands into the unabbreviated syntax (see <specref
287ref="path-abbrev"/>).</p>
288
289<p>Here are some examples of location paths using the unabbreviated
290syntax:</p>
291
292<ulist>
293
294<item><p><code>child::para</code> selects the
295<code>para</code> element children of the context node</p></item>
296
297<item><p><code>child::*</code> selects all element
298children of the context node</p></item>
299
300<item><p><code>child::text()</code> selects all text
301node children of the context node</p></item>
302
303<item><p><code>child::node()</code> selects all the
304children of the context node, whatever their node type</p></item>
305
306<item><p><code>attribute::name</code> selects the
307<code>name</code> attribute of the context node</p></item>
308
309<item><p><code>attribute::*</code> selects all the
310attributes of the context node</p></item>
311
312<item><p><code>descendant::para</code> selects the
313<code>para</code> element descendants of the context node</p></item>
314
315<item><p><code>ancestor::div</code> selects all <code>div</code>
316ancestors of the context node</p></item>
317
318<item><p><code>ancestor-or-self::div</code> selects the
319<code>div</code> ancestors of the context node and, if the context node is a
320<code>div</code> element, the context node as well</p></item>
321
322<item><p><code>descendant-or-self::para</code> selects the
323<code>para</code> element descendants of the context node and, if the context node is
324a <code>para</code> element, the context node as well</p></item>
325
326<item><p><code>self::para</code> selects the context node if it is a
327<code>para</code> element, and otherwise selects nothing</p></item>
328
329<item><p><code>child::chapter/descendant::para</code>
330selects the <code>para</code> element descendants of the
331<code>chapter</code> element children of the context node</p></item>
332
333<item><p><code>child::*/child::para</code> selects
334all <code>para</code> grandchildren of the context node</p></item>
335
336<item><p><code>/</code> selects the document root (which is
337always the parent of the document element)</p></item>
338
339<item><p><code>/descendant::para</code> selects all the
340<code>para</code> elements in the same document as the context node</p></item>
341
342<item><p><code>/descendant::olist/child::item</code> selects all the
343<code>item</code> elements that have an <code>olist</code> parent and
344that are in the same document as the context node</p></item>
345
346<item><p><code>child::para[position()=1]</code> selects the first
347<code>para</code> child of the context node</p></item>
348
349<item><p><code>child::para[position()=last()]</code> selects the last
350<code>para</code> child of the context node</p></item>
351
352<item><p><code>child::para[position()=last()-1]</code> selects
353the last but one <code>para</code> child of the context node</p></item>
354
355<item><p><code>child::para[position()>1]</code> selects all
356the <code>para</code> children of the context node other than the
357first <code>para</code> child of the context node</p></item>
358
359<item><p><code>following-sibling::chapter[position()=1]</code>
360selects the next <code>chapter</code> sibling of the context node</p></item>
361
362<item><p><code>preceding-sibling::chapter[position()=1]</code>
363selects the previous <code>chapter</code> sibling of the context
364node</p></item>
365
366<item><p><code>/descendant::figure[position()=42]</code> selects
367the forty-second <code>figure</code> element in the
368document</p></item>
369
370<item><p><code>/child::doc/child::chapter[position()=5]/child::section[position()=2]</code>
371selects the second <code>section</code> of the fifth
372<code>chapter</code> of the <code>doc</code> document
373element</p></item>
374
375<item><p><code>child::para[attribute::type="warning"]</code>
376selects all <code>para</code> children of the context node that have a
377<code>type</code> attribute with value <code>warning</code></p></item>
378
379<item><p><code>child::para[attribute::type='warning'][position()=5]</code>
380selects the fifth <code>para</code> child of the context node that has
381a <code>type</code> attribute with value
382<code>warning</code></p></item>
383
384<item><p><code>child::para[position()=5][attribute::type="warning"]</code>
385selects the fifth <code>para</code> child of the context node if that
386child has a <code>type</code> attribute with value
387<code>warning</code></p></item>
388
389<item><p><code>child::chapter[child::title='Introduction']</code>
390selects the <code>chapter</code> children of the context node that
391have one or more <code>title</code> children with <termref
392def="dt-string-value">string-value</termref> equal to
393<code>Introduction</code></p></item>
394
395<item><p><code>child::chapter[child::title]</code> selects the
396<code>chapter</code> children of the context node that have one or
397more <code>title</code> children</p></item>
398
399<item><p><code>child::*[self::chapter or self::appendix]</code>
400selects the <code>chapter</code> and <code>appendix</code> children of
401the context node</p></item>
402
403<item><p><code>child::*[self::chapter or
404self::appendix][position()=last()]</code> selects the last
405<code>chapter</code> or <code>appendix</code> child of the context
406node</p></item>
407
408</ulist>
409
410<p>There are two kinds of location path: relative location paths
411and absolute location paths.</p>
412
413<p>A relative location path consists of a sequence of one or more
414location steps separated by <code>/</code>.  The steps in a relative
415location path are composed together from left to right.  Each step in
416turn selects a set of nodes relative to a context node. An initial
417sequence of steps is composed together with a following step as
418follows.  The initial sequence of steps selects a set of nodes
419relative to a context node.  Each node in that set is used as a
420context node for the following step.  The sets of nodes identified by
421that step are unioned together.  The set of nodes identified by
422the composition of the steps is this union. For example,
423<code>child::div/child::para</code> selects the
424<code>para</code> element children of the <code>div</code> element
425children of the context node, or, in other words, the
426<code>para</code> element grandchildren that have <code>div</code>
427parents.</p>
428
429<p>An absolute location path consists of <code>/</code> optionally
430followed by a relative location path.  A <code>/</code> by itself
431selects the root node of the document containing the context node.  If
432it is followed by a relative location path, then the location path
433selects the set of nodes that would be selected by the relative
434location path relative to the root node of the document containing the
435context node.</p>
436
437<scrap>
438<head>Location Paths</head>
439<prodgroup pcw5="1" pcw2="10" pcw4="18">
440<prod id="NT-LocationPath">
441<lhs>LocationPath</lhs>
442<rhs><nt def="NT-RelativeLocationPath">RelativeLocationPath</nt></rhs>
443<rhs>| <nt def="NT-AbsoluteLocationPath">AbsoluteLocationPath</nt></rhs>
444</prod>
445<prod id="NT-AbsoluteLocationPath">
446<lhs>AbsoluteLocationPath</lhs>
447<rhs>'/' <nt def="NT-RelativeLocationPath">RelativeLocationPath</nt>?</rhs>
448<rhs>| <nt def="NT-AbbreviatedAbsoluteLocationPath">AbbreviatedAbsoluteLocationPath</nt></rhs>
449</prod>
450<prod id="NT-RelativeLocationPath">
451<lhs>RelativeLocationPath</lhs>
452<rhs><nt def="NT-Step">Step</nt></rhs>
453<rhs>| <nt def="NT-RelativeLocationPath">RelativeLocationPath</nt> '/' <nt def="NT-Step">Step</nt></rhs>
454<rhs>| <nt def="NT-AbbreviatedRelativeLocationPath">AbbreviatedRelativeLocationPath</nt></rhs>
455</prod>
456</prodgroup>
457</scrap>
458
459<div2>
460<head>Location Steps</head>
461
462<p>A location step has three parts:</p>
463
464<ulist>
465
466<item><p>an axis, which specifies the tree relationship between the
467nodes selected by the location step and the context node,</p></item>
468
469<item><p>a node test, which specifies the node type and <termref
470def="dt-expanded-name">expanded-name</termref> of the nodes selected
471by the location step, and</p></item>
472
473<item><p>zero or more predicates, which use arbitrary expressions to
474further refine the set of nodes selected by the location
475step.</p></item>
476
477</ulist>
478
479<p>The syntax for a location step is the axis name and node test
480separated by a double colon, followed by zero or more expressions each
481in square brackets. For example, in
482<code>child::para[position()=1]</code>, <code>child</code> is the name
483of the axis, <code>para</code> is the node test and
484<code>[position()=1]</code> is a predicate.</p>
485
486<p>The node-set selected by the location step is the node-set that
487results from generating an initial node-set from the axis and
488node-test, and then filtering that node-set by each of the predicates
489in turn.</p>
490
491<p>The initial node-set consists of the nodes having the relationship
492to the context node specified by the axis, and having the node type
493and <termref def="dt-expanded-name">expanded-name</termref> specified
494by the node test.  For example, a location step
495<code>descendant::para</code> selects the <code>para</code> element
496descendants of the context node: <code>descendant</code> specifies
497that each node in the initial node-set must be a descendant of the
498context; <code>para</code> specifies that each node in the initial
499node-set must be an element named <code>para</code>.  The available
500axes are described in <specref ref="axes"/>.  The available node tests
501are described in <specref ref="node-tests"/>.  The meaning of some
502node tests is dependent on the axis.</p>
503
504<p>The initial node-set is filtered by the first predicate to generate
505a new node-set; this new node-set is then filtered using the second
506predicate, and so on. The final node-set is the node-set selected by
507the location step. The axis affects how the expression in each
508predicate is evaluated and so the semantics of a predicate is defined
509with respect to an axis.  See <specref ref="predicates"/>.</p>
510
511<scrap>
512<head>Location Steps</head>
513<prodgroup pcw5="1" pcw2="10" pcw4="18">
514<prod id="NT-Step">
515<lhs>Step</lhs>
516<rhs><nt def="NT-AxisSpecifier">AxisSpecifier</nt>
517<nt def="NT-NodeTest">NodeTest</nt>
518<nt def="NT-Predicate">Predicate</nt>*</rhs>
519<rhs>| <nt def="NT-AbbreviatedStep">AbbreviatedStep</nt></rhs>
520</prod>
521<prod id="NT-AxisSpecifier">
522<lhs>AxisSpecifier</lhs>
523<rhs><nt def="NT-AxisName">AxisName</nt> '::'</rhs>
524<rhs>| <nt def="NT-AbbreviatedAxisSpecifier">AbbreviatedAxisSpecifier</nt>
525</rhs>
526</prod>
527</prodgroup>
528</scrap>
529
530</div2>
531
532<div2 id="axes">
533<head>Axes</head>
534
535<p>The following axes are available:</p>
536
537<ulist>
538
539<item><p>the <code>child</code> axis contains the children of the
540context node</p></item>
541
542<item><p>the <code>descendant</code> axis contains the descendants of
543the context node; a descendant is a child or a child of a child and so
544on; thus the descendant axis never contains attribute or namespace
545nodes</p></item>
546
547<item><p>the <code>parent</code> axis contains the <termref
548def="dt-parent">parent</termref> of the context node, if there is
549one</p></item>
550
551<item><p>the <code>ancestor</code> axis contains the ancestors of the
552context node; the ancestors of the context node consist of the
553<termref def="dt-parent">parent</termref> of context node and the
554parent's parent and so on; thus, the ancestor axis will always include
555the root node, unless the context node is the root node</p></item>
556
557<item><p>the <code>following-sibling</code> axis contains all the
558following siblings of the context node; if the
559context node is an attribute node or namespace node, the
560<code>following-sibling</code> axis is empty</p></item>
561
562<item><p>the <code>preceding-sibling</code> axis contains all the
563preceding siblings of the context node; if the context node is an
564attribute node or namespace node, the <code>preceding-sibling</code>
565axis is empty</p></item>
566
567<item><p>the <code>following</code> axis contains all nodes in the
568same document as the context node that are after the context node in
569document order, excluding any descendants and excluding attribute
570nodes and namespace nodes</p></item>
571
572<item><p>the <code>preceding</code> axis contains all nodes in the
573same document as the context node that are before the context node in
574document order, excluding any ancestors and excluding attribute nodes
575and namespace nodes</p></item>
576
577<item><p>the <code>attribute</code> axis contains the attributes of
578the context node; the axis will be empty unless the context node is an
579element</p></item>
580
581<item><p>the <code>namespace</code> axis contains the namespace nodes
582of the context node; the axis will be empty unless the context node
583is an element</p></item>
584
585<item><p>the <code>self</code> axis contains just the context node
586itself</p></item>
587
588<item><p>the <code>descendant-or-self</code> axis contains the context
589node and the descendants of the context node</p></item>
590
591<item><p>the <code>ancestor-or-self</code> axis contains the context
592node and the ancestors of the context node; thus, the ancestor axis
593will always include the root node</p></item>
594
595</ulist>
596
597<note><p>The <code>ancestor</code>, <code>descendant</code>,
598<code>following</code>, <code>preceding</code> and <code>self</code>
599axes partition a document (ignoring attribute and namespace nodes):
600they do not overlap and together they contain all the nodes in the
601document.</p></note>
602
603<scrap>
604<head>Axes</head>
605<prod id="NT-AxisName">
606<lhs>AxisName</lhs>
607<rhs>'ancestor'</rhs>
608<rhs>| 'ancestor-or-self'</rhs>
609<rhs>| 'attribute'</rhs>
610<rhs>| 'child'</rhs>
611<rhs>| 'descendant'</rhs>
612<rhs>| 'descendant-or-self'</rhs>
613<rhs>| 'following'</rhs>
614<rhs>| 'following-sibling'</rhs>
615<rhs>| 'namespace'</rhs>
616<rhs>| 'parent'</rhs>
617<rhs>| 'preceding'</rhs>
618<rhs>| 'preceding-sibling'</rhs>
619<rhs>| 'self'</rhs>
620</prod>
621</scrap>
622
623</div2>
624
625<div2 id="node-tests">
626<head>Node Tests</head>
627
628<p><termdef id="dt-principal-node-type" term="Principal Node
629Type">Every axis has a <term>principal node type</term>.  If an axis
630can contain elements, then the principal node type is element;
631otherwise, it is the type of the nodes that the axis can
632contain.</termdef> Thus,</p>
633
634<slist>
635
636<sitem>For the attribute axis, the principal node type is attribute.</sitem>
637
638<sitem>For the namespace axis, the principal node type is namespace.</sitem>
639
640<sitem>For other axes, the principal node type is element.</sitem>
641
642</slist>
643
644<p>A node test that is a <xnt href="&XMLNames;#NT-QName">QName</xnt>
645is true if and only if the type of the node (see <specref ref="data-model"/>)
646is the principal node type and has
647an <termref def="dt-expanded-name">expanded-name</termref> equal to
648the <termref def="dt-expanded-name">expanded-name</termref> specified
649by the <xnt href="&XMLNames;#NT-QName">QName</xnt>.  For example,
650<code>child::para</code> selects the <code>para</code> element
651children of the context node; if the context node has no
652<code>para</code> children, it will select an empty set of nodes.
653<code>attribute::href</code> selects the <code>href</code> attribute
654of the context node; if the context node has no <code>href</code>
655attribute, it will select an empty set of nodes.</p>
656
657<p>A <xnt href="&XMLNames;#NT-QName">QName</xnt> in the node test is
658expanded into an <termref
659def="dt-expanded-name">expanded-name</termref> using the namespace
660declarations from the expression context.  This is the same way
661expansion is done for element type names in start and end-tags except
662that the default namespace declared with <code>xmlns</code> is not
663used: if the <xnt href="&XMLNames;#NT-QName">QName</xnt> does not have
664a prefix, then the namespace URI is null (this is the same way
665attribute names are expanded).  It is an error if the <xnt
666href="&XMLNames;#NT-QName">QName</xnt> has a prefix for which there is
667no namespace declaration in the expression context.</p>
668
669<p>A node test <code>*</code> is true for any node of the principal
670node type.  For example, <code>child::*</code> will select all element
671children of the context node, and <code>attribute::*</code> will
672select all attributes of the context node.</p>
673
674<p>A node test can have the form <xnt
675href="&XMLNames;#NT-NCName">NCName</xnt><code>:*</code>.  In this
676case, the prefix is expanded in the same way as with a <xnt
677href="&XMLNames;#NT-QName">QName</xnt>, using the context namespace
678declarations.  It is an error if there is no namespace declaration for
679the prefix in the expression context.  The node test will be true for
680any node of the principal type whose <termref
681def="dt-expanded-name">expanded-name</termref> has the namespace URI
682to which the prefix expands, regardless of the local part of the
683name.</p>
684
685<p>The node test <code>text()</code> is true for any text node. For
686example, <code>child::text()</code> will select the text node
687children of the context node.  Similarly, the node test
688<code>comment()</code> is true for any comment node, and the node test
689<code>processing-instruction()</code> is true for any processing
690instruction. The <code>processing-instruction()</code> test may have
691an argument that is <nt def="NT-Literal">Literal</nt>; in this case, it
692is true for any processing instruction that has a name equal to the
693value of the <nt def="NT-Literal">Literal</nt>.</p>
694
695<p>A node test <code>node()</code> is true for any node of any type
696whatsoever.</p>
697
698<scrap>
699<head></head>
700<prod id="NT-NodeTest">
701<lhs>NodeTest</lhs>
702<rhs><nt def="NT-NameTest">NameTest</nt></rhs>
703<rhs>| <nt def="NT-NodeType">NodeType</nt> '(' ')'</rhs>
704<rhs>| 'processing-instruction' '(' <nt def="NT-Literal">Literal</nt> ')'</rhs>
705</prod>
706</scrap>
707
708</div2>
709
710<div2 id="predicates">
711<head>Predicates</head>
712
713<p>An axis is either a forward axis or a reverse axis.  An axis that
714only ever contains the context node or nodes that are after the
715context node in <termref def="dt-document-order">document
716order</termref> is a forward axis.  An axis that only ever contains
717the context node or nodes that are before the context node in <termref
718def="dt-document-order">document order</termref> is a reverse axis.
719Thus, the ancestor, ancestor-or-self, preceding, and preceding-sibling
720axes are reverse axes; all other axes are forward axes. Since the self
721axis always contains at most one node, it makes no difference whether
722it is a forward or reverse axis.  <termdef term="Proximity Position"
723id="dt-proximity-position">The <term>proximity position</term> of a
724member of a node-set with respect to an axis is defined to be the
725position of the node in the node-set ordered in document order if the
726axis is a forward axis and ordered in reverse document order if the
727axis is a reverse axis. The first position is 1.</termdef></p>
728
729<p>A predicate filters a node-set with respect to an axis to produce a
730new node-set.  For each node in the node-set to be filtered, the <nt
731def="NT-PredicateExpr">PredicateExpr</nt> is evaluated with that node
732as the context node, with the number of nodes in the node-set as the
733context size, and with the <termref
734def="dt-proximity-position">proximity position</termref> of the node
735in the node-set with respect to the axis as the context position; if
736<nt def="NT-PredicateExpr">PredicateExpr</nt> evaluates to true for
737that node, the node is included in the new node-set; otherwise, it is
738not included.</p>
739
740<p>A <nt def="NT-PredicateExpr">PredicateExpr</nt> is evaluated by
741evaluating the <nt def="NT-Expr">Expr</nt> and converting the result
742to a boolean.  If the result is a number, the result will be converted
743to true if the number is equal to the context position and will be
744converted to false otherwise; if the result is not a number, then the
745result will be converted as if by a call to the
746<function>boolean</function> function.  Thus a location path
747<code>para[3]</code> is equivalent to
748<code>para[position()=3]</code>.</p>
749
750<scrap>
751<head>Predicates</head>
752<prod id="NT-Predicate">
753<lhs>Predicate</lhs>
754<rhs>'[' <nt def="NT-PredicateExpr">PredicateExpr</nt> ']'</rhs>
755</prod>
756<prod id="NT-PredicateExpr">
757<lhs>PredicateExpr</lhs>
758<rhs><nt def="NT-Expr">Expr</nt></rhs>
759</prod>
760</scrap>
761
762</div2>
763
764<div2 id="path-abbrev">
765<head>Abbreviated Syntax</head>
766
767<p>Here are some examples of location paths using abbreviated
768syntax:</p>
769
770<ulist>
771
772<item><p><code>para</code> selects the <code>para</code> element children of
773the context node</p></item>
774
775<item><p><code>*</code> selects all element children of the
776context node</p></item>
777
778<item><p><code>text()</code> selects all text node children of the
779context node</p></item>
780
781<item><p><code>@name</code> selects the <code>name</code> attribute of
782the context node</p></item>
783
784<item><p><code>@*</code> selects all the attributes of the
785context node</p></item>
786
787<item><p><code>para[1]</code> selects the first <code>para</code> child of
788the context node</p></item>
789
790<item><p><code>para[last()]</code> selects the last <code>para</code> child
791of the context node</p></item>
792
793<item><p><code>*/para</code> selects all <code>para</code> grandchildren of
794the context node</p></item>
795
796<item><p><code>/doc/chapter[5]/section[2]</code> selects the second
797<code>section</code> of the fifth <code>chapter</code> of the
798<code>doc</code></p></item>
799
800<item><p><code>chapter//para</code> selects the <code>para</code> element
801descendants of the <code>chapter</code> element children of the
802context node</p></item>
803
804<item><p><code>//para</code> selects all the <code>para</code> descendants of
805the document root and thus selects all <code>para</code> elements in the
806same document as the context node</p></item>
807
808<item><p><code>//olist/item</code> selects all the <code>item</code>
809elements in the same document as the context node that have an
810<code>olist</code> parent</p></item>
811
812<item><p><code>.</code> selects the context node</p></item>
813
814<item><p><code>.//para</code> selects the <code>para</code> element
815descendants of the context node</p></item>
816
817<item><p><code>..</code> selects the parent of the context node</p></item>
818
819<item><p><code>../@lang</code> selects the <code>lang</code> attribute
820of the parent of the context node</p></item>
821
822<item><p><code>para[@type="warning"]</code> selects all <code>para</code>
823children of the context node that have a <code>type</code> attribute with
824value <code>warning</code></p></item>
825
826<item><p><code>para[@type="warning"][5]</code> selects the fifth
827<code>para</code> child of the context node that has a <code>type</code>
828attribute with value <code>warning</code></p></item>
829
830<item><p><code>para[5][@type="warning"]</code> selects the fifth
831<code>para</code> child of the context node if that child has a
832<code>type</code> attribute with value <code>warning</code></p></item>
833
834<item><p><code>chapter[title="Introduction"]</code> selects the
835<code>chapter</code> children of the context node that have one or
836more <code>title</code> children with <termref
837def="dt-string-value">string-value</termref> equal to
838<code>Introduction</code></p></item>
839
840<item><p><code>chapter[title]</code> selects the <code>chapter</code>
841children of the context node that have one or more <code>title</code>
842children</p></item>
843
844<item><p><code>employee[@secretary and @assistant]</code> selects all
845the <code>employee</code> children of the context node that have both a
846<code>secretary</code> attribute and an <code>assistant</code>
847attribute</p></item>
848
849</ulist>
850
851<p>The most important abbreviation is that <code>child::</code> can be
852omitted from a location step.  In effect, <code>child</code> is the
853default axis.  For example, a location path <code>div/para</code> is
854short for <code>child::div/child::para</code>.</p>
855
856<p>There is also an abbreviation for attributes:
857<code>attribute::</code> can be abbreviated to <code>@</code>. For
858example, a location path <code>para[@type="warning"]</code> is short
859for <code>child::para[attribute::type="warning"]</code> and so selects
860<code>para</code> children with a <code>type</code> attribute with
861value equal to <code>warning</code>.</p>
862
863<p><code>//</code> is short for
864<code>/descendant-or-self::node()/</code>.  For example,
865<code>//para</code> is short for
866<code>/descendant-or-self::node()/child::para</code> and so will
867select any <code>para</code> element in the document (even a
868<code>para</code> element that is a document element will be selected
869by <code>//para</code> since the document element node is a child of
870the root node); <code>div//para</code> is short for
871<code>div/descendant-or-self::node()/child::para</code> and so
872will select all <code>para</code> descendants of <code>div</code>
873children.</p>
874
875<note><p>The location path <code>//para[1]</code> does
876<emph>not</emph> mean the same as the location path
877<code>/descendant::para[1]</code>.  The latter selects the first
878descendant <code>para</code> element; the former selects all descendant
879<code>para</code> elements that are the first <code>para</code>
880children of their parents.</p></note>
881
882<p>A location step of <code>.</code> is short for
883<code>self::node()</code>. This is particularly useful in
884conjunction with <code>//</code>. For example, the location path
885<code>.//para</code> is short for</p>
886
887<eg>self::node()/descendant-or-self::node()/child::para</eg>
888
889<p>and so will select all <code>para</code> descendant elements of the
890context node.</p>
891
892<p>Similarly, a location step of <code>..</code> is short for
893<code>parent::node()</code>. For example, <code>../title</code> is
894short for <code>parent::node()/child::title</code> and so will
895select the <code>title</code> children of the parent of the context
896node.</p>
897
898<scrap>
899<head>Abbreviations</head>
900<prodgroup pcw5="1" pcw2="15" pcw4="16">
901<prod id="NT-AbbreviatedAbsoluteLocationPath">
902<lhs>AbbreviatedAbsoluteLocationPath</lhs>
903<rhs>'//' <nt def="NT-RelativeLocationPath">RelativeLocationPath</nt></rhs>
904</prod>
905<prod id="NT-AbbreviatedRelativeLocationPath">
906<lhs>AbbreviatedRelativeLocationPath</lhs>
907<rhs><nt def="NT-RelativeLocationPath">RelativeLocationPath</nt> '//' <nt def="NT-Step">Step</nt></rhs>
908</prod>
909<prod id="NT-AbbreviatedStep">
910<lhs>AbbreviatedStep</lhs>
911<rhs>'.'</rhs>
912<rhs>| '..'</rhs>
913</prod>
914<prod id="NT-AbbreviatedAxisSpecifier">
915<lhs>AbbreviatedAxisSpecifier</lhs>
916<rhs>'@'?</rhs>
917</prod>
918</prodgroup>
919</scrap>
920
921</div2>
922
923</div1>
924
925<div1>
926<head>Expressions</head>
927
928<div2>
929<head>Basics</head>
930
931<p>A <nt def="NT-VariableReference">VariableReference</nt> evaluates
932to the value to which the variable name is bound in the set of
933variable bindings in the context.  It is an error if the variable name
934is not bound to any value in the set of variable bindings in the
935expression context.</p>
936
937<p>Parentheses may be used for grouping.</p>
938
939<scrap>
940<head></head>
941<prod id="NT-Expr">
942<lhs>Expr</lhs>
943<rhs><nt def="NT-OrExpr">OrExpr</nt></rhs>
944</prod>
945<prod id="NT-PrimaryExpr">
946<lhs>PrimaryExpr</lhs>
947<rhs><nt def="NT-VariableReference">VariableReference</nt></rhs>
948<rhs>| '(' <nt def="NT-Expr">Expr</nt> ')'</rhs>
949<rhs>| <nt def="NT-Literal">Literal</nt></rhs>
950<rhs>| <nt def="NT-Number">Number</nt></rhs>
951<rhs>| <nt def="NT-FunctionCall">FunctionCall</nt></rhs>
952</prod>
953</scrap>
954
955</div2>
956
957<div2>
958<head>Function Calls</head>
959
960<p>A <nt def="NT-FunctionCall">FunctionCall</nt> expression is
961evaluated by using the <nt def="NT-FunctionName">FunctionName</nt> to
962identify a function in the expression evaluation context function
963library, evaluating each of the <nt def="NT-Argument">Argument</nt>s,
964converting each argument to the type required by the function, and
965finally calling the function, passing it the converted arguments.  It
966is an error if the number of arguments is wrong or if an argument
967cannot be converted to the required type.  The result of the <nt
968def="NT-FunctionCall">FunctionCall</nt> expression is the result
969returned by the function.</p>
970
971<p>An argument is converted to type string as if by calling the
972<function>string</function> function.  An argument is converted to
973type number as if by calling the <function>number</function> function.
974An argument is converted to type boolean as if by calling the
975<function>boolean</function> function.  An argument that is not of
976type node-set cannot be converted to a node-set.</p>
977
978<scrap>
979<head></head>
980<prod id="NT-FunctionCall">
981<lhs>FunctionCall</lhs>
982<rhs><nt def="NT-FunctionName">FunctionName</nt> '(' ( <nt def="NT-Argument">Argument</nt> ( ',' <nt def="NT-Argument">Argument</nt> )* )? ')'</rhs>
983</prod>
984<prod id="NT-Argument">
985<lhs>Argument</lhs>
986<rhs><nt def="NT-Expr">Expr</nt></rhs>
987</prod>
988</scrap>
989
990</div2>
991
992<div2 id="node-sets">
993<head>Node-sets</head>
994
995<p>A location path can be used as an expression.  The expression
996returns the set of nodes selected by the path.</p>
997
998<p>The <code>|</code> operator computes the union of its operands,
999which must be node-sets.</p>
1000
1001<p><nt def="NT-Predicate">Predicate</nt>s are used to filter
1002expressions in the same way that they are used in location paths. It
1003is an error if the expression to be filtered does not evaluate to a
1004node-set.  The <nt def="NT-Predicate">Predicate</nt> filters the
1005node-set with respect to the child axis.</p>
1006
1007<note><p>The meaning of a <nt def="NT-Predicate">Predicate</nt>
1008depends crucially on which axis applies. For example,
1009<code>preceding::foo[1]</code> returns the first <code>foo</code>
1010element in <emph>reverse document order</emph>, because the axis that
1011applies to the <code>[1]</code> predicate is the preceding axis; by
1012contrast, <code>(preceding::foo)[1]</code> returns the first
1013<code>foo</code> element in <emph>document order</emph>, because the
1014axis that applies to the <code>[1]</code> predicate is the child
1015axis.</p></note>
1016
1017<p>The <code>/</code> and <code>//</code> operators compose an
1018expression and a relative location path.  It is an error if the
1019expression does not evaluate to a node-set.  The <code>/</code>
1020operator does composition in the same way as when <code>/</code> is
1021used in a location path. As in location paths, <code>//</code> is
1022short for <code>/descendant-or-self::node()/</code>.</p>
1023
1024<p>There are no types of objects that can be converted to node-sets.</p>
1025
1026<scrap>
1027<head></head>
1028<prod id="NT-UnionExpr">
1029<lhs>UnionExpr</lhs>
1030<rhs><nt def="NT-PathExpr">PathExpr</nt></rhs>
1031<rhs>| <nt def="NT-UnionExpr">UnionExpr</nt> '|' <nt def="NT-PathExpr">PathExpr</nt></rhs>
1032</prod>
1033<prod id="NT-PathExpr">
1034<lhs>PathExpr</lhs>
1035<rhs><nt def="NT-LocationPath">LocationPath</nt></rhs>
1036<rhs>| <nt def="NT-FilterExpr">FilterExpr</nt></rhs>
1037<rhs>| <nt def="NT-FilterExpr">FilterExpr</nt> '/' <nt def="NT-RelativeLocationPath">RelativeLocationPath</nt></rhs>
1038<rhs>| <nt def="NT-FilterExpr">FilterExpr</nt> '//' <nt def="NT-RelativeLocationPath">RelativeLocationPath</nt></rhs>
1039</prod>
1040<prod id="NT-FilterExpr">
1041<lhs>FilterExpr</lhs>
1042<rhs><nt def="NT-PrimaryExpr">PrimaryExpr</nt></rhs>
1043<rhs>| <nt def="NT-FilterExpr">FilterExpr</nt> <nt def="NT-Predicate">Predicate</nt></rhs>
1044</prod>
1045</scrap>
1046
1047</div2>
1048
1049<div2 id="booleans">
1050<head>Booleans</head>
1051
1052<p>An object of type boolean can have one of two values, true and
1053false.</p>
1054
1055<p>An <code>or</code> expression is evaluated by evaluating each
1056operand and converting its value to a boolean as if by a call to the
1057<function>boolean</function> function.  The result is true if either
1058value is true and false otherwise.  The right operand is not evaluated
1059if the left operand evaluates to true.</p>
1060
1061<p>An <code>and</code> expression is evaluated by evaluating each
1062operand and converting its value to a boolean as if by a call to the
1063<function>boolean</function> function.  The result is true if both
1064values are true and false otherwise.  The right operand is not
1065evaluated if the left operand evaluates to false.</p>
1066
1067<p>An <nt def="NT-EqualityExpr">EqualityExpr</nt> (that is not just
1068a <nt def="NT-RelationalExpr">RelationalExpr</nt>) or a <nt
1069def="NT-RelationalExpr">RelationalExpr</nt> (that is not just an <nt
1070def="NT-AdditiveExpr">AdditiveExpr</nt>) is evaluated by comparing the
1071objects that result from evaluating the two operands.  Comparison of
1072the resulting objects is defined in the following three paragraphs.
1073First, comparisons that involve node-sets are defined in terms of
1074comparisons that do not involve node-sets; this is defined uniformly
1075for <code>=</code>, <code>!=</code>, <code>&lt;=</code>,
1076<code>&lt;</code>, <code>&gt;=</code> and <code>&gt;</code>.  Second,
1077comparisons that do not involve node-sets are defined for
1078<code>=</code> and <code>!=</code>.  Third, comparisons that do not
1079involve node-sets are defined for <code>&lt;=</code>,
1080<code>&lt;</code>, <code>&gt;=</code> and <code>&gt;</code>.</p>
1081
1082<p>If both objects to be compared are node-sets, then the comparison
1083will be true if and only if there is a node in the first node-set and
1084a node in the second node-set such that the result of performing the
1085comparison on the <termref
1086def="dt-string-value">string-value</termref>s of the two nodes is
1087true.  If one object to be compared is a node-set and the other is a
1088number, then the comparison will be true if and only if there is a
1089node in the node-set such that the result of performing the comparison
1090on the number to be compared and on the result of converting the
1091<termref def="dt-string-value">string-value</termref> of that node to
1092a number using the <function>number</function> function is true.  If
1093one object to be compared is a node-set and the other is a string,
1094then the comparison will be true if and only if there is a node in the
1095node-set such that the result of performing the comparison on the
1096<termref def="dt-string-value">string-value</termref> of the node and
1097the other string is true. If one object to be compared is a node-set
1098and the other is a boolean, then the comparison will be true if and
1099only if the result of performing the comparison on the boolean and on
1100the result of converting the node-set to a boolean using the
1101<function>boolean</function> function is true.</p>
1102
1103<p>When neither object to be compared is a node-set and the operator
1104is <code>=</code> or <code>!=</code>, then the objects are compared by
1105converting them to a common type as follows and then comparing them.
1106If at least one object to be compared is a boolean, then each object
1107to be compared is converted to a boolean as if by applying the
1108<function>boolean</function> function.  Otherwise, if at least one
1109object to be compared is a number, then each object to be compared is
1110converted to a number as if by applying the
1111<function>number</function> function.  Otherwise, both objects to be
1112compared are converted to strings as if by applying the
1113<function>string</function> function.  The <code>=</code> comparison
1114will be true if and only if the objects are equal; the <code>!=</code>
1115comparison will be true if and only if the objects are not equal.
1116Numbers are compared for equality according to IEEE 754 <bibref
1117ref="IEEE754"/>.  Two booleans are equal if either both are true or
1118both are false.  Two strings are equal if and only if they consist of
1119the same sequence of UCS characters.</p>
1120
1121<note><p>If <code>$x</code> is bound to a node-set, then
1122<code>$x="foo"</code> does not mean the same as
1123<code>not($x!="foo")</code>: the former is true if and only if
1124<emph>some</emph> node in <code>$x</code> has the string-value
1125<code>foo</code>; the latter is true if and only if <emph>all</emph>
1126nodes in <code>$x</code> have the string-value
1127<code>foo</code>.</p></note>
1128
1129<p>When neither object to be compared is a node-set and the operator
1130is <code>&lt;=</code>, <code>&lt;</code>, <code>&gt;=</code> or
1131<code>&gt;</code>, then the objects are compared by converting both
1132objects to numbers and comparing the numbers according to IEEE 754.
1133The <code>&lt;</code> comparison will be true if and only if the first
1134number is less than the second number.  The <code>&lt;=</code>
1135comparison will be true if and only if the first number is less than
1136or equal to the second number.  The <code>&gt;</code> comparison will
1137be true if and only if the first number is greater than the second
1138number.  The <code>&gt;=</code> comparison will be true if and only if
1139the first number is greater than or equal to the second number.</p>
1140
1141<note>
1142
1143<p>When an XPath expression occurs in an XML document, any
1144<code>&lt;</code> and <code>&lt;=</code> operators must be quoted
1145according to XML 1.0 rules by using, for example,
1146<code>&amp;lt;</code> and <code>&amp;lt;=</code>. In the following
1147example the value of the <code>test</code> attribute is an XPath
1148expression:</p>
1149
1150<eg><![CDATA[<xsl:if test="@value &lt; 10">...</xsl:if>]]></eg>
1151
1152</note>
1153
1154<scrap>
1155<head></head>
1156<prod id="NT-OrExpr">
1157<lhs>OrExpr</lhs>
1158<rhs><nt def="NT-AndExpr">AndExpr</nt></rhs>
1159<rhs>| <nt def="NT-OrExpr">OrExpr</nt> 'or' <nt def="NT-AndExpr">AndExpr</nt></rhs>
1160</prod>
1161<prod id="NT-AndExpr">
1162<lhs>AndExpr</lhs>
1163<rhs><nt def="NT-EqualityExpr">EqualityExpr</nt></rhs>
1164<rhs>| <nt def="NT-AndExpr">AndExpr</nt> 'and' <nt def="NT-EqualityExpr">EqualityExpr</nt></rhs>
1165</prod>
1166<prod id="NT-EqualityExpr">
1167<lhs>EqualityExpr</lhs>
1168<rhs><nt def="NT-RelationalExpr">RelationalExpr</nt></rhs>
1169<rhs>| <nt def="NT-EqualityExpr">EqualityExpr</nt> '=' <nt def="NT-RelationalExpr">RelationalExpr</nt></rhs>
1170<rhs>| <nt def="NT-EqualityExpr">EqualityExpr</nt> '!=' <nt def="NT-RelationalExpr">RelationalExpr</nt></rhs>
1171</prod>
1172<prod id="NT-RelationalExpr">
1173<lhs>RelationalExpr</lhs>
1174<rhs><nt def="NT-AdditiveExpr">AdditiveExpr</nt></rhs>
1175<rhs>| <nt def="NT-RelationalExpr">RelationalExpr</nt> '&lt;' <nt def="NT-AdditiveExpr">AdditiveExpr</nt></rhs>
1176<rhs>| <nt def="NT-RelationalExpr">RelationalExpr</nt> '>' <nt def="NT-AdditiveExpr">AdditiveExpr</nt></rhs>
1177<rhs>| <nt def="NT-RelationalExpr">RelationalExpr</nt> '&lt;=' <nt def="NT-AdditiveExpr">AdditiveExpr</nt></rhs>
1178<rhs>| <nt def="NT-RelationalExpr">RelationalExpr</nt> '>=' <nt def="NT-AdditiveExpr">AdditiveExpr</nt></rhs>
1179</prod>
1180</scrap>
1181
1182<note><p>The effect of the above grammar is that the order of
1183precedence is (lowest precedence first):</p>
1184
1185<ulist>
1186
1187<item><p><code>or</code></p></item>
1188
1189<item><p><code>and</code></p></item>
1190
1191<item><p><code>=</code>, <code>!=</code></p></item>
1192
1193<item><p><code>&lt;=</code>, <code>&lt;</code>, <code>&gt;=</code>,
1194<code>&gt;</code></p></item>
1195
1196</ulist>
1197
1198<p>and the operators are all left associative.</p>
1199
1200<p>For example, <code>3 &gt; 2 &gt; 1</code> is equivalent to <code>(3
1201&gt; 2) &gt; 1</code>, which evaluates to false.</p>
1202
1203</note>
1204
1205</div2>
1206
1207<div2 id="numbers">
1208<head>Numbers</head>
1209
1210<p>A number represents a floating-point number.  A number can have any
1211double-precision 64-bit format IEEE 754 value <bibref ref="IEEE754"/>.
1212These include a special <quote>Not-a-Number</quote> (NaN) value,
1213positive and negative infinity, and positive and negative zero.  See
1214<loc href="http://java.sun.com/docs/books/jls/html/4.doc.html#9208"
1215>Section 4.2.3</loc> of <bibref ref="JLS"/> for a summary of the key
1216rules of the IEEE 754 standard.</p>
1217
1218<p>The numeric operators convert their operands to numbers as if by
1219calling the <function>number</function> function.</p>
1220
1221<p>The <code>+</code> operator performs addition.</p>
1222
1223<p>The <code>-</code> operator performs subtraction.</p>
1224
1225<note><p>Since XML allows <code>-</code> in names, the <code>-</code>
1226operator typically needs to be preceded by whitespace.  For example,
1227<code>foo-bar</code> evaluates to a node-set containing the child
1228elements named <code>foo-bar</code>; <code>foo - bar</code> evaluates
1229to the difference of the result of converting the <termref
1230def="dt-string-value">string-value</termref> of the first
1231<code>foo</code> child element to a number and the result of
1232converting the <termref def="dt-string-value">string-value</termref>
1233of the first <code>bar</code> child to a number.</p></note>
1234
1235<p>The <code>div</code> operator performs floating-point division
1236according to IEEE 754.</p>
1237
1238<p>The <code>mod</code> operator returns the remainder from a
1239truncating division.  For example,</p>
1240
1241<ulist>
1242<item><p><code>5 mod 2</code> returns <code>1</code></p></item>
1243<item><p><code>5 mod -2</code> returns <code>1</code></p></item>
1244<item><p><code>-5 mod 2</code> returns <code>-1</code></p></item>
1245<item><p><code>-5 mod -2</code> returns <code>-1</code></p></item>
1246</ulist>
1247
1248<note><p>This is the same as the <code>%</code> operator in Java and
1249ECMAScript.</p></note>
1250
1251<note><p>This is not the same as the IEEE 754 remainder operation, which
1252returns the remainder from a rounding division.</p></note>
1253
1254<scrap>
1255<head>Numeric Expressions</head>
1256<prodgroup pcw5="1" pcw2="10" pcw4="21">
1257<prod id="NT-AdditiveExpr">
1258<lhs>AdditiveExpr</lhs>
1259<rhs><nt def="NT-MultiplicativeExpr">MultiplicativeExpr</nt></rhs>
1260<rhs>| <nt def="NT-AdditiveExpr">AdditiveExpr</nt> '+' <nt def="NT-MultiplicativeExpr">MultiplicativeExpr</nt></rhs>
1261<rhs>| <nt def="NT-AdditiveExpr">AdditiveExpr</nt> '-' <nt def="NT-MultiplicativeExpr">MultiplicativeExpr</nt></rhs>
1262</prod>
1263<prod id="NT-MultiplicativeExpr">
1264<lhs>MultiplicativeExpr</lhs>
1265<rhs><nt def="NT-UnaryExpr">UnaryExpr</nt></rhs>
1266<rhs>| <nt def="NT-MultiplicativeExpr">MultiplicativeExpr</nt> <nt def="NT-MultiplyOperator">MultiplyOperator</nt> <nt def="NT-UnaryExpr">UnaryExpr</nt></rhs>
1267<rhs>| <nt def="NT-MultiplicativeExpr">MultiplicativeExpr</nt> 'div' <nt def="NT-UnaryExpr">UnaryExpr</nt></rhs>
1268<rhs>| <nt def="NT-MultiplicativeExpr">MultiplicativeExpr</nt> 'mod' <nt def="NT-UnaryExpr">UnaryExpr</nt></rhs>
1269</prod>
1270<prod id="NT-UnaryExpr">
1271<lhs>UnaryExpr</lhs>
1272<rhs><nt def="NT-UnionExpr">UnionExpr</nt></rhs>
1273<rhs>| '-' <nt def="NT-UnaryExpr">UnaryExpr</nt></rhs>
1274</prod>
1275</prodgroup>
1276</scrap>
1277
1278</div2>
1279
1280<div2 id="strings">
1281<head>Strings</head>
1282
1283<p>Strings consist of a sequence of zero or more characters, where a
1284character is defined as in the XML Recommendation <bibref ref="XML"/>.
1285A single character in XPath thus corresponds to a single Unicode
1286abstract character with a single corresponding Unicode scalar value
1287(see <bibref ref="UNICODE"/>); this is not the same thing as a 16-bit
1288Unicode code value: the Unicode coded character representation for an
1289abstract character with Unicode scalar value greater that U+FFFF is a
1290pair of 16-bit Unicode code values (a surrogate pair).  In many
1291programming languages, a string is represented by a sequence of 16-bit
1292Unicode code values; implementations of XPath in such languages must
1293take care to ensure that a surrogate pair is correctly treated as a
1294single XPath character.</p>
1295
1296<note><p>It is possible in Unicode for there to be two strings that
1297should be treated as identical even though they consist of the
1298distinct sequences of Unicode abstract characters.  For example, some
1299accented characters may be represented in either a precomposed or
1300decomposed form.  Therefore, XPath expressions may return unexpected
1301results unless both the characters in the XPath expression and in the
1302XML document have been normalized into a canonical form.  See <bibref
1303ref="CHARMOD"/>.</p></note>
1304
1305</div2>
1306
1307<div2 id="exprlex">
1308<head>Lexical Structure</head>
1309
1310<p>When tokenizing, the longest possible token is always returned.</p>
1311
1312<p>For readability, whitespace may be used in expressions even though not
1313explicitly allowed by the grammar: <nt
1314def="NT-ExprWhitespace">ExprWhitespace</nt> may be freely added within
1315patterns before or after any <nt
1316def="NT-ExprToken">ExprToken</nt>.</p>
1317
1318<p>The following special tokenization rules must be applied in the
1319order specified to disambiguate the <nt
1320def="NT-ExprToken">ExprToken</nt> grammar:</p>
1321
1322<ulist>
1323
1324<item><p>If there is a preceding token and the preceding token is not
1325one of <code>@</code>, <code>::</code>, <code>(</code>,
1326<code>[</code>, <code>,</code> or an <nt
1327def="NT-Operator">Operator</nt>, then a <code>*</code> must be
1328recognized as a <nt def="NT-MultiplyOperator">MultiplyOperator</nt>
1329and an <xnt href="&XMLNames;#NT-NCName">NCName</xnt> must be
1330recognized as an <nt
1331def="NT-OperatorName">OperatorName</nt>.</p></item>
1332
1333<item><p>If the character following an <xnt
1334href="&XMLNames;#NT-NCName">NCName</xnt> (possibly after intervening
1335<nt def="NT-ExprWhitespace">ExprWhitespace</nt>) is <code>(</code>,
1336then the token must be recognized as a <nt
1337def="NT-NodeType">NodeType</nt> or a <nt
1338def="NT-FunctionName">FunctionName</nt>.</p></item>
1339
1340<item><p>If the two characters following an <xnt
1341href="&XMLNames;#NT-NCName">NCName</xnt> (possibly after intervening
1342<nt def="NT-ExprWhitespace">ExprWhitespace</nt>) are <code>::</code>,
1343then the token must be recognized as an <nt
1344def="NT-AxisName">AxisName</nt>.</p></item>
1345
1346<item><p>Otherwise, the token must not be recognized as a <nt
1347def="NT-MultiplyOperator">MultiplyOperator</nt>, an <nt
1348def="NT-OperatorName">OperatorName</nt>, a <nt
1349def="NT-NodeType">NodeType</nt>, a <nt
1350def="NT-FunctionName">FunctionName</nt>, or an <nt
1351def="NT-AxisName">AxisName</nt>.</p></item>
1352
1353</ulist>
1354
1355<scrap>
1356<head>Expression Lexical Structure</head>
1357<prodgroup pcw5="1" pcw2="8" pcw4="21">
1358<prod id="NT-ExprToken">
1359<lhs>ExprToken</lhs>
1360<rhs>'(' | ')' | '[' | ']' | '.' | '..' | '@' | ',' | '::'</rhs>
1361<rhs>| <nt def="NT-NameTest">NameTest</nt></rhs>
1362<rhs>| <nt def="NT-NodeType">NodeType</nt></rhs>
1363<rhs>| <nt def="NT-Operator">Operator</nt></rhs>
1364<rhs>| <nt def="NT-FunctionName">FunctionName</nt></rhs>
1365<rhs>| <nt def="NT-AxisName">AxisName</nt></rhs>
1366<rhs>| <nt def="NT-Literal">Literal</nt></rhs>
1367<rhs>| <nt def="NT-Number">Number</nt></rhs>
1368<rhs>| <nt def="NT-VariableReference">VariableReference</nt></rhs>
1369</prod>
1370<prod id="NT-Literal">
1371<lhs>Literal</lhs>
1372<rhs>'"' [^"]* '"'</rhs>
1373<rhs>| "'" [^']* "'"</rhs>
1374</prod>
1375<prod id="NT-Number">
1376<lhs>Number</lhs>
1377<rhs><nt def="NT-Digits">Digits</nt> ('.' <nt def="NT-Digits">Digits</nt>?)?</rhs>
1378<rhs>| '.' <nt def="NT-Digits">Digits</nt></rhs>
1379</prod>
1380<prod id="NT-Digits">
1381<lhs>Digits</lhs>
1382<rhs>[0-9]+</rhs>
1383</prod>
1384<prod id="NT-Operator">
1385<lhs>Operator</lhs>
1386<rhs><nt def="NT-OperatorName">OperatorName</nt></rhs>
1387<rhs>| <nt def="NT-MultiplyOperator">MultiplyOperator</nt></rhs>
1388<rhs>| '/' | '//' | '|' | '+' | '-' | '=' | '!=' | '&lt;' | '&lt;=' | '&gt;' | '&gt;='</rhs>
1389</prod>
1390<prod id="NT-OperatorName">
1391<lhs>OperatorName</lhs>
1392<rhs>'and' | 'or' | 'mod' | 'div'</rhs>
1393</prod>
1394<prod id="NT-MultiplyOperator">
1395<lhs>MultiplyOperator</lhs>
1396<rhs>'*'</rhs>
1397</prod>
1398<prod id="NT-FunctionName">
1399<lhs>FunctionName</lhs>
1400<rhs>
1401<xnt href="&XMLNames;#NT-QName">QName</xnt>
1402- <nt def="NT-NodeType">NodeType</nt>
1403</rhs>
1404</prod>
1405<prod id="NT-VariableReference">
1406<lhs>VariableReference</lhs>
1407<rhs>'$' <xnt href="&XMLNames;#NT-QName">QName</xnt></rhs>
1408</prod>
1409<prod id="NT-NameTest">
1410<lhs>NameTest</lhs>
1411<rhs>'*'</rhs>
1412<rhs>| <xnt href="&XMLNames;#NT-NCName">NCName</xnt> ':' '*'</rhs>
1413<rhs>| <xnt href="&XMLNames;#NT-QName">QName</xnt></rhs>
1414</prod>
1415<prod id="NT-NodeType">
1416<lhs>NodeType</lhs>
1417<rhs>'comment'</rhs>
1418<rhs>| 'text'</rhs>
1419<rhs>| 'processing-instruction'</rhs>
1420<rhs>| 'node'</rhs>
1421</prod>
1422<prod id="NT-ExprWhitespace">
1423<lhs>ExprWhitespace</lhs>
1424<rhs><xnt href="&XML;#NT-S">S</xnt></rhs>
1425</prod>
1426</prodgroup>
1427</scrap>
1428
1429</div2>
1430
1431</div1>
1432
1433<div1 id="corelib">
1434<head>Core Function Library</head>
1435
1436<p>This section describes functions that XPath implementations must
1437always include in the function library that is used to evaluate
1438expressions.</p>
1439
1440<p>Each function in the function library is specified using a function
1441prototype, which gives the return type, the name of the function, and
1442the type of the arguments.  If an argument type is followed by a
1443question mark, then the argument is optional; otherwise, the argument
1444is required.</p>
1445
1446<div2>
1447<head>Node Set Functions</head>
1448
1449<proto name="last" return-type="number"></proto>
1450
1451<p>The <function>last</function> function returns a number equal to
1452the <termref def="dt-context-size">context size</termref> from the
1453expression evaluation context.</p>
1454
1455<proto name="position" return-type="number"></proto>
1456
1457<p>The <function>position</function> function returns a number equal to
1458the <termref def="dt-context-position">context position</termref> from
1459the expression evaluation context.</p>
1460
1461<proto name="count" return-type="number"><arg type="node-set"/></proto>
1462
1463<p>The <function>count</function> function returns the number of nodes in the
1464argument node-set.</p>
1465
1466<proto name="id" return-type="node-set"><arg type="object"/></proto>
1467
1468<p>The <function>id</function> function selects elements by their
1469unique ID (see <specref ref="unique-id"/>).  When the argument to
1470<function>id</function> is of type node-set, then the result is the
1471union of the result of applying <function>id</function> to the
1472<termref def="dt-string-value">string-value</termref> of each of the
1473nodes in the argument node-set.  When the argument to
1474<function>id</function> is of any other type, the argument is
1475converted to a string as if by a call to the
1476<function>string</function> function; the string is split into a
1477whitespace-separated list of tokens (whitespace is any sequence of
1478characters matching the production <xnt href="&XML;#NT-S">S</xnt>);
1479the result is a node-set containing the elements in the same document
1480as the context node that have a unique ID equal to any of the tokens
1481in the list.</p>
1482
1483<ulist>
1484<item><p><code>id("foo")</code> selects the element with unique ID
1485<code>foo</code></p></item>
1486<item><p><code>id("foo")/child::para[position()=5]</code> selects
1487the fifth <code>para</code> child of the element with unique ID
1488<code>foo</code></p></item>
1489</ulist>
1490
1491<proto name="local-name" return-type="string"><arg occur="opt" type="node-set"/></proto>
1492
1493<p>The <function>local-name</function> function returns the local part
1494of the <termref def="dt-expanded-name">expanded-name</termref> of the
1495node in the argument node-set that is first in <termref
1496def="dt-document-order">document order</termref>. If the argument
1497node-set is empty or the first node has no <termref
1498def="dt-expanded-name">expanded-name</termref>, an empty string is
1499returned.  If the argument is omitted, it defaults to a node-set with
1500the context node as its only member.</p>
1501
1502<proto name="namespace-uri" return-type="string"><arg occur="opt"
1503type="node-set"/></proto>
1504
1505<p>The <function>namespace-uri</function> function returns the
1506namespace URI of the <termref
1507def="dt-expanded-name">expanded-name</termref> of the node in the
1508argument node-set that is first in <termref
1509def="dt-document-order">document order</termref>. If the argument
1510node-set is empty, the first node has no <termref
1511def="dt-expanded-name">expanded-name</termref>, or the namespace URI
1512of the <termref def="dt-expanded-name">expanded-name</termref> is
1513null, an empty string is returned.  If the argument is omitted, it
1514defaults to a node-set with the context node as its only member.</p>
1515
1516<note><p>The string returned by the
1517<function>namespace-uri</function> function will be empty except for
1518element nodes and attribute nodes.</p></note>
1519
1520<proto name="name" return-type="string"><arg occur="opt" type="node-set"/></proto>
1521
1522<p>The <function>name</function> function returns a string containing
1523a <xnt href="&XMLNames;#NT-QName">QName</xnt> representing the
1524<termref def="dt-expanded-name">expanded-name</termref> of the node in
1525the argument node-set that is first in <termref
1526def="dt-document-order">document order</termref>. The <xnt
1527href="&XMLNames;#NT-QName">QName</xnt> must represent the <termref
1528def="dt-expanded-name">expanded-name</termref> with respect to the
1529namespace declarations in effect on the node whose <termref
1530def="dt-expanded-name">expanded-name</termref> is being represented.
1531Typically, this will be the <xnt
1532href="&XMLNames;#NT-QName">QName</xnt> that occurred in the XML
1533source.  This need not be the case if there are namespace declarations
1534in effect on the node that associate multiple prefixes with the same
1535namespace.  However, an implementation may include information about
1536the original prefix in its representation of nodes; in this case, an
1537implementation can ensure that the returned string is always the same
1538as the <xnt href="&XMLNames;#NT-QName">QName</xnt> used in the XML
1539source. If the argument node-set is empty or the first node has no
1540<termref def="dt-expanded-name">expanded-name</termref>, an empty
1541string is returned.  If the argument it omitted, it defaults to a
1542node-set with the context node as its only member.</p>
1543
1544<note><p>The string returned by the <function>name</function> function
1545will be the same as the string returned by the
1546<function>local-name</function> function except for element nodes and
1547attribute nodes.</p></note>
1548
1549</div2>
1550
1551<div2>
1552<head>String Functions</head>
1553
1554<proto name="string" return-type="string"><arg occur="opt" type="object"/></proto>
1555
1556<p>The <function>string</function> function converts an object to a string
1557as follows:</p>
1558
1559<ulist>
1560
1561<item><p>A node-set is converted to a string by returning the <termref
1562def="dt-string-value">string-value</termref> of the node in the
1563node-set that is first in <termref def="dt-document-order">document
1564order</termref>.  If the node-set is empty, an empty string is
1565returned.</p></item>
1566
1567<item><p>A number is converted to a string as follows</p>
1568
1569<ulist>
1570
1571<item><p>NaN is converted to the string <code>NaN</code></p></item>
1572
1573<item><p>positive zero is converted to the string
1574<code>0</code></p></item>
1575
1576<item><p>negative zero is converted to the string
1577<code>0</code></p></item>
1578
1579<item><p>positive infinity is converted to the string
1580<code>Infinity</code></p></item>
1581
1582<item><p>negative infinity is converted to the string
1583<code>-Infinity</code></p></item>
1584
1585<item><p>if the number is an integer, the number is represented in
1586decimal form as a <nt def="NT-Number">Number</nt> with no decimal
1587point and no leading zeros, preceded by a minus sign (<code>-</code>)
1588if the number is negative</p></item>
1589
1590<item><p>otherwise, the number is represented in decimal form as a <nt
1591def="NT-Number">Number</nt> including a decimal point with at least
1592one digit before the decimal point and at least one digit after the
1593decimal point, preceded by a minus sign (<code>-</code>) if the number
1594is negative; there must be no leading zeros before the decimal point
1595apart possibly from the one required digit immediately before the
1596decimal point; beyond the one required digit after the decimal point
1597there must be as many, but only as many, more digits as are needed to
1598uniquely distinguish the number from all other IEEE 754 numeric
1599values.</p></item>
1600
1601</ulist>
1602
1603</item>
1604
1605<item><p>The boolean false value is converted to the string
1606<code>false</code>.  The boolean true value is converted to the
1607string <code>true</code>.</p></item>
1608
1609<item><p>An object of a type other than the four basic types is
1610converted to a string in a way that is dependent on that
1611type.</p></item>
1612
1613</ulist>
1614
1615<p>If the argument is omitted, it defaults to a node-set with the
1616context node as its only member.</p>
1617
1618<note><p>The <code>string</code> function is not intended for
1619converting numbers into strings for presentation to users.  The
1620<code>format-number</code> function and <code>xsl:number</code>
1621element in <bibref ref="XSLT"/> provide this
1622functionality.</p></note>
1623
1624<proto name="concat" return-type="string"><arg type="string"/><arg type="string"/><arg occur="rep" type="string"/></proto>
1625
1626<p>The <function>concat</function> function returns the concatenation of its
1627arguments.</p>
1628
1629<proto name="starts-with" return-type="boolean"><arg type="string"/><arg type="string"/></proto>
1630
1631<p>The <function>starts-with</function> function returns true if the
1632first argument string starts with the second argument string, and
1633otherwise returns false.</p>
1634
1635<proto name="contains" return-type="boolean"><arg type="string"/><arg type="string"/></proto>
1636
1637<p>The <function>contains</function> function returns true if the first
1638argument string contains the second argument string, and otherwise
1639returns false.</p>
1640
1641<proto name="substring-before" return-type="string"><arg type="string"/><arg type="string"/></proto>
1642
1643<p>The <function>substring-before</function> function returns the substring
1644of the first argument string that precedes the first occurrence of the
1645second argument string in the first argument string, or the empty
1646string if the first argument string does not contain the second
1647argument string.  For example,
1648<code>substring-before("1999/04/01","/")</code> returns
1649<code>1999</code>.</p>
1650
1651<proto name="substring-after" return-type="string"><arg type="string"/><arg type="string"/></proto>
1652
1653<p>The <function>substring-after</function> function returns the
1654substring of the first argument string that follows the first
1655occurrence of the second argument string in the first argument string,
1656or the empty string if the first argument string does not contain the
1657second argument string. For example,
1658<code>substring-after("1999/04/01","/")</code> returns
1659<code>04/01</code>, and
1660<code>substring-after("1999/04/01","19")</code> returns
1661<code>99/04/01</code>.</p>
1662
1663<proto name="substring" return-type="string">
1664<arg type="string"/>
1665<arg type="number"/>
1666<arg type="number" occur="opt"/>
1667</proto>
1668
1669<p>The <function>substring</function> function returns the substring of the
1670first argument starting at the position specified in the second
1671argument with length specified in the third argument. For example,
1672<code>substring("12345",2,3)</code> returns <code>"234"</code>.
1673If the third argument is not specified, it returns
1674the substring starting at the position specified in the second
1675argument and continuing to the end of the string. For example,
1676<code>substring("12345",2)</code> returns <code>"2345"</code>.</p>
1677
1678<p>More precisely, each character in the string (see <specref
1679ref="strings"/>) is considered to have a numeric position: the
1680position of the first character is 1, the position of the second
1681character is 2 and so on.</p>
1682
1683<note><p>This differs from Java and ECMAScript, in which the
1684<code>String.substring</code> method treats the position of the first
1685character as 0.</p></note>
1686
1687<p>The returned substring contains those
1688characters for which the position of the character is greater than or
1689equal to the rounded value of the second argument and, if the third
1690argument is specified, less than the sum of the rounded value of the
1691second argument and the rounded value of the third argument; the
1692comparisons and addition used for the above follow the standard IEEE
1693754 rules; rounding is done as if by a call to the
1694<function>round</function> function. The following examples illustrate
1695various unusual cases:</p>
1696
1697<ulist>
1698
1699<item><p><code>substring("12345", 1.5, 2.6)</code> returns
1700<code>"234"</code></p></item>
1701
1702<item><p><code>substring("12345", 0, 3)</code> returns
1703<code>"12"</code></p></item>
1704
1705<item><p><code>substring("12345", 0 div 0, 3)</code> returns
1706<code>""</code></p></item>
1707
1708<item><p><code>substring("12345", 1, 0 div 0)</code> returns
1709<code>""</code></p></item>
1710
1711<item><p><code>substring("12345", -42, 1 div 0)</code> returns
1712<code>"12345"</code></p></item>
1713
1714<item><p><code>substring("12345", -1 div 0, 1 div 0)</code> returns
1715<code>""</code></p></item>
1716
1717</ulist>
1718
1719<proto name="string-length" return-type="number">
1720<arg type="string" occur="opt"/>
1721</proto>
1722
1723<p>The <function>string-length</function> returns the number of
1724characters in the string (see <specref ref="strings"/>).  If the
1725argument is omitted, it defaults to the context node converted to a
1726string, in other words the <termref
1727def="dt-string-value">string-value</termref> of the context node.</p>
1728
1729<proto name="normalize-space" return-type="string"><arg occur="opt" type="string"/></proto>
1730
1731<p>The <function>normalize-space</function> function returns the argument
1732string with whitespace normalized by stripping leading and trailing
1733whitespace and replacing sequences of whitespace characters by a
1734single space.  Whitespace characters are the same as those allowed by the <xnt
1735href="&XML;#NT-S">S</xnt> production in XML.  If the argument is
1736omitted, it defaults to the context node converted to a string, in
1737other words the <termref def="dt-string-value">string-value</termref>
1738of the context node.</p>
1739
1740<proto name="translate" return-type="string"><arg type="string"/><arg type="string"/><arg type="string"/></proto>
1741
1742<p>The <function>translate</function> function returns the first
1743argument string with occurrences of characters in the second argument
1744string replaced by the character at the corresponding position in the
1745third argument string.  For example,
1746<code>translate("bar","abc","ABC")</code> returns the string
1747<code>BAr</code>.  If there is a character in the second argument
1748string with no character at a corresponding position in the third
1749argument string (because the second argument string is longer than the
1750third argument string), then occurrences of that character in the
1751first argument string are removed.  For example,
1752<code>translate("--aaa--","abc-","ABC")</code> returns
1753<code>"AAA"</code>. If a character occurs more than once in the second
1754argument string, then the first occurrence determines the replacement
1755character.  If the third argument string is longer than the second
1756argument string, then excess characters are ignored.</p>
1757
1758<note><p>The <function>translate</function> function is not a sufficient
1759solution for case conversion in all languages.  A future version of
1760XPath may provide additional functions for case conversion.</p></note>
1761
1762</div2>
1763
1764<div2>
1765<head>Boolean Functions</head>
1766
1767<proto name="boolean" return-type="boolean"><arg type="object"/></proto>
1768
1769<p>The <function>boolean</function> function converts its argument to a
1770boolean as follows:</p>
1771
1772<ulist>
1773
1774<item><p>a number is true if and only if it is neither positive or
1775negative zero nor NaN</p></item>
1776
1777<item><p>a node-set is true if and only if it is non-empty</p></item>
1778
1779<item><p>a string is true if and only if its length is non-zero</p></item>
1780
1781<item><p>an object of a type other than the four basic types is
1782converted to a boolean in a way that is dependent on that
1783type</p></item>
1784
1785</ulist>
1786
1787<proto name="not" return-type="boolean"><arg type="boolean"/></proto>
1788
1789<p>The <function>not</function> function returns true if its argument is
1790false, and false otherwise.</p>
1791
1792<proto name="true" return-type="boolean"></proto>
1793
1794<p>The <function>true</function> function returns true.</p>
1795
1796<proto name="false" return-type="boolean"></proto>
1797
1798<p>The <function>false</function> function returns false.</p>
1799
1800<proto name="lang" return-type="boolean"><arg type="string"/></proto>
1801
1802<p>The <function>lang</function> function returns true or false depending on
1803whether the language of the context node as specified by
1804<code>xml:lang</code> attributes is the same as or is a sublanguage of
1805the language specified by the argument string.  The language of the
1806context node is determined by the value of the <code>xml:lang</code>
1807attribute on the context node, or, if the context node has no
1808<code>xml:lang</code> attribute, by the value of the
1809<code>xml:lang</code> attribute on the nearest ancestor of the context
1810node that has an <code>xml:lang</code> attribute.  If there is no such
1811attribute, then <function>lang</function> returns false. If there is such an
1812attribute, then <function>lang</function> returns true if the attribute
1813value is equal to the argument ignoring case, or if there is some
1814suffix starting with <code>-</code> such that the attribute value is
1815equal to the argument ignoring that suffix of the attribute value and
1816ignoring case. For example, <code>lang("en")</code> would return true
1817if the context node is any of these five elements:</p>
1818
1819<eg><![CDATA[<para xml:lang="en"/>
1820<div xml:lang="en"><para/></div>
1821<para xml:lang="EN"/>
1822<para xml:lang="en-us"/>]]></eg>
1823</div2>
1824
1825<div2>
1826<head>Number Functions</head>
1827
1828<proto name="number" return-type="number"><arg occur="opt" type="object"/></proto>
1829
1830<p>The <function>number</function> function converts its argument to a
1831number as follows:</p>
1832
1833<ulist>
1834
1835<item><p>a string that consists of optional whitespace followed by an
1836optional minus sign followed by a <nt def="NT-Number">Number</nt>
1837followed by whitespace is converted to the IEEE 754 number that is
1838nearest (according to the IEEE 754 round-to-nearest rule)
1839to the mathematical value represented by the string; any other
1840string is converted to NaN</p></item>
1841
1842<item><p>boolean true is converted to 1; boolean false is converted to
18430</p></item>
1844
1845<item>
1846
1847<p>a node-set is first converted to a string as if by a call to the
1848<function>string</function> function and then converted in the same way as a
1849string argument</p>
1850
1851</item>
1852
1853<item><p>an object of a type other than the four basic types is
1854converted to a number in a way that is dependent on that
1855type</p></item>
1856
1857</ulist>
1858
1859<p>If the argument is omitted, it defaults to a node-set with the
1860context node as its only member.</p>
1861
1862<note><p>The <function>number</function> function should not be used
1863for conversion of numeric data occurring in an element in an XML
1864document unless the element is of a type that represents numeric data
1865in a language-neutral format (which would typically be transformed
1866into a language-specific format for presentation to a user). In
1867addition, the <function>number</function> function cannot be used
1868unless the language-neutral format used by the element is consistent
1869with the XPath syntax for a <nt
1870def="NT-Number">Number</nt>.</p></note>
1871
1872<proto name="sum" return-type="number"><arg type="node-set"/></proto>
1873
1874<p>The <function>sum</function> function returns the sum, for each
1875node in the argument node-set, of the result of converting the
1876<termref def="dt-string-value">string-value</termref>s of the node to
1877a number.</p>
1878
1879<proto name="floor" return-type="number"><arg type="number"/></proto>
1880
1881<p>The <function>floor</function> function returns the largest (closest to
1882positive infinity) number that is not greater than the argument and
1883that is an integer.</p>
1884
1885<proto name="ceiling" return-type="number"><arg type="number"/></proto>
1886
1887<p>The <function>ceiling</function> function returns the smallest (closest
1888to negative infinity) number that is not less than the argument and
1889that is an integer.</p>
1890
1891<proto name="round" return-type="number"><arg type="number"/></proto>
1892
1893<p>The <function>round</function> function returns the number that is
1894closest to the argument and that is an integer.  If there are two such
1895numbers, then the one that is closest to positive infinity is
1896returned. If the argument is NaN, then NaN is returned. If the
1897argument is positive infinity, then positive infinity is returned.  If
1898the argument is negative infinity, then negative infinity is
1899returned. If the argument is positive zero, then positive zero is
1900returned.  If the argument is negative zero, then negative zero is
1901returned.  If the argument is less than zero, but greater than or
1902equal to -0.5, then negative zero is returned.</p>
1903
1904<note><p>For these last two cases, the result of calling the
1905<function>round</function> function is not the same as the result of
1906adding 0.5 and then calling the <function>floor</function>
1907function.</p></note>
1908
1909</div2>
1910
1911
1912</div1>
1913
1914
1915<div1 id="data-model">
1916<head>Data Model</head>
1917
1918<p>XPath operates on an XML document as a tree. This section describes
1919how XPath models an XML document as a tree.  This model is conceptual
1920only and does not mandate any particular implementation.  The
1921relationship of this model to the XML Information Set <bibref
1922ref="XINFO"/> is described in <specref ref="infoset"/>.</p>
1923
1924<p>XML documents operated on by XPath must conform to the XML
1925Namespaces Recommendation <bibref ref="XMLNAMES"/>.</p>
1926
1927<p>The tree contains nodes.  There are seven types of node:</p>
1928
1929<ulist>
1930
1931<item><p>root nodes</p></item>
1932
1933<item><p>element nodes</p></item>
1934
1935<item><p>text nodes</p></item>
1936
1937<item><p>attribute nodes</p></item>
1938
1939<item><p>namespace nodes</p></item>
1940
1941<item><p>processing instruction nodes</p></item>
1942
1943<item><p>comment nodes</p></item>
1944
1945</ulist>
1946
1947<p><termdef term="String Value" id="dt-string-value">For every type of
1948node, there is a way of determining a <term>string-value</term> for a
1949node of that type.  For some types of node, the string-value is part
1950of the node; for other types of node, the string-value is computed
1951from the string-value of descendant nodes.</termdef></p>
1952
1953<note><p>For element nodes and root nodes, the string-value of a node
1954is not the same as the string returned by the DOM
1955<code>nodeValue</code> method (see <bibref ref="DOM"/>).</p></note>
1956
1957<p><termdef term="Expanded Name" id="dt-expanded-name">Some types of
1958node also have an <term>expanded-name</term>, which is a pair
1959consisting of a local part and a namespace URI. The local part is a
1960string.  The namespace URI is either null or a string.  The namespace
1961URI specified in the XML document can be a URI reference as defined in
1962<bibref ref="RFC2396"/>; this means it can have a fragment identifier
1963and can be relative.  A relative URI should be resolved into an
1964absolute URI during namespace processing: the namespace URIs of
1965<termref def="dt-expanded-name">expanded-name</termref>s of nodes in
1966the data model should be absolute.</termdef> Two <termref
1967def="dt-expanded-name">expanded-name</termref>s are equal if they have
1968the same local part, and either both have a null namespace URI or both
1969have non-null namespace URIs that are equal.</p>
1970
1971<p><termdef id="dt-document-order" term="Document Order">There is an
1972ordering, <term>document order</term>, defined on all the nodes in the
1973document corresponding to the order in which the first character of
1974the XML representation of each node occurs in the XML representation
1975of the document after expansion of general entities.  Thus, the root
1976node will be the first node. Element nodes occur before their
1977children. Thus, document order orders element nodes in order of the
1978occurrence of their start-tag in the XML (after expansion of
1979entities). The attribute nodes and namespace nodes of an element occur
1980before the children of the element.  The namespace nodes are defined
1981to occur before the attribute nodes. The relative order of namespace
1982nodes is implementation-dependent.  The relative order of attribute
1983nodes is implementation-dependent.</termdef> <termdef
1984id="dt-reverse-document-order" term="Reverse Document
1985Order"><term>Reverse document order</term> is the reverse of <termref
1986def="dt-document-order">document order</termref>.</termdef></p>
1987
1988<p>Root nodes and element nodes have an ordered list of child nodes.
1989Nodes never share children: if one node is not the same node as
1990another node, then none of the children of the one node will be the
1991same node as any of the children of another node.  <termdef
1992id="dt-parent" term="Parent">Every node other than the root node has
1993exactly one <term>parent</term>, which is either an element node or
1994the root node.</termdef> A root node or an element node is the parent
1995of each of its child nodes. <termdef id="dt-descendants"
1996term="Descendants">The <term>descendants</term> of a node are the
1997children of the node and the descendants of the children of the
1998node.</termdef></p>
1999
2000<div2 id="root-node">
2001<head>Root Node</head>
2002
2003<p>The root node is the root of the tree.  A root node does not occur
2004except as the root of the tree.  The element node for the document
2005element is a child of the root node.  The root node also has as
2006children processing instruction and comment nodes for processing
2007instructions and comments that occur in the prolog and after the end
2008of the document element.</p>
2009
2010<p>The <termref def="dt-string-value">string-value</termref> of the
2011root node is the concatenation of the <termref
2012def="dt-string-value">string-value</termref>s of all text node
2013<termref def="dt-descendants">descendants</termref> of the root
2014node in document order.</p>
2015
2016<p>The root node does not have an <termref
2017def="dt-expanded-name">expanded-name</termref>.</p>
2018
2019</div2>
2020
2021<div2 id="element-nodes">
2022<head>Element Nodes</head>
2023
2024<p>There is an element node for every element in the document.  An
2025element node has an <termref
2026def="dt-expanded-name">expanded-name</termref> computed by expanding
2027the <xnt href="&XMLNames;#NT-QName">QName</xnt> of the element
2028specified in the tag in accordance with the XML Namespaces
2029Recommendation <bibref ref="XMLNAMES"/>.  The namespace URI of the
2030element's <termref def="dt-expanded-name">expanded-name</termref> will
2031be null if the <xnt href="&XMLNames;#NT-QName">QName</xnt> has no
2032prefix and there is no applicable default namespace.</p>
2033
2034<note><p>In the notation of Appendix A.3 of <bibref ref="XMLNAMES"/>,
2035the local part of the expanded-name corresponds to the
2036<code>type</code> attribute of the <code>ExpEType</code> element; the
2037namespace URI of the expanded-name corresponds to the <code>ns</code>
2038attribute of the <code>ExpEType</code> element, and is null if the
2039<code>ns</code> attribute of the <code>ExpEType</code> element is
2040omitted.</p></note>
2041
2042<p>The children of an element node are the element nodes, comment
2043nodes, processing instruction nodes and text nodes for its content.
2044Entity references to both internal and external entities are expanded.
2045Character references are resolved.</p>
2046
2047<p>The <termref def="dt-string-value">string-value</termref> of an
2048element node is the concatenation of the <termref
2049def="dt-string-value">string-value</termref>s of all text node
2050<termref def="dt-descendants">descendants</termref> of the element
2051node in document order.</p>
2052
2053<div3 id="unique-id">
2054<head>Unique IDs</head>
2055
2056<p>An element node may have a unique identifier (ID).  This is the
2057value of the attribute that is declared in the DTD as type
2058<code>ID</code>.  No two elements in a document may have the same
2059unique ID.  If an XML processor reports two elements in a document as
2060having the same unique ID (which is possible only if the document is
2061invalid) then the second element in document order must be treated as
2062not having a unique ID.</p>
2063
2064<note><p>If a document does not have a DTD, then no element in the
2065document will have a unique ID.</p></note>
2066
2067</div3>
2068
2069</div2>
2070
2071<div2 id="attribute-nodes">
2072<head>Attribute Nodes</head>
2073
2074<p>Each element node has an associated set of attribute nodes; the
2075element is the <termref def="dt-parent">parent</termref> of each of
2076these attribute nodes; however, an attribute node is not a child of
2077its parent element.</p>
2078
2079<note><p>This is different from the DOM, which does not treat the
2080element bearing an attribute as the parent of the attribute (see
2081<bibref ref="DOM"/>).</p></note>
2082
2083<p>Elements never share attribute nodes: if one element node is not
2084the same node as another element node, then none of the attribute
2085nodes of the one element node will be the same node as the attribute
2086nodes of another element node.</p>
2087
2088<note><p>The <code>=</code> operator tests whether two nodes have the
2089same value, <emph>not</emph> whether they are the same node.  Thus
2090attributes of two different elements may compare as equal using
2091<code>=</code>, even though they are not the same node.</p></note>
2092
2093<p>A defaulted attribute is treated the same as a specified attribute.
2094If an attribute was declared for the element type in the DTD, but the
2095default was declared as <code>#IMPLIED</code>, and the attribute was
2096not specified on the element, then the element's attribute set does
2097not contain a node for the attribute.</p>
2098
2099<p>Some attributes, such as <code>xml:lang</code> and
2100<code>xml:space</code>, have the semantics that they apply to all
2101elements that are descendants of the element bearing the attribute,
2102unless overridden with an instance of the same attribute on another
2103descendant element.  However, this does not affect where attribute
2104nodes appear in the tree: an element has attribute nodes only for
2105attributes that were explicitly specified in the start-tag or
2106empty-element tag of that element or that were explicitly declared in
2107the DTD with a default value.</p>
2108
2109<p>An attribute node has an <termref
2110def="dt-expanded-name">expanded-name</termref> and a <termref
2111def="dt-string-value">string-value</termref>.  The <termref
2112def="dt-expanded-name">expanded-name</termref> is computed by
2113expanding the <xnt href="&XMLNames;#NT-QName">QName</xnt> specified in
2114the tag in the XML document in accordance with the XML Namespaces
2115Recommendation <bibref ref="XMLNAMES"/>.  The namespace URI of the
2116attribute's name will be null if the <xnt
2117href="&XMLNames;#NT-QName">QName</xnt> of the attribute does not have
2118a prefix.</p>
2119
2120<note><p>In the notation of Appendix A.3 of <bibref ref="XMLNAMES"/>,
2121the local part of the expanded-name corresponds to the
2122<code>name</code> attribute of the <code>ExpAName</code> element; the
2123namespace URI of the expanded-name corresponds to the <code>ns</code>
2124attribute of the <code>ExpAName</code> element, and is null if the
2125<code>ns</code> attribute of the <code>ExpAName</code> element is
2126omitted.</p></note>
2127
2128<p>An attribute node has a <termref
2129def="dt-string-value">string-value</termref>.  The <termref
2130def="dt-string-value">string-value</termref> is the normalized value
2131as specified by the XML Recommendation <bibref ref="XML"/>.  An
2132attribute whose normalized value is a zero-length string is not
2133treated specially: it results in an attribute node whose <termref
2134def="dt-string-value">string-value</termref> is a zero-length
2135string.</p>
2136
2137<note><p>It is possible for default attributes to be declared in an
2138external DTD or an external parameter entity.  The XML Recommendation
2139does not require an XML processor to read an external DTD or an
2140external parameter unless it is validating. A stylesheet or other facility that assumes
2141that the XPath tree contains default attribute values declared in an
2142external DTD or parameter entity may not work with some non-validating
2143XML processors.</p></note>
2144
2145<p>There are no attribute nodes corresponding to attributes that
2146declare namespaces (see <bibref ref="XMLNAMES"/>).</p>
2147
2148</div2>
2149
2150<div2 id="namespace-nodes">
2151<head>Namespace Nodes</head>
2152
2153<p>Each element has an associated set of namespace nodes, one for each
2154distinct namespace prefix that is in scope for the element (including
2155the <code>xml</code> prefix, which is implicitly declared by the XML
2156Namespaces Recommendation <bibref ref="XMLNAMES"/>) and one for
2157the default namespace if one is in scope for the element.  The element
2158is the <termref def="dt-parent">parent</termref> of each of these
2159namespace nodes; however, a namespace node is not a child of
2160its parent element.  Elements never share namespace nodes: if one element
2161node is not the same node as another element node, then none of the
2162namespace nodes of the one element node will be the same node as the
2163namespace nodes of another element node. This means that an element
2164will have a namespace node:</p>
2165
2166<ulist>
2167
2168<item><p>for every attribute on the element whose name starts with
2169<code>xmlns:</code>;</p></item>
2170
2171<item><p>for every attribute on an ancestor element whose name starts
2172<code>xmlns:</code> unless the element itself or a nearer ancestor
2173redeclares the prefix;</p></item>
2174
2175<item>
2176
2177<p>for an <code>xmlns</code> attribute, if the element or some
2178ancestor has an <code>xmlns</code> attribute, and the value of the
2179<code>xmlns</code> attribute for the nearest such element is
2180non-empty</p>
2181
2182<note><p>An attribute <code>xmlns=""</code> <quote>undeclares</quote>
2183the default namespace (see <bibref ref="XMLNAMES"/>).</p></note>
2184
2185</item>
2186
2187</ulist>
2188
2189<p>A namespace node has an <termref
2190def="dt-expanded-name">expanded-name</termref>: the local part is
2191the namespace prefix (this is empty if the namespace node is for the
2192default namespace); the namespace URI is always null.</p>
2193
2194<p>The <termref def="dt-string-value">string-value</termref> of a
2195namespace node is the namespace URI that is being bound to the
2196namespace prefix; if it is relative, it must be resolved just like a
2197namespace URI in an <termref
2198def="dt-expanded-name">expanded-name</termref>.</p>
2199
2200</div2>
2201
2202
2203<div2>
2204<head>Processing Instruction Nodes</head>
2205
2206<p>There is a processing instruction node for every processing
2207instruction, except for any processing instruction that occurs within
2208the document type declaration.</p>
2209
2210<p>A processing instruction has an <termref
2211def="dt-expanded-name">expanded-name</termref>: the local part is
2212the processing instruction's target; the namespace URI is null.  The
2213<termref def="dt-string-value">string-value</termref> of a processing
2214instruction node is the part of the processing instruction following
2215the target and any whitespace.  It does not include the terminating
2216<code>?&gt;</code>.</p>
2217
2218<note><p>The XML declaration is not a processing instruction.
2219Therefore, there is no processing instruction node corresponding to the
2220XML declaration.</p></note>
2221
2222</div2>
2223
2224<div2>
2225<head>Comment Nodes</head>
2226
2227<p>There is a comment node for every comment, except for any comment that
2228occurs within the document type declaration.</p>
2229
2230<p>The <termref def="dt-string-value">string-value</termref> of
2231comment is the content of the comment not including the opening
2232<code>&lt;!--</code> or the closing <code>--&gt;</code>.</p>
2233
2234<p>A comment node does not have an <termref
2235def="dt-expanded-name">expanded-name</termref>.</p>
2236
2237</div2>
2238
2239<div2>
2240<head>Text Nodes</head>
2241
2242<p>Character data is grouped into text nodes.  As much character data
2243as possible is grouped into each text node: a text node never has an
2244immediately following or preceding sibling that is a text node.  The
2245<termref def="dt-string-value">string-value</termref> of a text node
2246is the character data.  A text node always has at least one character
2247of data.</p>
2248
2249<p>Each character within a CDATA section is treated as character data.
2250Thus, <code>&lt;![CDATA[&lt;]]&gt;</code> in the source document will
2251treated the same as <code>&amp;lt;</code>.  Both will result in a
2252single <code>&lt;</code> character in a text node in the tree.  Thus, a
2253CDATA section is treated as if the <code>&lt;![CDATA[</code> and
2254<code>]]&gt;</code> were removed and every occurrence of
2255<code>&lt;</code> and <code>&amp;</code> were replaced by
2256<code>&amp;lt;</code> and <code>&amp;amp;</code> respectively.</p>
2257
2258<note><p>When a text node that contains a <code>&lt;</code> character
2259is written out as XML, the <code>&lt;</code> character must be escaped
2260by, for example, using <code>&amp;lt;</code>, or including it in a
2261CDATA section.</p></note>
2262
2263<p>Characters inside comments, processing instructions and attribute
2264values do not produce text nodes. Line-endings in external entities
2265are normalized to #xA as specified in the XML Recommendation <bibref
2266ref="XML"/>.</p>
2267
2268<p>A text node does not have an <termref
2269def="dt-expanded-name">expanded-name</termref>.</p>
2270
2271</div2>
2272
2273</div1>
2274
2275<div1>
2276<head>Conformance</head>
2277
2278<p>XPath is intended primarily as a component that can be used by
2279other specifications. Therefore, XPath relies on specifications that
2280use XPath (such as <bibref ref="XPTR"/> and <bibref ref="XSLT"/>) to
2281specify criteria for conformance of implementations of XPath and does
2282not define any conformance criteria for independent implementations of
2283XPath.</p>
2284
2285</div1>
2286
2287</body>
2288
2289<back>
2290<div1>
2291<head>References</head>
2292<div2>
2293<head>Normative References</head>
2294
2295<blist>
2296
2297<bibl id="IEEE754" key="IEEE 754">Institute of Electrical and
2298Electronics Engineers. <emph>IEEE Standard for Binary Floating-Point
2299Arithmetic</emph>. ANSI/IEEE Std 754-1985.</bibl>
2300
2301<bibl id="RFC2396" key="RFC2396">T. Berners-Lee, R. Fielding, and
2302L. Masinter.  <emph>Uniform Resource Identifiers (URI): Generic
2303Syntax</emph>. IETF RFC 2396. See <loc
2304href="http://www.ietf.org/rfc/rfc2396.txt">http://www.ietf.org/rfc/rfc2396.txt</loc>.</bibl>
2305
2306<bibl id="XML" key="XML">World Wide Web Consortium. <emph>Extensible
2307Markup Language (XML) 1.0.</emph> W3C Recommendation. See <loc
2308href="http://www.w3.org/TR/1998/REC-xml-19980210">http://www.w3.org/TR/1998/REC-xml-19980210</loc></bibl>
2309
2310<bibl id="XMLNAMES" key="XML Names">World Wide Web
2311Consortium. <emph>Namespaces in XML.</emph> W3C Recommendation. See
2312<loc
2313href="http://www.w3.org/TR/REC-xml-names">http://www.w3.org/TR/REC-xml-names</loc></bibl>
2314
2315</blist>
2316</div2>
2317<div2>
2318<head>Other References</head>
2319
2320<blist>
2321
2322<bibl id="CHARMOD" key="Character Model">World Wide Web Consortium.
2323<emph>Character Model for the World Wide Web.</emph> W3C Working
2324Draft. See <loc
2325href="http://www.w3.org/TR/WD-charmod">http://www.w3.org/TR/WD-charmod</loc></bibl>
2326
2327<bibl id="DOM" key="DOM">World Wide Web Consortium.  <emph>Document
2328Object Model (DOM) Level 1 Specification.</emph> W3C
2329Recommendation. See <loc href="http://www.w3.org/TR/REC-DOM-Level-1"
2330>http://www.w3.org/TR/REC-DOM-Level-1</loc></bibl>
2331
2332<bibl id="JLS" key="JLS">J. Gosling, B. Joy, and G. Steele.  <emph>The
2333Java Language Specification</emph>. See <loc
2334href="http://java.sun.com/docs/books/jls/index.html"
2335>http://java.sun.com/docs/books/jls/index.html</loc>.</bibl>
2336
2337<bibl id="ISO10646" key="ISO/IEC 10646">ISO (International
2338Organization for Standardization).  <emph>ISO/IEC 10646-1:1993,
2339Information technology -- Universal Multiple-Octet Coded Character Set
2340(UCS) -- Part 1: Architecture and Basic Multilingual Plane</emph>.
2341International Standard. See <loc
2342href="http://www.iso.ch/cate/d18741.html">http://www.iso.ch/cate/d18741.html</loc>.</bibl>
2343
2344<bibl id="TEI" key="TEI">C.M. Sperberg-McQueen, L. Burnard
2345<emph>Guidelines for Electronic Text Encoding and
2346Interchange</emph>. See <loc href="http://etext.virginia.edu/TEI.html"
2347>http://etext.virginia.edu/TEI.html</loc>.</bibl>
2348
2349<bibl id="UNICODE" key="Unicode">Unicode Consortium. <emph>The Unicode
2350Standard</emph>.  See <loc
2351href="http://www.unicode.org/unicode/standard/standard.html"
2352>http://www.unicode.org/unicode/standard/standard.html</loc>.</bibl>
2353
2354<bibl id="XINFO" key="XML Infoset">World Wide Web
2355Consortium. <emph>XML Information Set.</emph> W3C Working Draft. See
2356<loc
2357href="http://www.w3.org/TR/xml-infoset">http://www.w3.org/TR/xml-infoset</loc>
2358</bibl>
2359
2360<bibl id="XPTR" key="XPointer">World Wide Web Consortium. <emph>XML
2361Pointer Language (XPointer).</emph> W3C Working Draft. See <loc
2362href="http://www.w3.org/TR/WD-xptr"
2363>http://www.w3.org/TR/WD-xptr</loc></bibl>
2364
2365<bibl id="XQL" key="XQL">J. Robie, J. Lapp, D. Schach.
2366<emph>XML Query Language (XQL)</emph>. See
2367<loc href="http://www.w3.org/TandS/QL/QL98/pp/xql.html"
2368>http://www.w3.org/TandS/QL/QL98/pp/xql.html</loc></bibl>
2369
2370<bibl id="XSLT" key="XSLT">World Wide Web Consortium.  <emph>XSL
2371Transformations (XSLT).</emph> W3C Recommendation.  See <loc
2372href="http://www.w3.org/TR/xslt"
2373>http://www.w3.org/TR/xslt</loc></bibl>
2374
2375</blist>
2376
2377</div2>
2378</div1>
2379
2380<inform-div1 id="infoset">
2381<head>XML Information Set Mapping</head>
2382
2383<p>The nodes in the XPath data model can be derived from the
2384information items provided by the XML Information Set <bibref
2385ref="XINFO"/> as follows:</p>
2386
2387<note><p>A new version of the XML Information Set Working Draft, which
2388will replace the May 17 version, was close to completion at the time
2389when the preparation of this version of XPath was completed and was
2390expected to be released at the same time or shortly after the release
2391of this version of XPath.  The mapping is given for this new version
2392of the XML Information Set Working Draft. If the new version of the
2393XML Information Set Working has not yet been released, W3C members may
2394consult the internal Working Group version <loc
2395href="http://www.w3.org/XML/Group/1999/09/WD-xml-infoset-19990915.html">
2396http://www.w3.org/XML/Group/1999/09/WD-xml-infoset-19990915.html</loc>
2397(<loc href="http://cgi.w3.org/MemberAccess/">members
2398only</loc>).</p></note>
2399
2400<ulist>
2401
2402<item><p>The root node comes from the document information item.  The
2403children of the root node come from the <emph
2404role="infoset-property">children</emph> and <emph
2405role="infoset-property">children - comments</emph>
2406properties.</p></item>
2407
2408<item><p>An element node comes from an element information item.  The
2409children of an element node come from the <emph
2410role="infoset-property">children</emph> and <emph
2411role="infoset-property">children - comments</emph> properties. The
2412attributes of an element node come from the <emph
2413role="infoset-property">attributes</emph> property.  The namespaces
2414of an element node come from the <emph
2415role="infoset-property">in-scope namespaces</emph> property.  The
2416local part of the <termref
2417def="dt-expanded-name">expanded-name</termref> of the element node
2418comes from the <emph role="infoset-property">local name</emph>
2419property.  The namespace URI of the <termref
2420def="dt-expanded-name">expanded-name</termref> of the element node
2421comes from the <emph role="infoset-property">namespace URI</emph>
2422property. The unique ID of the element node comes from the <emph
2423role="infoset-property">children</emph> property of the attribute
2424information item in the <emph
2425role="infoset-property">attributes</emph> property that has an <emph
2426role="infoset-property">attribute type</emph> property equal to
2427<code>ID</code>.</p></item>
2428
2429<item><p>An attribute node comes from an attribute information item.
2430The local part of the <termref
2431def="dt-expanded-name">expanded-name</termref> of the attribute node
2432comes from the <emph role="infoset-property">local name</emph>
2433property.  The namespace URI of the <termref
2434def="dt-expanded-name">expanded-name</termref> of the attribute node
2435comes from the <emph role="infoset-property">namespace URI</emph>
2436property. The <termref def="dt-string-value">string-value</termref> of
2437the node comes from concatenating the <emph
2438role="infoset-property">character code</emph> property of each member
2439of the <emph role="infoset-property">children</emph>
2440property.</p></item>
2441
2442<item><p>A text node comes from a sequence of one or more consecutive
2443character information items.  The <termref
2444def="dt-string-value">string-value</termref> of the node comes from
2445concatenating the <emph role="infoset-property">character code</emph>
2446property of each of the character information items.</p></item>
2447
2448<item><p>A processing instruction node comes from a processing
2449instruction information item.  The local part of the <termref
2450def="dt-expanded-name">expanded-name</termref> of the node comes from
2451the <emph role="infoset-property">target</emph> property. (The
2452namespace URI part of the <termref
2453def="dt-expanded-name">expanded-name</termref> of the node is null.)
2454The <termref def="dt-string-value">string-value</termref> of the node
2455comes from the <emph role="infoset-property">content</emph>
2456property. There are no processing instruction nodes for processing
2457instruction items that are children of document type declaration
2458information item.</p></item>
2459
2460<item><p>A comment node comes from a comment information item.  The
2461<termref def="dt-string-value">string-value</termref> of the node
2462comes from the <emph role="infoset-property">content</emph> property.
2463There are no comment nodes for comment information items that are
2464children of document type declaration information item.</p></item>
2465
2466<item><p>A namespace node comes from a namespace declaration
2467information item.  The local part of the <termref
2468def="dt-expanded-name">expanded-name</termref> of the node comes from
2469the <emph role="infoset-property">prefix</emph> property.  (The
2470namespace URI part of the <termref
2471def="dt-expanded-name">expanded-name</termref> of the node is null.)
2472The <termref def="dt-string-value">string-value</termref> of the node
2473comes from the <emph role="infoset-property">namespace URI</emph>
2474property.</p></item>
2475
2476</ulist>
2477
2478</inform-div1>
2479
2480</back>
2481</spec>
2482