Skip to main content

XPathBindings

Trait XPathBindings 

Source
pub trait XPathBindings {
Show 20 methods // Provided methods fn resolve_prefix(&self, _prefix: &str) -> Option<String> { ... } fn call_function( &self, _ns_uri: &str, _name: &str, _args: Vec<Value>, ) -> Option<Result<Value, XmlError>> { ... } fn call_function_in( &self, ns_uri: &str, name: &str, args: Vec<Value>, _xpath_context_node: NodeId, ) -> Option<Result<Value, XmlError>> { ... } fn function_available_in( &self, _ns_uri: &str, _name: &str, _arity: usize, ) -> bool { ... } fn function_signature_in( &self, _ns_uri: &str, _name: &str, _arity: usize, ) -> Option<FunctionSig> { ... } fn castable_as_user_type( &self, _ns_uri: &str, _local: &str, _value: &str, _source_kind: Option<&str>, ) -> Option<bool> { ... } fn cast_to_user_type( &self, _ns_uri: &str, _local: &str, _value: &str, ) -> Option<Result<Value, XmlError>> { ... } fn instance_of_user_type( &self, _target_ns: &str, _target_local: &str, _value_type: Option<(&str, &str)>, ) -> Option<bool> { ... } fn schema_type_exists(&self, _ns: &str, _local: &str) -> bool { ... } fn node_schema_type(&self, _node_id: NodeId) -> Option<(String, String)> { ... } fn node_typed_value( &self, _node_id: NodeId, _lexical: &str, ) -> Option<Value> { ... } fn variable(&self, _name: &str) -> Option<Value> { ... } fn xpath_version_2_or_later(&self) -> bool { ... } fn load_document( &self, _uri: &str, _base_uri: Option<&str>, ) -> Option<Result<Vec<ForeignNodePtr>, XmlError>> { ... } fn apply_foreign_path( &self, _nodes: &[ForeignNodePtr], _predicates: &[Expr], _steps: &[Step], ) -> Option<Result<Vec<ForeignNodePtr>, XmlError>> { ... } fn static_base_uri(&self) -> Option<String> { ... } fn node_base_uri(&self, _id: NodeId) -> Option<String> { ... } fn foreign_string_value(&self, _p: ForeignNodePtr) -> String { ... } fn load_dynamic_document( &self, _uri: &str, ) -> Option<Result<NodeId, XmlError>> { ... } fn regex_dialect(&self) -> Dialect { ... }
}
Expand description

Caller-supplied resolver for things outside the XPath spec that downstream consumers (libxslt, lxml’s extensions= / variables= / namespaces= kwargs) want to inject:

  • Namespace prefixes used in prefix:local name tests must resolve to a URI somehow — the consumer registers the prefix→URI map and we consult it during eval.
  • User-defined functions like my:foo(bar) need to dispatch to caller-provided code.
  • XPath variables ($varname) need a value source.

All three default to “not provided”; the engine falls through to XPath 1.0 behaviour (error / empty result) when a binding returns None.

Provided Methods§

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 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: NodeId, ) -> 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: NodeId) -> 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: NodeId, _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 variable(&self, _name: &str) -> Option<Value>

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

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<ForeignNodePtr>, 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: &[ForeignNodePtr], _predicates: &[Expr], _steps: &[Step], ) -> Option<Result<Vec<ForeignNodePtr>, 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: NodeId) -> 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: ForeignNodePtr) -> 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<NodeId, 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.

Some(Err(...)) means the URI was understood but couldn’t be resolved (network/IO error, parse error). None means the bindings layer doesn’t support dynamic doc-loading at all — the caller falls back to the legacy “URI not pre-loaded” error so the failure mode is the same as before this hook existed.

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§