Skip to main content

XPathBindingsBuilder

Struct XPathBindingsBuilder 

Source
pub struct XPathBindingsBuilder { /* private fields */ }
Expand description

Builder + XPathBindings impl for caller-supplied namespaces, variables, and extension functions. Cheap to clone (functions are stored in Arc). Pass &builder (or any &dyn XPathBindings) to super::XPathContext::eval_with.

Implementations§

Source§

impl XPathBindingsBuilder

Source

pub fn new() -> XPathBindingsBuilder

Empty builder — start here and chain.

Source

pub fn namespace( &mut self, prefix: impl Into<String>, uri: impl Into<String>, ) -> &mut XPathBindingsBuilder

Bind prefix to uri for QName resolution in the XPath expression’s static context. Mirrors libxml2’s xmlXPathRegisterNs / lxml’s namespaces= kwarg.

Source

pub fn bind_variable( &mut self, name: impl Into<String>, value: Value, ) -> &mut XPathBindingsBuilder

Bind $name to value. XPath references like $name (no prefix) and $prefix:name (prefix resolved against the namespace map) both consult this table.

Method name is bind_variable (not variable) so it doesn’t shadow the XPathBindings::variable trait method on the same type.

Source

pub fn function<F>( &mut self, ns_uri: impl Into<String>, name: impl Into<String>, f: F, ) -> &mut XPathBindingsBuilder
where F: Fn(Vec<Value>) -> Result<Value, XmlError> + Send + Sync + 'static,

Register f to handle ns_uri:name(...) calls. Pass "" as ns_uri to register a function under the default (unprefixed) namespace — that lets name(...) work without a prefix, but is rarely what you want because it can shadow XPath 1.0 built-ins.

Trait Implementations§

Source§

impl Clone for XPathBindingsBuilder

Source§

fn clone(&self) -> XPathBindingsBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for XPathBindingsBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for XPathBindingsBuilder

Source§

fn default() -> XPathBindingsBuilder

Returns the “default value” for a type. Read more
Source§

impl XPathBindings for XPathBindingsBuilder

Source§

fn resolve_prefix(&self, prefix: &str) -> Option<String>

Resolve a namespace prefix to its URI. None means the prefix is undeclared — the engine surfaces that as an XPath error.
Source§

fn variable(&self, name: &str) -> Option<Value>

Look up an XPath variable’s value. None means undefined, which surfaces as an XPath error.
Source§

fn call_function( &self, ns_uri: &str, name: &str, args: Vec<Value>, ) -> Option<Result<Value, XmlError>>

Invoke a registered XPath function. None means the function isn’t registered — the engine falls back to its built-in function table (count(), string(), etc.). An inner Err propagates as the eval result.
Source§

fn call_function_in( &self, ns_uri: &str, name: &str, args: Vec<Value>, _xpath_context_node: usize, ) -> Option<Result<Value, XmlError>>

Like call_function, but also receives the current XPath context node — the node that position()/last() are reporting against and that a no-arg generate-id() / current() would see if the spec sense were “XPath context”, not “XSLT current()”. Default delegates to call_function, dropping the context. XSLT overrides this so generate-id() and friends work in predicate sub-expressions.
Source§

fn function_available_in( &self, _ns_uri: &str, _name: &str, _arity: usize, ) -> bool

Is a function with this expanded name and arity available to call — a registered user xsl:function or extension? Lets fn:function-lookup return the empty sequence for unknown names without invoking anything. Default false.
Source§

fn function_signature_in( &self, _ns_uri: &str, _name: &str, _arity: usize, ) -> Option<FunctionSig>

The declared signature of a user xsl:function with this expanded name and arity, if known — used to apply function subtyping in instance of function(…). None means the signature is unknown (a built-in, an extension, or no such function), in which case the caller falls back to arity-only matching.
Source§

fn castable_as_user_type( &self, _ns_uri: &str, _local: &str, _value: &str, _source_kind: Option<&str>, ) -> Option<bool>

Schema-aware processing: test whether a lexical value is castable to a user-defined (schema) simple type, identified by its expanded name. Some(bool) when the type is known (true = castable); None when no schema is in scope or the type is unknown, in which case the caller treats it as an unrecognized type as before.
Source§

fn cast_to_user_type( &self, _ns_uri: &str, _local: &str, _value: &str, ) -> Option<Result<Value, XmlError>>

Schema-aware processing: cast a lexical value to a user-defined simple type, returning the typed value. None when no schema is in scope or the type is unknown.
Source§

fn instance_of_user_type( &self, _target_ns: &str, _target_local: &str, _value_type: Option<(&str, &str)>, ) -> Option<bool>

Schema-aware processing: is a value whose declared type is value_type (its expanded name, or None if untyped / built-in) an instance of the user-defined target type? None when no schema is in scope or the target type is unknown.
Source§

fn schema_type_exists(&self, _ns: &str, _local: &str) -> bool

Schema-aware processing: does a simple type with this expanded name exist in an in-scope schema? Lets instance of / cast as distinguish “the type is unknown” (XPST0051) from “the type is known but the value isn’t of it” (the operator’s normal false / failure). Default false — no schema in scope.
Source§

fn node_schema_type(&self, _node_id: usize) -> Option<(String, String)>

Schema-aware processing: the expanded name (ns, local) of the schema type that governs the source node node_id, as recorded by validating the source document against the in-scope schema (the post-schema-validation infoset). None when the source wasn’t schema-validated, the node has no annotation, or the governing type is anonymous (no name to report). Callers treat None as “untyped” — today’s behavior.
Source§

fn node_typed_value(&self, _node_id: usize, _lexical: &str) -> Option<Value>

Schema-aware atomization (XPath 2.0 §2.5.2): the typed value of source node node_id, whose string value is lexical, when the node carries a simple-typed schema annotation. Returns the typed atomic (so data($n) instance of xs:integer and arithmetic see the real type). None when the node wasn’t schema-typed or its type has no atomizable typed value — the caller then atomizes to xs:untypedAtomic as before.
Source§

fn xpath_version_2_or_later(&self) -> bool

Is the host an XPath 2.0 (or later) processor? Selects the xs:double/xs:float → string canonical form: 1.0 is decimal-only, 2.0 uses scientific notation outside [1e-6, 1e6) (1.0E6). Only affects typed doubles — integer / decimal output is unchanged. Default false.
Source§

fn load_document( &self, _uri: &str, _base_uri: Option<&str>, ) -> Option<Result<Vec<*const Node<'static>>, XmlError>>

XSLT document(uri[, base]) — load the URI as XML and return the loaded doc’s root as a foreign-node pointer set. base_uri is the base URI of the calling expression (e.g. the stylesheet’s URL); the bindings impl resolves the URI relative to that. None means the bindings don’t support document loading — the engine reports “unknown function” as for any other unrecognized name.
Source§

fn apply_foreign_path( &self, _nodes: &[*const Node<'static>], _predicates: &[Expr], _steps: &[Step], ) -> Option<Result<Vec<*const Node<'static>>, XmlError>>

Evaluate a path expression’s predicates + steps against a foreign-doc node-set. The bindings impl looks up each pointer’s owning doc (compat keeps a registry of docs loaded via document()), grabs that doc’s DocIndex, and re-runs the core engine’s apply_predicates / eval_step_on_nodes against it. Returns the resulting node-set as foreign pointers. None means the bindings don’t support foreign- doc traversal — engine errors out.
Source§

fn static_base_uri(&self) -> Option<String>

Static base URI of the expression’s surrounding XSLT element (XPath 2.0 §C.1). Consulted by fn:resolve-uri($rel) when no explicit base is supplied and by fn:static-base-uri(). Default None means the runtime has no static base URI for this evaluation — resolve-uri then returns its argument unchanged.
Source§

fn node_base_uri(&self, _id: usize) -> Option<String>

XPath 2.0 §3.1.5 base-URI accessor for synthetic nodes the runtime constructs. Default None means “no override” — fn:base-uri then continues walking up the ancestor chain (and ultimately returns the empty sequence). XSLT bindings override this to consult the RTF base-URI table populated when an xsl:variable / xsl:document carrying xml:base materialised a temporary tree.
Source§

fn foreign_string_value(&self, _p: *const Node<'static>) -> String

XPath 1.0 §5 string-value of a foreign-doc node. Core can’t dereference the pointer itself (no unsafe in this crate); the bindings impl (compat) walks the node through libxml2-ABI accessors and returns the concatenated text. Default returns empty string — accurate for the lean build where ForeignNodeSet is unreachable anyway.
Source§

fn load_dynamic_document(&self, _uri: &str) -> Option<Result<usize, XmlError>>

Dynamic-doc loader hook. Invoked by the XSLT document() / XPath 2.0 doc() runtime when the requested URI isn’t in the statically-discovered pre-load map. Implementations resolve the URI through the surrounding Loader, parse the resource, graft it into the active DocIndex via super::DocIndex::graft_dynamic_document, and return the new doc-root NodeId. Read more
Source§

fn regex_dialect(&self) -> Dialect

Which regex dialect to use for fn:matches / fn:replace / fn:tokenize / xsl:analyze-string. The default is crate::regex::Dialect::Xpath (XSLT 3.0 / XPath 3.0 grammar). An XSLT 2.0 host that wants the W3C conformance suite’s stricter rejection of (?:…) overrides this to crate::regex::Dialect::Xpath20.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.