XML technologies / XPath / XPath 2.0: language reference / XPath expressions: the evaluation context / Dynamic context
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, chapter 4.)
At run time, an XPath expression is evaluated in the dynamic context (evaluation context). Three important components of the dynamic context determine the so-called focus of the XPath expression.
These are the context item (which may also be a node, then called the context node), its context position and the context size. The focus enables the processor to track and thus control processing.
Components of the dynamic context must be valid when accessed. Otherwise, for example if no context item exists when one is accessed, a dynamic error (dynamic error) is reported. This may terminate processing unless it is one of the recoverable errors (recoverable errors). Dynamic errors are also called run-time errors.
Note — Tolerance of potential dynamic errors
A potential dynamic error detected during static analysis need not be reported immediately. The application may wait to see whether the affected expression is actually evaluated at run time. This allows the expression to be guarded appropriately, for example with function-available() or similar mechanisms.
Components of the dynamic context
Components of the dynamic context include the current system time (current date and time) and the location-dependent timezone offset, also obtained from the system clock (implicit timezone). These components depend on the time and geographical location of processing and are dynamic in that sense. However, they remain constant throughout processing and, like the static context, are described as global.
Lists of available external documents and collections also belong to the dynamic context and remain constant at run time (accessible documents, accessible collections). A nonempty list of this kind is a subset of the statically known documents and collections (see above).
Variables defined and bound within XPath expressions are part of the dynamic context. Dynamic variables are bound within for expressions (see sequence expressions); references to the variable must also occur within the same expression.
The focus components primarily include the context node (context node) or, more generally, when an atomic value rather than a node is being processed, the context item (context item).
The size of the current sequence, that is, its number of items, is called the context size (context size). It remains constant while a sequence is processed but changes dynamically when a new current sequence is processed.
The context item changes dynamically as path expressions and their predicates are evaluated. The position of the item currently being processed within the sequence is called the context position (context position). It changes dynamically while the current sequence (current sequence) is processed. The maximum context position equals the current context size.
During an XSLT transformation, XPath’s dynamic context is extended with components used by XSLT functions and instructions. These include:
the current group (current-group) of a grouping instruction
xsl:for-each-groupits current grouping key (current-grouping-key)
the currently captured substring (current-captured-substring) during evaluation of a regular expression, as with instruction
xsl:analyze-string
Compatibility mode also determines evaluation
Whether XPath expressions in the stylesheet are evaluated according to XPath 2.0 rules or in a backward-compatible manner according to XPath 1.0 rules is determined by the XPath 1.0 compatibility mode. This component is set to true when XPath 1.0 backward compatibility must be ensured; otherwise it is false.
Copyright © Galileo Press, Bonn 2008
You may print the online version for private use.
Otherwise, this chapter from "XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch" is subject to the same terms as the bound edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn