<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="xmlspec.xsl"?>
<!DOCTYPE spec PUBLIC "-//W3C//DTD Specification V2.1//EN"
 "xmlspec.dtd" [
<!ENTITY monthno "12">
<!ENTITY month "December">
<!ENTITY day "19">
<!ENTITY year "2002">
<!ENTITY trpath "http://www.w3.org/TR/">
<!ENTITY W3C-path "&trpath;&year;/">
<!ENTITY doctype "WD">
<!ENTITY isodate "&year;&monthno;&day;">
<!ENTITY schemename "xpointer">
<!ENTITY shortname "xptr-&schemename;">
<!ENTITY dirname "&W3C-path;&doctype;-&shortname;-&isodate;/">
<!ENTITY scheme-phrase "<code>&schemename;()</code> scheme">
<!ENTITY abstract 'The XPointer <code>&schemename;()</code>
 scheme is intended to be used with the XPointer Framework
 <bibref ref="xptr-framework"/> to provide a high level of
 functionality for addressing portions of XML documents.
 It is based on XPath <bibref ref="XPath"/>, and adds the
 ability to address strings, points, and ranges in accordance
 with definitions provided in DOM 2: Range.<bibref ref="dom2"/>'>
<!ENTITY media-types "one of <code>text/xml</code>, 
<code>application/xml</code>, 
<code>text/xml-external-parsed-entity</code>, or <code>application/xml-external-parsed-entity</code>">
<!ENTITY XLink "http://www.w3.org/TR/xlink">
<!ENTITY XML "http://www.w3.org/TR/REC-xml">
<!ENTITY XMLNames "http://www.w3.org/TR/REC-xml-names">
<!ENTITY XPath "http://www.w3.org/TR/xpath">
<!ENTITY Dom2Range "http://www.w3.org/TR/DOM-Level-2-Traversal-Range/">
<!ENTITY Issues "http://www.w3.org/XML/Group/1999/07/LinkingIssueList">
<!ENTITY RFC2396 "http://www.rfc-editor.org/rfc/rfc2396.txt">
<!ENTITY xptr-framework-file "http://www.w3.org/TR/2002/PR-xptr-framework-20021113/">
<!ENTITY xptr-element-file "http://www.w3.org/TR/2002/PR-xptr-element-20021113/">
<!ENTITY xptr-xmlns-file "http://www.w3.org/TR/2002/PR-xptr-xmlns-20021113/">
<!ENTITY nbsp "&#160;">

]>
<spec w3c-doctype="wd">
<header>
<title>XPointer &schemename;() Scheme</title>
<w3c-designation>&doctype;-&shortname;-&isodate;</w3c-designation>
<w3c-doctype>W3C Working Draft</w3c-doctype>
<pubdate><day>&day;</day><month>&month;</month><year>&year;</year></pubdate>
<publoc><loc href="&dirname;">&dirname;</loc></publoc>
<altlocs><loc href="&dirname;&schemename;.xml">XML</loc>
<loc href="&dirname;xmlspec.dtd">(its DTD)</loc>
<loc href="&dirname;xmlspec.xsl">(an XSL stylesheet for it)</loc>
</altlocs>
<latestloc><loc href="&trpath;&shortname;/">&trpath;&shortname;/</loc></latestloc>
<prevlocs><loc href="http://www.w3.org/TR/2002/WD-xptr-xpointer-20020710/">http://www.w3.org/TR/2002/WD-xptr-xpointer-20020710/</loc></prevlocs>
<authlist>
<author>
 <name>Steven DeRose</name>
 <affiliation>Brown University Scholarly Technology Group, Bible Technologies Group</affiliation>
 <email href="mailto:sderose@acm.org">sderose@acm.org</email>
</author>
<author>
 <name>Eve Maler</name>
 <affiliation>Sun Microsystems</affiliation>
 <email href="mailto:eve.maler@sun.com">eve.maler@sun.com</email>
</author>
<author>
 <name>Ron Daniel Jr.</name>
 <affiliation>Taxonomy Strategies</affiliation>
 <email href="mailto:rdaniel@taxonomystrategies.com">rdaniel@taxonomystrategies.com</email>
</author>
</authlist>
<abstract>
<p diff="chg">&abstract;</p>
</abstract>
<status>
<p>This is a W3C Working Draft for review by W3C members and other interested parties. It is a draft document and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use W3C Working Drafts as reference material or to cite them as other than <quote>work in progress</quote>.  Comments on this document should be sent to the public mailing list <loc
href="mailto:www-xml-linking-comments@w3.org">www-xml-linking-comments@w3.org</loc>
(<loc href="http://lists.w3.org/Archives/Public/www-xml-linking-comments/">archive</loc>).
</p>
 <p>This document has been produced by the <loc href="http://www.w3.org/XML/Linking">W3C XML Linking Working
Group</loc> as part of the <loc href="http://www.w3.org/XML/Activity">XML
Activity</loc>.  The goals of this work are set out in the <loc href="http://www.w3.org/TR/NOTE-xptr-req">XPointer
Requirements</loc> document.</p>
 <p>There are patent disclosures and license commitments associated with
this working draft, which may be found on the <loc href="http://www.w3.org/2002/06/xptr_IPR_summary.html">XPointer IPR Statement</loc> page in conformance with <loc href="http://www.w3.org/Consortium/Process-20010719/#ipr">W3C policy</loc>.</p>
<p diff="chg">This specification is one of four into which the prior XPointer specification has been divided. This version addresses comments received on the
<loc href="http://www.w3.org/TR/2001/CR-xptr-20010911/">XPointer
Candidate Recommendation</loc> which were relevant to the <code>xpointer()</code> scheme it defines. Except for responding to the relevant Last Call comments, and incorporating non-substantive editorial improvements, this documents is substantially identical to that part of the Last Call XPointer specification which is not covered by 
<bibref ref="xptr-framework"/>, 
<bibref ref="xptr-xmlns"/>, and 
<bibref ref="xptr-element"/>, </p>
 <p>A list of current W3C Recommendations and other technical documents can be
found at <loc href="http://www.w3.org/TR/">http://www.w3.org/TR/</loc></p>
</status>
<langusage>
<language id="en">English</language>
<language id="ebnf">Extended Backus-Naur Form (formal grammar)</language>
</langusage>
<revisiondesc>
<slist>
<sitem>20021218 sjd: Rename range to covering-range; remove leftover diff markup; typos.</sitem>
<sitem>20021127 sjd: Editorial comments.</sitem>
<sitem>20021120 sjd: Move ordering detail to appendix; cleanup.</sitem>
<sitem>20021030 sjd: Install new document ordering section, add DOM 2: Range references, remove unused definitions. General editing check.</sitem>
<sitem>20020717: Easy editorial fixes based on CR comments.</sitem>
<sitem>20020522: Initial draft as broken out from larger CR document.</sitem>
</slist>
</revisiondesc>
</header>
<body>
<div1>
<head>Introduction </head>
<p>&abstract; This scheme supports addressing into the internal structures of XML documents and external parsed entities. It allows for examination of a document's hierarchical structure and choice of portions based on various properties, such as element types, attribute values, character content, and relative position. In particular, it provides for specific reference to elements, character strings, and other XML information, whether or not they bear an explicit ID attribute.</p>
<p>The &scheme-phrase; is built on top of the XML Path Language <bibref ref="XPath"/>, which is a joint expression language also underlying the XSL Transformations (XSLT) language. The &scheme-phrase;'s extensions to XPath add the ability to identify locations that are not single, whole elements (such as those corresponding to typical selections and selection points in some user interfaces), and to combine string matching with the other location methods provided.</p>
<p>The &scheme-phrase; does not cover addressing into the internal structures of DTDs or the XML declaration.</p>
<div2>
<head>Origin and Goals </head>
<p>In addition to XPath, a number of prior systems and standards have helped guide the development of this specification; these are listed in the non-normative references section.<specref ref="non-norm-ref-sec"/> See the XPointer Requirements Document <bibref ref="xpreq"/> for a thorough explanation of requirements for the design of the &scheme-phrase;.</p>
</div2>
<div2>
<head>Notation and Document Conventions </head>
<p><termdef id="dt-must" term="Must, May, etc.">The key words <term>must</term>, <term>must 
not</term>, <term>required</term>, <term>shall</term>, <term>shall not</term>, <term>should</term>, <term>should not</term>, <term>recommended</term>, <term>may</term>, and <term>optional</term> in this specification are to be interpreted as described in <bibref ref="rfc2119"/>.</termdef></p>
<p>The terms pointer, pointer part, scheme, XPointer processor, application, error, failure, and namespace binding context are used in this specification as <xspecref href="&xptr-framework-file;#terminology">defined</xspecref> in the XPointer Framework specification. Note that errors defined by this specification are distinct from XPointer Framework errors.</p>
<p>The formal grammar for the &scheme-phrase; is given using simple Extended Backus-Naur Form (EBNF) notation, as described in the XML Recommendation <bibref ref="XML"/>.</p>
<p>The prototypes for &scheme-phrase; functions are given using the same notation used in the <bibref ref="XPath"/> Recommendation.</p>
<p>This specification explicitly extends some aspects of the syntax and semantics of XPath (mainly in relation to support for locations other than whole nodes). Except in such cases, <bibref ref="XPath"/> constructs and definitions remain in effect in the &scheme-phrase;.</p>
</div2>
</div1>
<div1>
<head>Terms and Concepts </head>
<p>Some special terms are defined here in order to clarify their relationship
to similar terms used in the technologies on which the &scheme-phrase; is
based. Additional terms specific to the &scheme-phrase; are defined in the
flow of the text. Refer to <bibref ref="XPath"/>, <bibref ref="dom2"/>, <bibref
ref="Infoset"/>, and <bibref ref="rfc2396"/> for definitions of other technical
terms used in this specification.</p>
<glist>
<gitem><label>point</label>
<def>
<p>A location in an XML Information Set with no content or children. For example, the location between two adjacent nodes, or after a particular character within a text node.
This notion is defined fully later (see <termref
def="dt-point">point</termref>), and comes from the DOM Level 2 <bibref ref="dom2"/> specification's notion of positions; this specification refers to such positions by the term <quote>point</quote> to avoid confusion with XPath positions.</p>
</def></gitem>
<gitem><label>range</label>
<def>
<p>An identification of all the XML Information Set content between a pair of points.
This notion is defined fully later (see <termref def="dt-range">range</termref>),
and comes from the DOM Level 2 <bibref ref="dom2"/> specification.</p>
</def></gitem>
<gitem><label><termdef id="dt-location" term="Location">location</termdef></label>
<def>
<p>A generalization of XPath's <term>node</term> that includes points and
ranges in addition to XPath nodes (which include the 7 node types defined by the XML Information Set.<bibref ref="Infoset"/></p>
</def></gitem>
<gitem><label><termdef id="dt-locset" term="Location set">location-set</termdef></label>
<def>
<p>An unordered list of locations, such as produced by an &scheme-phrase; expression.
This corresponds to the <term>node-set</term> that is produced by XPath expressions,
except for the generalization to include points and ranges. Just as for an XPath
node-set, a location-set is unordered, but can be treated as having a specific order depending on
the axis that is operating on it. In this specification, the ordering depends on the notion of document order defined in<specref ref="document-order-sec"/>, which applies to point and range locations as well as nodes,
rather than on XPath's treatment of document order for nodes.</p>
</def></gitem>
</glist>
</div1>
<div1 id="conformance">
<head>Conformance
</head>
<p>Conforming XPointer processors claiming to support the &scheme-phrase; must
conform to the behavior defined in this specification and may conform to additional
XPointer scheme specifications.
</p>
<p>This specification is intended for use with the XPointer Framework <bibref
ref="xptr-framework"/> specification, and thus conforming XPointer processors
must conform to the requirements of the XPointer Framework.
</p>
<p>This specification normatively refers to the XPath <bibref ref="XPath"/> Recommendation, and conforming XPointer processors must therefore conform to the requirements of XPath except as this specification modifies them.
</p>
<p>This specification also normatively uses the XPointer <code>xmlns</code>() scheme specification <bibref ref="xptr-xmlns"/>; XPointer processors claiming to conform to this specification must also conform to the <code>xmlns</code>() specification.
</p>
<p>Scheme data for the &scheme-phrase; conforms to this specification if it
does not cause an error as described in this specification.
</p>
<p>Should need arise to refer to the namespace for objects defined by this
specification, the normative namespace URI for the &scheme-phrase; is <code>http://www.w3.org/2001/05/XPointer</code>.</p>
</div1>
<div1 id="model">
<head>Language and Processing</head>
<p>XPath expressions work with a data set that is derived from the elements
and other markup constructs of an XML document. The &scheme-phrase; model
augments this data set. Both <code>&schemename;()</code> expressions and XPath
expressions operate by selecting portions of such data sets, often by their
structural relationship to other parts (for example, the parent of a node
with a certain ID value). The <code>&schemename;()</code>, like XPath, uses iterative
selections, each operating on what is found by the prior one.
</p>
<p>Selection of portions of the information hierarchy is done through three main constructs: axes,
predicates, and functions (constructs defined in XPath <bibref ref="XPath"/> ).
An axis defines a sequence of candidates that might
be located; predicates then test for various criteria relative to such portions;
and functions generate new candidates or perform various other tasks. For
example, an expression can identify certain elements from among the siblings of some previously located element, based on whether those sibling elements have an attribute
with a certain value or are of a certain type such as <quote>footnote</quote>. Another expression could
identify the point location immediately preceding a certain element (which in turn was identified by ID or other tests).</p>
<div2>
<head>Syntax</head>
<p>This section describes the syntax and semantics of the &scheme-phrase; and
the behavior of XPointer processors with respect to this scheme.</p>
<p>The scheme name is <quote>&schemename;</quote>. 
If scheme data in a pointer part with the &scheme-phrase; does
not conform to the syntax defined in this section, it is an error and the
pointer part fails.</p>
<scrap>
<head>xpointer() Scheme Syntax</head>
<prod id="NT-xpointerschemedata">
<lhs>xpointerschemedata</lhs><rhs><xnt href="&XPath;#NT-Expr">Expr</xnt></rhs>
</prod>
</scrap>
<p><xnt href="&XPath;#NT-Expr">Expr</xnt> is as defined in the XPath Recommendation <bibref
ref="XPath"/>, with the extensions defined in this specification.</p>
</div2>
<div2 id="terminology">
<head>Additions to XPath Terms and Concepts </head>
<p>The &scheme-phrase; extends XPath by adding the following:</p>
<ulist>
<item>
  <p diff="chg">A generalization of the XPath<bibref ref="XPath"/> concepts of nodes, node types, and
  node-sets to the &scheme-phrase; concepts of <termref
  def="dt-locset">locations</termref> (which subsume nodes, <termref
  def="dt-point">points</termref>, and <termref
  def="dt-range">ranges</termref>), location types (namely the Infoset node types plus
  point and range), and location-sets, which are sets of locations in the same way that
  XPath node sets are sets of nodes.</p>
</item>
<item><p>Two new location types, <code>point</code> and <code>range</code>,
corresponding to DOM positions and ranges, that can appear in location-set
results; also tests (akin to node tests) for these location types.</p></item>
<item><p>Rules for establishing the XPath evaluation context.</p></item>
<item><p>Allowance (as in <bibref ref="XSLT"/>) for the root node to have
multiple child elements, to allow expressions to address into arbitrary external
parsed entities as well as well-formed documents.</p></item>
<item><p>The functions <function>covering-range</function> and <function>range-inside</function>,
to address the covering ranges of locations in location sets.</p></item>
<item><p>The functions <function>string-range</function> and <function>range-to</function>,
to identify ranges by identifying the location of a given literal string in the text of some node(s), or by extending from the start of one location to the end of another.</p></item>
<item><p>The function <function>here</function>, applicable when the &scheme-phrase; expression being evaluated is found within an XML document. <function>here</function>
identifies the element directly bearing or containing the &scheme-phrase; expression.</p></item>
<item><p>The function <function>origin</function>, applicable when an &scheme-phrase; 
expression is interpreted in the course of a hypertext link traversal (for example, as defined in the XLink recommendation <bibref ref="XLink"/>). <function>origin</function>
identifies the location from which of the current hypertext traversal was initiated (sometimes called the "origin anchor".</p></item>
<item><p>The functions <function>start-point</function> and <function>end-point</function>,
to identify the beginning and ending point locations that bound another location
such as a node or range.</p></item>
</ulist>
<p>XPath provides for locating any subset of the <emph>nodes</emph> in an
XML document or external parsed entities. XPath functionality, such as filtering
an axis output by predicate, is generally defined in terms of operations on
nodes and node-sets. As noted earlier, the &scheme-phrase; also identifies locations
that are points and ranges.
For example, a range could extend from the middle of one paragraph to the
middle of the next, thus containing only part of the relevant paragraphs and
text nodes.
</p>
<note>
<p>The order of a location's characters as displayed on a computer screen might not reflect
their order in the underlying XML document. For example, this may occur when a portion of
a right-to-left language such as Arabic is embedded in a left-to-right language
such as French. For expressions that identify ranges of strings, the document
order is used, not the display order. Thus, an expression for a single range
might be displayed non-contiguously, and conversely a user selection of an
apparent single range might correspond to multiple non-contiguous ranges in
the underlying document.</p>
</note>
</div2>
<div2 id="context">
<head>Evaluation Context Initialization </head>
<p>An &scheme-phrase; expression in a pointer part (as defined in the XPointer Framework
<bibref ref="xptr-framework"/>) is evaluated to yield an
object of type <term>location-set</term>. This evaluation is carried out within a context
similar to the XPath evaluation context except for the generalization of
nodes to locations. XPointer processors <termref def="dt-must">must</termref> initialize
this evaluation context to include the following information before evaluating an expression:</p>
<ulist>
<item><p>A location (the <term>context location</term>), initialized to the
root node of an XML document or external parsed entity.
</p></item>
<item><p>A non-zero context position, initialized to 1.
</p></item>
<item><p>A non-zero context size, initialized to 1. (At the start, the only
location in the current location list is the context location.)
</p></item>
<item><p>A set of variable bindings. No means for initializing these is defined
for &scheme-phrase; processors. Thus, the set of variable bindings used when evaluating
an expression is empty, and use of a variable reference in an expression results
in failure of the pointer part.
</p></item>
<item><p>A library of functions. Only functions defined in XPath or this specification
can be used in expressions. An &scheme-phrase; expression that uses other functions results
in failure of the pointer part.
</p></item>
<item><p>A namespace binding context consisting of the initial context defined
in the XPointer Framework specification and additional contributions made
by any pointer parts having the <code>xmlns</code>() scheme to the left of the
current pointer part.
</p></item>
<item><p>When applicable, properties for the locations that the <function>origin</function> and <function>here</function> functions identify.
</p></item>
</ulist>
</div2>
<div2 id="datatypes">
<head>The <emph>point</emph> and <emph>range</emph> Location Types</head>
<p>For non-node locations, <termref def="dt-point">point</termref> and <termref def="dt-range">range</termref> locations can appear in the location sets identified by expression of the &scheme-phrase;. This
section defines these types and their
characteristics required for XPath interoperability.
Locations that are also nodes, have the same characteristics as XPath nodes.</p>
<note>
<p>Unlike DOM Level 2, which is based on UTF-16 units, XPath and the &scheme-phrase; are
based on UCS characters. So while the concepts of points and ranges are based
on the notions of positions and ranges, there are differences in detail.
For example, a sequence which in DOM counts as two characters might count
in the &scheme-phrase; as one character.</p>
</note>
<p>Points and ranges can be used as context locations in the &scheme-phrase;.
This allows the <code>[]</code> operator to be used to select locations from location sets in general.</p>
<p>The <function>range-to</function> function may be applied with a context location of any location type, and identifies a range whose start-point is start-point of the context location, and whose end-point is the end-point of the location identified by the function's argument.</p>
<p>The <function>local-name</function>,
	  <function>namespace-uri</function>, and
	  <function>name</function> functions operate on the first
	  <termref def="dt-location">location</termref> in document order, not the first location which is also a node.
</p>
<div3>
<head>Definition of Point Location </head>
<p><termdef id="dt-point" term="Point">A location of type <term>point</term> is
defined in terms of two data items:</termdef> 
The first is the <termdef id="dt-container-node-index" term="Container Node">
<term>container node</term>, which is that node that directly contains the point.</termdef> For example, a point between two adjacent characters within a text node will be the text node.
The second is the <termdef id="dt-point-index" term="Index">index</termdef>, 
which is a non-negative integer that represents the offset of the point among the
child nodes or the character content of the <term>container node</term> (each node
type can have only one or the other).
An index of zero indicates the point before any child nodes or contained characters, and
a non-zero index <var>n</var> indicates the point immediately after the <var>n</var>th
child node or character.</p>
<note>
<p>The zero-based counting of node-points is compatible with that of DOM 2<bibref ref="dom2"/>,
and therefore differs from the one-based counting used for XPath string functions such as
<function>string-range</function> that are available in the &scheme-phrase;.</p>
</note>
<p>As defined, points are sufficient to identify the location preceding
or following any individual character, or preceding or following any node
in the data set constructed from an XML document or external parsed entity.</p>
<p>
Given this definition, two points are necessarily identical if they have the same container node and index.</p>
<note>
<p> This specification does not constrain the implementation of points; 
XPointer processors
need not actually represent points using data structures consisting of a node
and an index.</p>
<p>Also note that while some nodes have explicit boundaries
(such as element start-tags and end-tags), the boundaries of text nodes are
implicit. Applications that present a graphical user interface for the selection
or rendering of points and ranges need to take into consideration the fact
that some points that might not be distinguished in the user interface, such as the points just inside and just
outside the closing boundary of a text node inside an element, are in fact
distinct.</p>
</note>
<p>A point location does not have an <xtermref href="&XPath;#dt-expanded-name">expanded-name</xtermref>.</p>
<p>The <xtermref href="&XPath;#dt-string-value">string-value</xtermref> of
a point location is empty.</p>
<p> The <xtermref href="&XPath;#axes">axes</xtermref> of a point location are defined as follows:</p>
<ulist>
<item><p>The <kw>child</kw>, <kw>descendant</kw>, <kw>preceding-sibling</kw>, <kw>following-sibling</kw>, <kw>preceding</kw>, <kw>following</kw>, <kw
>attribute</kw>, and <kw>namespace</kw> axes are empty.</p></item>
<item><p>The <kw>descendant-or-self</kw> axis contains the point itself.</p>
</item>
<item><p>The <kw>self</kw> axis contains the point itself.</p></item>
<item><p>The <kw>parent</kw> axis contains the point's container node.</p>
</item>
<item><p>The <kw>ancestor</kw> axis contains the point's container node and
its ancestors.</p></item>
<item><p>The <kw>ancestor-or-self</kw> axis contains the point itself, the
point's container node, and its ancestors.</p></item>
</ulist>
</div3>
<div3>
<head>Definition of Range Location </head>
<p>A location of type <termdef id="dt-range" term="Range">
<term diff="chg">range</term> is defined by two
points</termdef>, a <termdef id="dt-start-point" term="Start point"
diff="add"><term>start point</term></termdef> and an 
<termdef id="dt-end-point" term="End point" diff="add">
<term>end point</term></termdef>.
A range represents all of the XML structure and content
between the start point and end point.  This is distinct from
any list of nodes and/or characters, in part because
some nodes might be only partly included. The start point
and end point of a range <termref def="dt-must">must</termref>
be in the same document or external parsed entity. The start
point <termref def="dt-must">must not</termref> appear
after the end point in document order (see <specref
ref="document-order-sec"/>).
</p>
<p><termdef id="dt-collapsed-range" term="Collapsed range">A
range whose start point and end point are equal is
a <term>collapsed range.</term></termdef>
</p>
<p>If the container node of one point of a range
is a node of a type other than element, text, or
root, the container node of the other point of the
range <termref def="dt-must">must</termref> be the
same node. For example, it is allowed to specify a
range from immediately before
a processing instruction to the end of an element, but
not to specify a range from text inside a processing
instruction to text outside it.
</p>
<p>A range location does not have an <xtermref href="&XPath;#dt-expanded-name">expanded-name</xtermref>.</p>
<p>The <xtermref href="&XPath;#dt-string-value">string-value</xtermref> of
a range location consists of the characters that are in text nodes and that
are between the start point and end point of the range.
</p>
<p>The axes of a range location are identical to the axes of its start point.
For example, the <kw>parent</kw> axis of a range contains the parent of the
start point of the range.</p>
</div3>
<div3>
<head>Covering Ranges for All Location Types </head>
<p><termdef id="dt-covering-range" term="Covering range">A <term>covering
range</term> is a <termref def="dt-range">range</termref> that wholly and exactly encompasses a <termref def="dt-location">location.</termref> The covering range can be identified by applying the <function>covering-range</function> function to any location.
The equivalent covering range for each type of location is defined as follows:</termdef></p>
<ulist>
<item><p>For a range location, the covering range is identical to the range (note that
as in DOM <bibref ref="dom2"/>, although ranges are well-defined <emph>within</emph> all node types, ranges may not extend from inside the boundaries of namespace, attribute, comment, or processing instruction nodes to outside, or from outside to inside).</p>
</item>
<item><p>For a point location, the start and end points of the covering range
are the point itself.</p></item>
<item><p>For a node location that is an element, text, comment, or processing
instruction node, the container node of the start point
and of the end point of the covering range are both the parent of the identified node;
the index of the start point of the covering range is the number of preceding sibling
nodes of the location; and the index of the end point is one greater than
the index of the start point.</p></item>
<item><p>For a node location that is the root node, the container node of the start point and
end point of the covering range are both the root node; the index of the start point
of the covering range is 0; and the index of the end point of the covering
range is the number of children of the root location.</p></item>
<item><p>For a node location that is an attribute or namespace node, the container node of 
the start point and end point of the covering range is the attribute or namespace
node itself; the index of the start point of the covering range is 0; and the
index of the end point of the covering range is the length of the <xtermref href="&XPath;#dt-string-value">string-value</xtermref>
of the attribute or namespace node.</p></item>
</ulist>
</div3>
<div3>
<head>Tests for <code>point</code> and <code>range</code> Locations </head>
<p>The &scheme-phrase; extends the XPath production for <xnt href="&XPath;#NT-NodeType">NodeType...</xnt> by
adding items for the <code>point</code> and <code>range</code> location types.
The production (<xspecref href="&XPath;#NT-NodeType">number 38 in XPath</xspecref>) becomes as follows:</p>
<scrap>
<head>NodeType </head>
<prod id="NT-NodeType">
<lhs>NodeType</lhs><rhs>'comment'</rhs><rhs>| 'text'</rhs><rhs>| 'processing-instruction'</rhs>
<rhs>| 'node'</rhs><rhs>| 'point'</rhs><rhs>| 'range'</rhs>
</prod>
</scrap>
<p>This definition allows <xnt href="&XPath;#NT-NodeTest">NodeTest</xnt>s
to select locations of type <code>point</code> and <code>range</code> from
a location-set that might include locations of many types.</p>
</div3>

<div3 id="document-order-sec">
<head>Document order</head>

<p>XPointer must be able to represent locations that are entire element nodes, like XPath; but also locations that are not. For example, an edit insertion point does not correspond to any whole node, but rather to a zero-size location, such as the point immediately preceding a character of text within a text node or between two adjacent element nodes. Similarly, typical drag-selections in various applications correspond to <termref def="dt-range">ranges</termref>, not nodes.</p>

<p>As in DOM 2: Range<bibref ref="dom2"/>, a point is determined by the node that contains it, and the offset of the point within that node. A range is determined by its starting and ending points.</p>

<p>The appendix "On points and ranges" provides a simple notation that is similar in syntax to the XPointer <function>element()</function> scheme, but that is not limited to identifying  whole elements. That notation clarifies the definition of document ordering given here and has useful additional properties, but ordering can be implemented using that or any other representation.</p>

<p>The diagram below shows the numbering of nodes and points in a graphic representation of an XML Information Set.</p>

<graphic source="xptr-nums.png" 
alt="Sample XML tree, with nodes and inter-node points numbered."/>
<p>Figure 1: Numbering of nodes and points</p>

<p>For example,</p>

<ulist>
<item><p>point(1.0) is just inside the beginning of the <code>p</code> element.</p></item>
<item><p>point(1.2) is between the end of the <code>em</code> element and the following text
node (which contains "world.").</p></item>
<item><p>point(.0) immediately precedes the root node.</p></item>
<item><p>point(1/2/1.1) immediately following the "b" in the middle text node.</p></item>
</ulist>

<p>Intuitively, points are ordered largely as one would expect from a pre-order traversal of the document, or the XML stream order. </p>

<p>More formally, any two document locations that are comparable, regardless of which type(s) they are, can be compared by comparing their <termref def="dt-covering-range">covering ranges.</termref> A comparison of ranges is defined purely by a sequence of comparisons of their starting and ending points. Because all comparisons thus reduce to comparisons of points, point comparison is defined first below. The sequence of point comparisons required to compare two ranges is defined second, and is sufficient for comparing any locations that can be compared.</p>

<p>Because text nodes are not explicitly represented in XML documents, the point immediately before (or after) a text node occurs at the same place in an XML source document as the point immediately before (or after) that text node's first (or last) character. This specification defines those locations as distinct; they do not compare as equal. For example, point(1.2) is not equal to point(1/3.0).</p>

<p>Because the attribute and namespace nodes of a given element node are unordered, it is illegal to compare them in certain ways, and the result of such an attempted comparison is undefined. Specifically:</p>

<ulist>
<item><p>Points within different attribute and/or namespace nodes of the same container node may not be compared.</p></item>

<item><p>A point within an attribute or namespace node may not be compared to the location of its container node.</p></item>

<item><p>A point within an attribute or namespace node, however, may be compared to any node other than its parent node or to any point within any node other than its parent node. In such comparisons, the point is ordered as its parent node would be.</p></item>

<item><p>Two points within the <emph>same</emph> attribute or namespace node may be compared, and are compared by their offsets just as are points within any other node.</p></item>
</ulist>

<p>Points within the same container node compare as do the values of their respective offsets.</p>

<p>Points within different nodes <emph>cannot</emph> be correctly ordered merely by comparing the order of their container nodes. For example, the later point could be late in a large node <var>N</var>, while the earlier point could be within an earlier child <var>M</var> of <var>N</var>. In that case node <var>N</var> is before <var>M</var> (because it started earlier), and so merely comparing <var>M</var> and <var>N</var> would produce the incorrect result.</p>

<p>To compare any comparable points <var>P1</var> and <var>P2</var>:</p>

<p><code>point(.0)</code> compares as before any other point; <code>point(.1)</code> compares as after any other point.</p>

<olist>
<item><p>Define <var>Node1</var> as the child sequence of the node directly containing point <var>P1</var>, and <var>Node2</var> as the child sequence of the node directly containing point <var>P2</var>.</p></item>

<item><p>Define <var>Offset1</var> as the offset of point <var>P1</var> within the node identified by <var>Node1</var>, and <var>Offset2</var> as the offset of point P2 within the node identified by <var>Node2</var>.</p></item> 

<item><p>Beginning at the uppermost end of <var>Node1</var> and <var>Node2</var> (typically both 1 for the XML document element), compare corresponding components of the two paths and discard all such pairs that are equal.</p></item>

<item><p>If a further component(s) is available from <emph>neither</emph> <var>Node1</var> nor <var>Node2</var>, the points are directly within the same containing node, and are ordered simply by their respective offsets.</p></item>

<item><p>If a further component(s) is available from <emph>both</emph> <var>Node1</var> and <var>Node2</var>, then the node whose next component value is greater represents the point that is later in document order.</p></item>

<item><p>If a further component(s) is available for only <var>Node1</var>, then <var>P1</var> is within some descendant of the node in which <var>P2</var> directly occurs. Thus it is necessary to determine the position of <var>Offset2</var> relative to the ancestor of <var>P1</var> that is at the same level (that is a child of <var>Node2</var>). To do this, compare <var>Offset2</var> to the first of the further components for <var>Node1</var>. If <var>Offset2</var> is greater than or equal, then <var>P2</var> follows <var>P1</var> in document order; otherwise it precedes <var>P1</var>.</p></item>

<item><p>If a further component(s) is available for only <var>Node2</var>, compare <var>Offset1</var> to the first of the further components for <var>Node2</var>. If <var>Offset1</var> is greater than or equal, then <var>P1</var> follows <var>P2</var> in document order; otherwise it precedes <var>P2</var>.</p></item>
</olist>

<note><p>As of this writing, the ordering algorithm in DOM 2: Range<bibref ref="dom2"/> appears to produce incorrect results for some cases. Until a correction to this problem is issued, implementors should be particularly careful that their implementations for document order comparison produce the results defined here.</p></note>

<p>Two ranges <var>R1</var> and <var>R2</var> are ordered using the following sequence of comparisons of their starting and ending points (these definitions avoid circularity because the definition of point ordering given above does not involve casting the compared points to their equivalent collapsed ranges):
</p>

<p>If the start point of <var>R1</var> is not equal to the start point of <var>R2</var>, then the ranges are ordered as their respective start points are ordered. That is, if <var>R1</var> starts before <var>R2</var> it is before <var>R2</var>, and if <var>R1</var> starts after <var>R2</var> it is after <var>R2</var>.
</p>

<p>If the start point of <var>R1</var> is equal to the start point of <var>R2</var>, then the ranges are ordered as their respective end points are ordered. That is, if <var>R1</var> and <var>R2</var> start at the same point, then: if <var>R1</var> ends before <var>R2</var> it is before <var>R2</var>; if <var>R1</var> and <var>R2</var> end at the same point <var>R1</var> is equal to <var>R2</var>; and if <var>R1</var> ends after <var>R2</var> it is after <var>R2</var>.
</p>

<p>Thus, <var>R1</var> and <var>R2</var> are equal if and only if their respective start points and end points are equal.
</p>

<p>
Comparisons between any two types of locations (point vs. node, etc.) must produce the same results as obtained through converting all comparands to their equivalent ranges and comparing those ranges.
</p>
<p>
This algorithm yields the correct results; however, implementations need not use this specific algorithm to compare point locations. They may use any algorithm that produces the same results.
</p>

</div3>
</div2>

<div2 id="xptr-functions">
<head>Functions Added by the &schemename;() Scheme</head>
<p>The &scheme-phrase; adds the following functions to those in XPath.</p>
<div3 id="rangeexprs">
<head><function>range-to</function> Function </head>
<proto name="range-to" return-type="location-set"><arg type="location-set"/>
</proto>
<p>For each location in the context, <function>range-to</function> returns
a range. The start point of the range is the start point of the context location
(as determined by the <function>start-point</function> function), and the
end point of the range is the end point (as determined by the <function>end-point</function> function)
of the location found by evaluating the <xnt href="&XPath;#NT-Expr">expression</xnt> argument
with respect to that context location.</p>
<p>The change made to the XPath syntax to support the <function>range-to</function> construct
corresponds to a single addition to the <xspecref href="http://www.w3.org/TR/xpath#section-Location-Steps">Step
production</xspecref> of the <bibref ref="XPath"/> specification. The original
production is as follows:</p>
<eg>[4] Step ::= AxisSpecifier NodeTest Predicate*
                | AbbreviatedStep</eg>
<p>The version in the &scheme-phrase; is as follows:</p>
<eg>[4xptr] Step ::= AxisSpecifier NodeTest Predicate*
                    | AbbreviatedStep
                    | 'range-to' '(' Expr ')' Predicate*</eg>
<p>This change is a single exception for the <function>range-to</function> function.
It is not a generic change and is not extensible to other functions. The modified
production expresses that a range computation must be made for each of the
locations in the current location list.</p>
<p>As an example of using the <function>range-to</function> function, the
following pointer part locates the range from the start point of the element
with ID <quote>chap1</quote> to the end point of the element with ID <quote>chap2</quote>.</p>
<eg>xpointer(id("chap1")/range-to(id("chap2")))</eg>
<p>As another example, imagine a document that uses empty elements (such as <code>&lt;REVST/></code> for
revision start and <code>&lt;REVEND/></code> for revision end) to mark the
boundaries of edits. The following pointer part would select, for each revision,
a range starting at the beginning of the <code>REVST</code> element and ending
at the end of the next <code>REVEND</code> element:</p>
<eg>xpointer(descendant::REVST/range-to(following::REVEND[1]))</eg>
</div3>
<div3 id="stringrange">
<head><function>string-range</function> Function </head>
<proto name="string-range" return-type="location-set"><arg type="location-set"/>
<arg type="string"/><arg type="number" occur="opt"/><arg type="number" occur="opt"/>
</proto>
<p>For each location in the <var>location-set</var> argument,
<function>string-range</function> returns
a set of ranges determined by searching the
<xtermref href="&XPath;#dt-string-value">string-value</xtermref>
of the location for substrings that match the <var>string</var>
argument. An empty <var diff="chg">string</var> is defined to
match before each character of the <xtermref href="&XPath;#dt-string-value">string-value</xtermref> and after the
final character. White space in a string is matched literally,
with no normalization except that provided by XML for line ends
and attribute values. Each non-overlapping match can contribute a
range to the resulting location set.</p>
<p>The third argument gives the position of the first
character to be in the resulting range, relative to
the start of the match. The default value is
1, which makes the range start immediately before the first
character of the
matched sub-string.
The fourth argument gives the number of characters in the
range; the default is that the range extends to the end
of the matched string.
Thus, both the start point and end point of each range
returned by the <function>string-range</function> function
will be within text nodes.</p>
<p>Element boundaries, as well as entire embedded nodes such as processing
instructions and comments, are ignored as specified by the definition of <xtermref
href="&XPath;#dt-string-value">string-value</xtermref> in <bibref ref="XPath"/>.</p>
<p>For any particular location,
if the <var>string</var> argument is not found
in the <xtermref href="&XPath;#dt-string-value">string-value</xtermref> of the location, or if the
third and fourth argument indicates a range that
is wholly beyond the beginning or end of the
document or entity, then no range is added to
the result for that match.</p>
<p>The start and end points of the range-locations
in the returned location-set will all be
character-points.</p>
<p>For example, the following expression returns a range that selects the
17th of those <quote>Thomas Pynchon</quote> strings appearing in a <code>title</code> element:</p>
<eg>string-range(//title,"Thomas Pynchon")[17]</eg>
<p>As another example, the following expression returns a collapsed range
whose points immediately precede the letter <quote>P</quote> (8 from the start
of the string) in the third of those <quote>Thomas Pynchon</quote> strings
appearing in a <code>P</code> element:</p>
<eg>string-range(//P,"Thomas Pynchon",8,0)[3]</eg>
<p>Alternatively this could be specified as follows:</p>
<eg>string-range(string-range(//P,"Thomas Pynchon")[3],"P",1,0)</eg>
<p><xtermref href="&XPath;#dt-string-value">String-values</xtermref> are <quote>views</quote> into only the string content of
a document or entity; they do not retain the structural context of any non-text
nodes interspersed with the text. Because the <function>string-range</function> function
operates on a <xtermref href="&XPath;#dt-string-value">string-value</xtermref>, markup that intervenes in the middle of a string
does not prevent a match. (Note that for this reason, a <function>string-range</function> match
is a range describing the relevant substring of the <xtermref href="&XPath;#dt-string-value">string-value</xtermref>, not necessarily
a contiguous string in a single text node in the document.) For example, if
the 17th occurrence of <quote>Thomas Pynchon</quote> had some inline markup
in it as follows, it would not change the string identified by the XPointer
processor:</p>
<eg>Thomas &lt;em>Pyn&lt;/em>chon</eg>
<p>The following expression selects the fifth of those exclamation marks appearing
in any text node in the document and the character immediately following that
exclamation mark:</p>
<eg>string-range(/,"!",1,2)[5]</eg>
<p>Although these examples locate ranges via text in the <xtermref href="&XPath;#dt-string-value">string-values</xtermref> of
elements, <function>string-range</function> is useful for locating ranges
that are wholly enclosed in other node types as well, such as attributes,
processing instructions, and comments.</p>
</div3>
<div3>
<head>Additional Range-Related Functions </head>
<p>The following functions are related to ranges.</p>
<div4>
<head><function>covering-range</function> Function </head>
<proto name="range" return-type="location-set"><arg type="location-set"/>
</proto>
<p>The <function>covering-range</function> function returns the <termref def="dt-covering-range">covering ranges</termref> for the locations
in the argument location-set. For each location <var>x</var> in the argument
location-set, a range location representing the
<termref def="dt-covering-range">covering range</termref> of <var>x</var> is
added to the result location-set.</p>
</div4>
<div4>
<head><function>range-inside</function> Function </head>
<proto name="range-inside" return-type="location-set"><arg type="location-set"/>
</proto>
<p>The <function>range-inside</function> function returns the distinct <termref def="dt-covering-range">covering ranges</termref> of the locations in the argument location-set. For each location <var>x</var> in
the argument location-set, a location is added to the result location-set.
If <var>x</var> is a range location or a point, then <var>x</var> is added
to the result location-set. Otherwise <var>x</var> is used as the container
node of the start and end points of the range location to be added, which
is defined in this way: The index of the start point of the range is zero.
If the end point is a character-point then its index is the length of the
<xtermref href="&XPath;#dt-string-value">string-value</xtermref> of <var>x</var>; otherwise its index is the number of children
of <var>x</var>.</p>
</div4>
<div4>
<head><function>start-point</function> Function </head>
<proto name="start-point" return-type="location-set"><arg type="location-set"/>
</proto>
<p>For each location <emph>x</emph> in the argument location-set, <function>start-point</function> adds
a location of type point to the resulting location-set. That point represents
the start point of location <emph>x</emph> and is determined by the following
rules:</p>
<ulist>
<item><p>If <emph>x</emph> is of type point, the resulting point is <emph>x</emph>.</p>
</item>
<item><p>If <emph>x</emph> is of type range, the resulting point is the start
point of <emph>x</emph>.</p></item>
<item><p>If <emph>x</emph> is of type root, element, text, comment, or processing
instruction, the container node of the resulting point is <emph>x</emph> and
the index is 0.</p></item>
<item><p>If <emph>x</emph> is of type attribute or namespace, the pointer
part in which the function appears fails.</p></item>
</ulist>
</div4>
<div4>
<head><function>end-point</function> Function </head>
<proto name="end-point" return-type="location-set"><arg type="location-set"/>
</proto>
<p>For each location <var>x</var> in the argument location-set, <function>end-point</function> adds
a location of type point to the result location-set. That point represents
the end point of location <var>x</var> and is determined by the following
rules:</p>
<ulist>
<item><p>If <var>x</var> is of type point, the resulting point is <var>x</var>.</p>
</item>
<item><p>If <var>x</var> is of type range, the resulting point is the end
point of <var>x</var>.</p></item>
<item><p>If <var>x</var> is of type root or element, the container node of
the resulting point is <var>x</var> and the index is the number of children
of <var>x</var>.</p></item>
<item><p>If <var>x</var> is of type text, comment, or processing instruction,
the container node of the resulting point is <var>x</var> and the index is
the length of the <xtermref href="&XPath;#dt-string-value">string-value</xtermref> of x.</p></item>
<item><p>If <emph>x</emph> is of type attribute or namespace, the pointer
part in which the function appears fails.</p></item>
</ulist>
</div4>
</div3>
<div3>
<head><function>here</function> Function </head>
<proto name="here" return-type="location-set"></proto>
<p>The <function>here</function> function is meaningful only when the expression
being interpreted occurs in an XML document or external parsed entity; otherwise
the pointer part in which the <function>here</function> function appears fails.
When in an XML context, the <function>here</function> function returns a location-set
with a single member. There are two possibilities for the location returned:</p>
<ulist>
<item><p>If the expression being evaluated appears in a text node inside an
element node, the location returned is the element node.</p></item>
<item><p>Otherwise, the location returned is the node that directly contains
the expression being evaluated.</p></item>
</ulist>
<p>In the following example, the <function>here</function> function appears
inside an expression that is in an attribute node. The expression as a whole,
then, returns the <el>slide</el> element just preceding the <el>slide</el> element
that most directly contains the attribute node in question.</p>
<eg>&lt;button
   xlink:type="simple"
   xlink:href="#xpointer(here()/ancestor::slide[1]/preceding::slide[1])">
Previous
&lt;/button></eg>
<note>
<p>The type of the node in which the <function>here</function> function appears
is likely to be <code>text</code>, <code>attribute</code>, or <code>processing-instruction</code>.
The returned location for an expression appearing in element content does
not have a node type of <code>element</code> because the expression is in
a text node that is itself inside an element.</p>
</note>
</div3>
<div3>
<head><function>origin</function> Function </head>
<proto name="origin" return-type="location-set"></proto>
<p>The <code>origin()</code> function is meaningful only when the expression
is being processed in response to traversal of a link expressed in an XML
document. The <function>origin</function> function enables addressing relative
to third-party and inbound links such as defined in the XLink Recommendation.
This allows expressions to express relative locations when links do not reside
directly at one of their endpoints. The function returns a location-set with
a single member, which locates the element from which a user or program initiated
traversal of the link. (See <bibref ref="XLink"/> for information about traversal.)</p>
<p>It is an error to use <function>origin</function> in the fragment identifier
portion of a URI reference where a URI is also provided and identifies a resource
different from the resource from which traversal was initiated, or in a situation
where traversal is not occurring.</p>
</div3>
</div2>
<div2>
<head>Root Node Children </head>
<p>The XML Recommendation requires well-formed documents to contain a single
element at the top level. Thus, the XPath data model of a well-formed document
will have a root node with a single child node of type element. In order to
address locations in arbitrary external parsed entities, along with well-formed
documents, the &scheme-phrase; extends the XPath data model to allow the root
node to have any sequence of nodes as children that would be possible of an
element node. This extension is identical to the one made by XSLT. Thus, the
root node may contain child nodes of type text, and any number of child nodes
of type element.</p>
</div2>
</div1>
</body><back>
<div1 id="references">
<head>References </head>
<div2>
<head>Normative References </head>
<blist>
<bibl id="dom2" key="DOM2"><titleref href="http://www.w3.org/TR/DOM-Level-2-Core/">Document
Object Model (DOM) Level 2 Specification: Version 1.0.</titleref> World Wide
Web Consortium, 2000.
</bibl>
<bibl id="Dom2Range"><titleref href="http://www.w3.org/TR/DOM-Level-2-Traversal-Range/">Document Object Model (DOM) Level 2 Traversal and Range Specification.</titleref> Version 1.0. W3C Recommendation, 13 November, 2000.
</bibl>
<bibl id="rfc2119" key="RFC 2119"><titleref href="http://www.rfc-editor.org/rfc/rfc2119.txt">RFC
2119: Key words for use in RFCs to Indicate Requirement Levels</titleref>.
Internet Engineering Task Force, 1997.
</bibl>
<bibl id="rfc2396" key="RFC 2396"><titleref href="http://www.rfc-editor.org/rfc/rfc2396.txt">RFC
2396: Uniform Resource Identifiers</titleref>. Internet Engineering Task Force,
1995.
</bibl>
<bibl id="XML" key="XML">Tim Bray, Jean
Paoli, C.M. Sperberg-McQueen, and Eve Maler, editors. <titleref href="http://www.w3.org/TR/REC-xml">Extensible Markup
Language (XML) 1.0 (Second Edition).</titleref> World Wide Web Consortium, 2000.
</bibl>
<bibl id="xptr-framework" key="XPtrFrame">Paul
Grosso, Eve Maler, Jonathan Marsh, and Norman Walsh, editors. <titleref href="&xptr-framework-file;">XPointer
Framework</titleref> W3C Proposed Recommendation. World Wide Web Consortium, 2002. 
</bibl>

<bibl id="xptr-element" key="XPtr-element">Paul
Grosso, Eve Maler, Jonathan Marsh, and Norman Walsh, editors. <titleref href="&xptr-element-file;">XPointer element() Scheme</titleref> W3C Proposed Recommendation. World Wide Web Consortium, 2002.</bibl>

<bibl id="xptr-xmlns" key="XPtr-xmlns">Steven DeRose,
	    Ron Daniel Jr., Eve
Maler and Jonathan Marsh, editors. <titleref href="&xptr-xmlns-file;">XPointer xmlns()
	      Scheme</titleref> W3C Proposed Recommendation.
World Wide Web Consortium, 2002.
</bibl>
<bibl id="unicode"
key="Unicode">The Unicode Consortium. <titleref href="http://www.unicode.org/unicode/standard/standard.html">The Unicode Standard.</titleref>
</bibl>
<bibl id="XPath" key="XPath">James Clark
and Steve DeRose, editors. <titleref href="http://www.w3.org/TR/xpath">XML Path Language (XPath)</titleref>.
World Wide Web Consortium, 1999.
</bibl>
</blist></div2>
<div2 id="non-norm-ref-sec">
<head>Non-Normative References </head>
<blist>
<bibl id="chum" key="CHUM">Steven J. DeRose and David G. Durand. 1995. <quote>The
TEI Hypertext Guidelines.</quote> In <titleref>Computing and the Humanities</titleref> 29(3).
Reprinted in <titleref>Text Encoding Initiative: Background and Context</titleref>,
ed. Nancy Ide and Jean Veronis, ISBN 0-7923-3704-2.
</bibl>
<bibl id="dexter" key="Dexter">Halasz, Frank. 1994. <quote>The Dexter Hypertext
Reference Model.</quote> In <titleref>Communications of the Association for
Computing Machinery</titleref> 37 (2), February 1994: 30-39.
</bibl>
<bibl id="fress" href="http://www.stg.brown.edu/~sjd/fress.html" key="FRESS">Steven
J. DeRose and Andries van Dam. 1999. <quote>Document structure in the FRESS
Hypertext System.</quote> <titleref>Markup Languages 1</titleref> (1) Winter.
Cambridge: MIT Press: 7-32.
</bibl>
<bibl id="html" key="HTML">
Dave Raggett, Arnaud Le Hors, and Ian Jacobs.
<titleref href="http://www.w3.org/TR/html4/">HTML
4.01 Specification</titleref>. World Wide Web Consortium, 1999.
</bibl>
<bibl id="Infoset" key="Infoset">John
Cowan and Richard Tobin, editors. <titleref href="http://www.w3.org/TR/xml-infoset/">XML Information Set</titleref>.
World Wide Web Consortium, 2001.
</bibl>
<bibl id="iso10744" key="ISO/IEC 10744"><titleref href="http://www.ornl.gov/sgml/wg8/docs/n1920/html/n1920.html">ISO/IEC
10744-1992 (E). Information technology --Hypermedia/Time-based Structuring
Language (HyTime).</titleref> Geneva: International Organization for Standardization,
1992. <titleref>Extended Facilities Annex.</titleref> [Geneva]: International
Organization for Standardization, 1996.
</bibl>
<bibl id="ohs" href="http://aue.auc.dk/~kock/OHS-HT98/Papers/ossenbruggen.html"
key="OHS">van Ossenbruggen, Jacco, Anton Eliëns and Lloyd Rutledge. <quote>The
Role of XML in Open Hypermedia Systems.</quote> Position paper for the 4th
Workshop on Open Hypermedia Systems, ACM Hypertext '98.
</bibl>
<bibl id="rlocs"
key="RLocs">Thomas A Phelps and Robert Wilensky. <titleref href="http://www.cs.berkeley.edu/~phelps/Robust/papers/RobustHyperlinks.html">Robust Intra-document
Locations.</titleref> University of California, Berkeley.
</bibl>
<bibl id="tei" key="TEI">C. M. Sperberg-McQueen
and Lou Burnard, editors. <titleref href="http://www.tei-c.org/Guidelines2/index.html#body.1_div.2">Guidelines for Electronic Text Encoding
and Interchange</titleref>. Association for Computers and the Humanities (ACH),
Association for Computational Linguistics (ACL), and Association for Literary
and Linguistic Computing (ALLC). Chicago, Oxford: Text Encoding Initiative,
1994.
</bibl>
<bibl id="XLink" key="XLink">Steve DeRose,
Eve Maler, David Orchard, and Ben Trafford, editors. <titleref href="http://www.w3.org/TR/xlink/">XML Linking
Language (XLink)</titleref>. World Wide Web Consortium, 2001.
</bibl>
<bibl id="xpreq" key="XPREQ">Steve
DeRose, editor. <titleref href="http://www.w3.org/TR/NOTE-xptr-req">XML XPointer Language Requirements Version 1.0</titleref>.
World Wide Web Consortium, 1999.
</bibl>
<bibl id="XSLT" key="XSLT">James Clark, editor. <titleref href="http://www.w3.org/TR/xslt">XSL Transformations (XSLT) Version 1.0</titleref>. World Wide Web Consortium,
1999.
</bibl>
</blist></div2>
</div1>

<inform-div1 id="appA">
<head>On points and ranges</head>

<div2 id="document-order-notation">
<head>Notation</head>

<p>The notation defined here builds on the XPointer <code>element()</code> scheme. However, where <code>element()</code> can only identify a whole element node in an XML Infoset, the notation defined here can also identify any point or range. This notation is intended to be easy to understand and to provide a clear way to explicate the sometimes-complex ordering relationships of document locations. It also has advantageous properties such as that many useful properties of document locations can be determined merely by examining their representation in this notation, and without having to resort to the actual document or Infoset.</p>

<p>The initial portion of the notation is identical to
	  <code>element()</code>: a list of child numbers separated by
	  the slash character ("/"). Such a list is called a <termdef
								      id="dt-child-sequence" term="child sequence"><term>child sequence</term></termdef>. The following XML source corresponds to the diagram below it and shows the <code>element()</code> scheme's child sequence number above each node:</p>
<eg>
  &lt;p>hello, &lt;emph>big &lt;/emph>world.&lt;/p>
</eg>

<eg>
                       ROOT
                         |
                         1
                         |
                         p
        ----------------------------------
        |                |               |
       1/1              1/2             1/3
        |                |               |
       txt             emph             txt
   -------------      -------        -----------
   h e l l o , _         |           w o r l d .
                       1/2/1
                         |
                        txt
                      -------
                      b i g _
</eg>
<p>Figure 2: Structure diagram with child sequences for all <emph>nodes</emph>.</p>

<p>"ROOT" here indicates the root node, "txt" indicates text nodes, "_" indicates the space character, and "p" and "emph" indicate element nodes.</p>

<p>For example:</p>

<ulist>
<item><p>element(1) identifies the <code>p</code> element (the document element; note that the root node has no number).</p></item>
<item><p>element(1/2/1) identifies the (only) text node within the <code>emph</code> element, which contains the text "big&nbsp;".</p></item>
</ulist>

<p>Points, ranges, and non-element nodes cannot be identified by the numbering mechanism. However, the DOM 2: Range<bibref ref="dom2"/> specification (http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html) defines points in terms of a containing node and an offset within it.  This numbering covers all the points adjacent to nodes of all ordered node types, and all the points adjacent to characters within the text-containing node types (not only text nodes, but also comments, processing instructions, namespace and attribute nodes).</p>

<p>For the exact same structure shown above, those <termref def="dt-point">points</termref> are numbered as shown below. </p>

<eg>
                       ROOT
                         |
                         |
                  ^      p      ^
                  0      |      1
                         |
        ----------------------------------
        |                |               |
        |                |               |
        |                |               |
  ^    txt      ^      emph      ^      txt    ^
  0     ^       1        |       2       ^     3
       / \               |              / \
      /   \              |             /   \
     /     \             |            /     \
  -------------         txt         -----------
  h e l l o , _          ^          w o r l d .
 ^ ^ ^ ^ ^ ^ ^ ^        / \        ^ ^ ^ ^ ^ ^ ^
 0 1 2 3 4 5 6 7       /   \       0 1 2 3 4 5 6
                      /     \
                      -------
                      b i g _
                     ^ ^ ^ ^ ^
                     0 1 2 3 4 
</eg>

<p>Figure 3: Structure diagram with <termref def="dt-point">points</termref> numbered.</p>

<p>For example:</p>

<ulist>
<item><p>the point just before the first text node is offset 0 within the <code>p</code> element</p></item>
<item><p>the point after the "r" of "world" is offset 3 within the last text node.</p></item>
<item><p>the point between the <code>emph</code> element and the following text node is offset 2 within the <code>p</code> element</p></item>
</ulist>

<note><p>Implementors must take care regarding a difference in how
	    XPath <bibref ref="XPath"/> and DOM 2: Range <bibref
								 ref="dom2"/> count characters. XPath and (and hence this specification) count UCS characters; DOM instead counts UTF-16 code points.</p></note>

<p>A point is always within some node, but a point cannot have children as a node can. Thus, a point can always be identified by the child sequence of the node it is in, plus the offset of the point within that node. </p>

<p>This specification therefore defines the <termdef
						     id="dt-point-sequence" term="point-sequence">point sequence</termdef> notation to be like the <code>element()</code> scheme syntax except that:</p>

<ulist>
<item><p>the slash-separated numbers are determined not by counting only element nodes, but by counting nodes of all types</p></item>
<item><p>an integer is appended when representing a point, to represent the point's offset within the node specified by the preceding child sequence</p></item>
<item><p>the final integer is separated from the preceding ones by "." instead of "/", to distinguish its different meaning</p></item>
<item><p>the child sequence may be empty, meaning that the point is directly within the root node</p></item>
<item><p>the notation is not named "element", but "point"</p></item>
</ulist>

<p>For example:</p>

<ulist>
<item><p>the point sequence to identify the point immediately following the period within the last text node above is <code>point(1/3.6)</code>. "1/3" identifies the last text node, while ".6" indicates the offset with that node.</p></item>
<item><p>the point immediately preceding the <code>p</code> element has point sequence <code>point(.0)</code>.</p></item>
</ulist>

<p>The last component must be delimited by "." instead of "/" in order to distinguish specifying a point from specifying a node at the same level. For example, <code>point(1/2)</code> is a child sequence that identifies the emph element above, but <code>point(1.2)</code> identifies the point immediately following it. Thus the XPointer startpoint() and endpoint() functions can be easily implemented in terms of this representation.</p>

<p>The point preceding the root node itself is identified as ".0"; the point after the root node itself is identified as ".1". The sequence "/" refers to the root node itself and may optionally be written before the first numeric component. </p>

<p>For an expression range(S, E) in which S and E are both points: If S precedes E in document order the expression represents the range beginning at S and ending at E; if S is equal to E in document order, the expression represents the collapsed range (equivalent to the point) at S (and equally at E); if S follows E in documents order, the expression is in error and results are undefined.</p>

<p>An expression point(P) in which P is not a point, is treated as point(start-point(P)). 
An expression range(S) is treated as range(S,S). 
An expression range(S, E) in which either S or E is not a point, is equivalent to range(start-point(S),end-point(E)).</p>

<p>The name of the point notation is "point", and its formal grammar is:</p>

<eg>
[1]     PointSchemeData   ::=  (NCName PointSequence?) | PointSequence 
[2]     PointSequence     ::=  (ChildSequence Offset?) | (Root Offset?) | Offset
[3]     ChildSequence     ::=  ('/' [1-9] [0-9]*)+
[4]     Root              ::=  '/'
[5]     Offset            ::=  ('.' [0-9]+)
</eg>

<p>The name of the range notation is "range", and its formal grammar is:</p>

<eg>
[6]     RangeSchemeData   ::=  PointSchemeData s* ("," s* PointSchemeData)?
</eg>

<p>The diagram in the section "Document Ordering" above, shows the point sequences to all points in its example, omitting the "point(" and ")" to save space.</p>

<note><p>As noted earlier, the point immediately before (or after) a text node occurs at the same place in an XML source document as the point immediately before (or after) that text node's first (or last) character. This specification defines those locations as distinct; they do not compare as equal. For example, the point at offset 2 within the p element above is not equal to the point at offset 0 within the text node containing "world." It is beyond the scope of this specification to define editing operations such as insertion, but we note that the permissible operations at such points may differ. For example, an interface might reject inserting a node within a text node even at offset 0, or inserting characters at the corresponding offset within the containing element.</p></note>

<p>Since a range is defined in terms of a starting point and an ending point, a range is uniquely identified by two point sequences. For example, the range extending from before the 2nd "l" of "hello", to immediately after the emph element, is from <code>point(1/1.3)</code> to <code>point(1.2)</code> and is here written <code>range(1/1.3, 1.2)</code>.</p>
</div2>

<div2>
<head>Ranges equivalent to points, characters, and nodes</head>

<p>The <termref def="dt-covering-range">covering range</termref> of any location, as defined above, is equivalent to the location and compares identically. For example,</p>

<ulist>
<item><p>the point just described following "l" is equivalent to <code>range(1/1.3, 1/1.3)</code>.</p></item>

<item><p>the "i" itself is equivalent to <code>range(1/2/1.1, 1/2/1.2)</code>.</p></item>

<item><p>the emph element above is equivalent to <code>range(1.1, 1.2)</code>.</p></item>

<item><p>the entire content of the root node (but not the root node itself) is equivalent to <code>range(.0,.1) or range(/.0, /.1).</code>.</p></item>

<item><p>the entire root node is equivalent to <code>range(/,/)</code>.</p></item>
</ulist>

<note><p>The node representation just shown is analogous to the "outerHTML" property in some scripting languages, as it contains the entire node as a whole, not merely its children or contents. The "inner" aspect of a node is also representable. For example, the complete content of the p element above, but not the p element itself, is <code>range(1.0, 1.3)</code>. The 3 represents offset 3 within the p element, the position following its 3rd child (which is the text node containing 'world.').</p></note>

<note><p>Several useful operations can be done using solely the point sequence representation of ranges. For example, order comparisons, tests of containment and equivalence, tests of whether a range could form a well-formed XML entity, and measures of nesting depth can all be trivially constructed based on this representation. However, this specification does not mandate implementation of this or any other internal representation, so long as the results specified here are obtained.</p></note>
</div2>
</inform-div1>

<inform-div1 id="wgmembers">
<head>Working Group Members </head>
<p>The first working drafts of this specification were developed in the XML
Working Group, whose members are listed in <bibref ref="XML"/>. The work was
completed in the XML Linking Working Group, with the following members active
at the completion of this specification:</p>
<orglist>
<member><name>Peter Chen</name><affiliation>LSU, Bootstrap Alliance</affiliation>
</member>
<member><name>Ron Daniel</name><affiliation>Taxonomy Strategies</affiliation><role>XPointer
co-editor and acting chair</role></member>
<member><name>Steven DeRose</name><affiliation>invited expert</affiliation>
<role>XPointer co-editor</role></member>
<member><name>David Durand</name><affiliation>University of Southhampton,
Dynamic Diagrams</affiliation></member>
<member><name>Masatomo Goto</name><affiliation>Fujitsu Laboratories</affiliation>
</member>
<member><name>Paul Grosso</name><affiliation>Arbortext</affiliation></member>
<member><name>Dmitry Lenkov</name><affiliation>Oracle</affiliation></member>
<member><name>Chris Maden</name><affiliation>Lexica</affiliation></member>
<member><name>Eve Maler</name><affiliation>Sun Microsystems</affiliation>
<role>past co-chair and co-editor</role></member>
<member><name>Jonathan Marsh</name><affiliation>Microsoft</affiliation></member>
<member><name>David Orchard</name><affiliation>Jamcracker</affiliation></member>
<member><name>Henry Thompson</name><affiliation>W3C and University of Edinburgh</affiliation>
<role>co-chair and W3C staff contact</role></member>
<member><name>Daniel Veillard</name><affiliation>invited expert</affiliation>
<role>co-chair</role></member>
</orglist>
<p>The editors wish to acknowledge substantial contributions from Tim Bray,
who previously served as co-editor and co-chair; from James Clark on integration with XPath; from Gavin Nicol and Martin Dürst on
passages related to internationalization; and from Jeni Tennison on the formal definition of document ordering. Finally, we would like to thank
the XML Linking Interest Group and Working Group for their support and input.</p>
</inform-div1>
</back></spec>

