home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 October / INTERNET108.ISO / pc / software / windows / building / xmlspy / xmlspyentcomplete5.exe / Data1.cab / _B8AC86505F0641D8BE7D55AF960BC781 < prev    next >
Encoding:
Extensible Markup Language  |  2002-10-01  |  102.3 KB  |  2,473 lines

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