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
impl XPathBindingsBuilder
Sourcepub fn new() -> XPathBindingsBuilder
pub fn new() -> XPathBindingsBuilder
Empty builder — start here and chain.
Sourcepub fn namespace(
&mut self,
prefix: impl Into<String>,
uri: impl Into<String>,
) -> &mut XPathBindingsBuilder
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.
Sourcepub fn bind_variable(
&mut self,
name: impl Into<String>,
value: Value,
) -> &mut XPathBindingsBuilder
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.
Sourcepub fn function<F>(
&mut self,
ns_uri: impl Into<String>,
name: impl Into<String>,
f: F,
) -> &mut XPathBindingsBuilder
pub fn function<F>( &mut self, ns_uri: impl Into<String>, name: impl Into<String>, f: F, ) -> &mut XPathBindingsBuilder
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
impl Clone for XPathBindingsBuilder
Source§fn clone(&self) -> XPathBindingsBuilder
fn clone(&self) -> XPathBindingsBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for XPathBindingsBuilder
impl Debug for XPathBindingsBuilder
Source§impl Default for XPathBindingsBuilder
impl Default for XPathBindingsBuilder
Source§fn default() -> XPathBindingsBuilder
fn default() -> XPathBindingsBuilder
Source§impl XPathBindings for XPathBindingsBuilder
impl XPathBindings for XPathBindingsBuilder
Source§fn resolve_prefix(&self, prefix: &str) -> Option<String>
fn resolve_prefix(&self, prefix: &str) -> Option<String>
None means the prefix
is undeclared — the engine surfaces that as an XPath error.Source§fn variable(&self, name: &str) -> Option<Value>
fn variable(&self, name: &str) -> Option<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>>
fn call_function( &self, ns_uri: &str, name: &str, args: Vec<Value>, ) -> Option<Result<Value, XmlError>>
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>>
fn call_function_in( &self, ns_uri: &str, name: &str, args: Vec<Value>, _xpath_context_node: usize, ) -> Option<Result<Value, XmlError>>
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
fn function_available_in( &self, _ns_uri: &str, _name: &str, _arity: usize, ) -> bool
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>
fn function_signature_in( &self, _ns_uri: &str, _name: &str, _arity: usize, ) -> Option<FunctionSig>
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>
fn castable_as_user_type( &self, _ns_uri: &str, _local: &str, _value: &str, _source_kind: Option<&str>, ) -> Option<bool>
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>>
fn cast_to_user_type( &self, _ns_uri: &str, _local: &str, _value: &str, ) -> Option<Result<Value, XmlError>>
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>
fn instance_of_user_type( &self, _target_ns: &str, _target_local: &str, _value_type: Option<(&str, &str)>, ) -> Option<bool>
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
fn schema_type_exists(&self, _ns: &str, _local: &str) -> bool
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)>
fn node_schema_type(&self, _node_id: usize) -> Option<(String, String)>
(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>
fn node_typed_value(&self, _node_id: usize, _lexical: &str) -> Option<Value>
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
fn xpath_version_2_or_later(&self) -> bool
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>>
fn load_document( &self, _uri: &str, _base_uri: Option<&str>, ) -> Option<Result<Vec<*const Node<'static>>, XmlError>>
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>>
fn apply_foreign_path( &self, _nodes: &[*const Node<'static>], _predicates: &[Expr], _steps: &[Step], ) -> Option<Result<Vec<*const Node<'static>>, XmlError>>
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>
fn static_base_uri(&self) -> Option<String>
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>
fn node_base_uri(&self, _id: usize) -> Option<String>
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
fn foreign_string_value(&self, _p: *const Node<'static>) -> String
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>>
fn load_dynamic_document(&self, _uri: &str) -> Option<Result<usize, XmlError>>
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 moreSource§fn regex_dialect(&self) -> Dialect
fn regex_dialect(&self) -> Dialect
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.