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

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