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