pub struct DynamicContext<'a, N: DomNavigator> {
pub static_context: &'a XPathContext<'a>,
pub context_item: Option<XmlItem<N>>,
pub context_position: usize,
pub context_size: usize,
pub current_datetime: Option<DateTimeValue>,
pub implicit_timezone: Option<TimezoneOffset>,
pub base_uri: Option<String>,
pub variables: VarStore<XPathValue<N>>,
/* private fields */
}Expand description
XPath 2.0 dynamic context for expression evaluation.
The dynamic context provides runtime information:
- Current context item (node or atomic value)
- Context position and size (for predicates)
- Variable bindings (indexed by VarSlotId)
- Current date/time (stable for duration of query)
- Implicit timezone
Fields§
§static_context: &'a XPathContext<'a>Reference to the static context
context_item: Option<XmlItem<N>>Current context item (if any)
context_position: usizeCurrent context position (1-based)
context_size: usizeCurrent context size
current_datetime: Option<DateTimeValue>Current date/time (stable for entire query evaluation)
implicit_timezone: Option<TimezoneOffset>Implicit timezone
base_uri: Option<String>Base URI for resolving relative URIs
variables: VarStore<XPathValue<N>>Variable bindings (indexed by VarSlotId from NameBinder)
Implementations§
Source§impl<'a, N: DomNavigator> DynamicContext<'a, N>
impl<'a, N: DomNavigator> DynamicContext<'a, N>
Sourcepub fn new(static_context: &'a XPathContext<'a>, var_count: usize) -> Self
pub fn new(static_context: &'a XPathContext<'a>, var_count: usize) -> Self
Create a new dynamic context with the given static context.
The var_count should be NameBinder::len() after binding.
Sourcepub fn with_context_item(self, item: XmlItem<N>) -> Self
pub fn with_context_item(self, item: XmlItem<N>) -> Self
Set the context item.
Sourcepub fn with_context_node(self, node: N) -> Self
pub fn with_context_node(self, node: N) -> Self
Set the context node.
Sourcepub fn with_position(self, position: usize, size: usize) -> Self
pub fn with_position(self, position: usize, size: usize) -> Self
Set context position and size (for predicate evaluation).
Sourcepub fn with_current_datetime(self, dt: DateTimeValue) -> Self
pub fn with_current_datetime(self, dt: DateTimeValue) -> Self
Set the current date/time.
Sourcepub fn with_implicit_timezone(self, tz: TimezoneOffset) -> Self
pub fn with_implicit_timezone(self, tz: TimezoneOffset) -> Self
Set the implicit timezone.
Sourcepub fn require_context_item(&self) -> Result<&XmlItem<N>, XPathError>
pub fn require_context_item(&self) -> Result<&XmlItem<N>, XPathError>
Get the context item, returning an error if undefined.
Sourcepub fn require_context_node(&self) -> Result<&N, XPathError>
pub fn require_context_node(&self) -> Result<&N, XPathError>
Get the context node, returning an error if undefined or not a node.
Returns XPTY0020 if the context item is not a node (per XPath 2.0 spec for axis steps).
Sourcepub fn get_variable(&self, slot: VarSlotId) -> Option<&XPathValue<N>>
pub fn get_variable(&self, slot: VarSlotId) -> Option<&XPathValue<N>>
Get a variable value by slot ID.
Sourcepub fn set_variable(&mut self, slot: VarSlotId, value: XPathValue<N>)
pub fn set_variable(&mut self, slot: VarSlotId, value: XPathValue<N>)
Set a variable value.
Sourcepub fn with_function_evaluator(
self,
evaluator: &'a dyn FunctionEvaluator<N>,
) -> Self
pub fn with_function_evaluator( self, evaluator: &'a dyn FunctionEvaluator<N>, ) -> Self
Set the function evaluator for custom function support.
Sourcepub fn function_evaluator(&self) -> &dyn FunctionEvaluator<N>
pub fn function_evaluator(&self) -> &dyn FunctionEvaluator<N>
Get the function evaluator, using built-in functions as default.
Returns a reference to the configured evaluator, or BuiltinEvaluator if none set.
Sourcepub fn has_custom_evaluator(&self) -> bool
pub fn has_custom_evaluator(&self) -> bool
Check if a custom function evaluator is configured.
Sourcepub fn eval_function(
&mut self,
handle: FunctionHandle,
args: Vec<XPathValue<N>>,
) -> Result<XPathValue<N>, XPathError>
pub fn eval_function( &mut self, handle: FunctionHandle, args: Vec<XPathValue<N>>, ) -> Result<XPathValue<N>, XPathError>
Evaluate a function using the configured evaluator.
This method exists to work around borrow checker issues with calling
self.function_evaluator().eval(handle, self, args) where the evaluator
borrow conflicts with the mutable self borrow.