pub struct DocIndex<'doc> {
pub nodes: Vec<INode<'doc>>,
/* private fields */
}Fields§
§nodes: Vec<INode<'doc>>Implementations§
Source§impl<'doc> DocIndex<'doc>
impl<'doc> DocIndex<'doc>
Sourcepub fn build(doc: &'doc ArenaDoc) -> Self
pub fn build(doc: &'doc ArenaDoc) -> Self
Build a flat index over doc. O(n) in the number of nodes.
Sourcepub fn add_document(&mut self, doc: &'doc ArenaDoc) -> NodeId
pub fn add_document(&mut self, doc: &'doc ArenaDoc) -> NodeId
Append another document’s tree to this index, returning the
NodeId of the new synthetic Document node. Used to make
runtime-loaded documents (e.g. via the XSLT document()
function or XInclude resolution) addressable through the
same XPath index as the primary source.
The added doc must outlive 'doc — typically achieved by
owning it in a Vec<Box<Document>> that lives at least as
long as the index.
Sourcepub fn string_value(&self, id: NodeId) -> String
pub fn string_value(&self, id: NodeId) -> String
XPath 1.0 § 5 string value of a node.
pub fn node_name(&self, id: NodeId) -> &str
pub fn local_name(&self, id: NodeId) -> &str
pub fn namespace_uri(&self, id: NodeId) -> &str
pub fn namespace_prefix(&self, id: NodeId) -> Option<&str>
Source§impl<'doc> DocIndex<'doc>
impl<'doc> DocIndex<'doc>
Sourcepub fn allocate_rtf_text_nodes_inherent(
&self,
values: Vec<String>,
) -> Vec<NodeId> ⓘ
pub fn allocate_rtf_text_nodes_inherent( &self, values: Vec<String>, ) -> Vec<NodeId> ⓘ
Allocate one synthetic text node per supplied string and
return their NodeIds in document order. Used by EXSLT
functions like str:tokenize, str:split, and
regexp:match that need to materialise a node-set of
strings without an XSLT-engine RTF arena to host them.
The nodes are top-level — they have no parent and no
document — but every DocIndexLike accessor handles them
correctly so callers can iterate the result with
xsl:for-each, take their string-value, count them, etc.
Their IDs sort after every real node-set node, so unions
stay totally ordered.
Source§impl<'doc> DocIndex<'doc>
impl<'doc> DocIndex<'doc>
Sourcepub fn start_rtf(&self) -> RtfBuilder
pub fn start_rtf(&self) -> RtfBuilder
Begin building a new result-tree fragment. Returns an
RtfBuilder that knows its
eventual host-vector slot — callers populate it via
add_document / add_element / etc., then hand it back to
finish_rtf.
Sourcepub fn mark_synthetic_wrap(&self, root: NodeId)
pub fn mark_synthetic_wrap(&self, root: NodeId)
Mark root (an RTF document-root NodeId) as the synthetic
wrap of a sequence-typed XSLT binding. See
synthetic_wraps for the rationale.
Sourcepub fn is_synthetic_wrap(&self, id: NodeId) -> bool
pub fn is_synthetic_wrap(&self, id: NodeId) -> bool
True when id is a synthetic doc-wrap created for
sequence-typed binding storage rather than a real source /
XSLT document tree root. Used by XTDE1270 / XTDE1370 /
XTDE1380 to refuse the wrap as a document for the purposes
of fn:key / fn:unparsed-entity-uri and friends.
Sourcepub fn finish_rtf(&self, builder: RtfBuilder) -> NodeId
pub fn finish_rtf(&self, builder: RtfBuilder) -> NodeId
Freeze a populated builder into the host vector. Returns the globally-encoded id of the RTF’s document node so the caller can bind a variable directly to it.
Sourcepub fn rtf_node_type(&self, id: NodeId) -> Option<(String, String)>
pub fn rtf_node_type(&self, id: NodeId) -> Option<(String, String)>
Governing type (ns, local) recorded for a constructed RTF node,
if it was built with a type= / xsl:type= annotation.
Sourcepub fn graft_dynamic_document(&self, doc: &Document) -> NodeId
pub fn graft_dynamic_document(&self, doc: &Document) -> NodeId
Graft a fully-parsed sup_xml_tree::dom::Document into the
index at runtime, returning the node id of its synthetic
document root. Used by XSLT 2.0 doc() / XSLT 1.0
document() to resolve URIs computed at apply time (rather
than statically discovered at compile time).
The grafted doc reuses the super::rtf storage: every
node’s data is copied into the RTF’s append-only nodes
table so the caller can drop the source [Document] right
after the call. XPath operations on the returned node id
dispatch through the same RTF accessors that XSLT-built
result-tree fragments use. Bytes-for-bytes structural
fidelity is preserved (PIs, comments, attributes,
namespace declarations); doc-level XSD typing and unparsed-
entity metadata are not — the spec leaves those undefined
for doc()-loaded resources.
Trait Implementations§
Source§impl<'doc> DocIndexLike for DocIndex<'doc>
impl<'doc> DocIndexLike for DocIndex<'doc>
Source§fn graft_dynamic_document(&self, doc: &Document) -> Option<NodeId>
fn graft_dynamic_document(&self, doc: &Document) -> Option<NodeId>
sup_xml_tree::dom::Document into the index
at runtime, returning the node id of its synthetic document
root. Concrete DocIndex implementations use the same
append-only RTF storage that XSLT result-tree fragments use,
so the call needs only &self; stub implementations (test
shims) return None to fall back to the legacy
“URI not pre-loaded” error path in document_fn.Source§fn children(&self, id: NodeId) -> &[NodeId] ⓘ
fn children(&self, id: NodeId) -> &[NodeId] ⓘ
attr_range).Source§fn parent(&self, id: NodeId) -> Option<NodeId>
fn parent(&self, id: NodeId) -> Option<NodeId>
None for the synthetic Document node (id 0).Source§fn attr_range(&self, id: NodeId) -> Range<NodeId>
fn attr_range(&self, id: NodeId) -> Range<NodeId>
Source§fn ns_range(&self, id: NodeId) -> Range<NodeId>
fn ns_range(&self, id: NodeId) -> Range<NodeId>
namespace:: axis traverses.
One per distinct in-scope prefix (own + inherited, with
closer declarations shadowing) plus the implicit xml
prefix. Empty for non-elements. Default impl returns an
empty range; the arena index materialises these eagerly
during build.Source§fn kind(&self, id: NodeId) -> XPathNodeKind
fn kind(&self, id: NodeId) -> XPathNodeKind
Source§fn pi_target(&self, id: NodeId) -> &str
fn pi_target(&self, id: NodeId) -> &str
XPathNodeKind::PI; returns ""
for other kinds.Source§fn string_value(&self, id: NodeId) -> String
fn string_value(&self, id: NodeId) -> String
Source§fn node_name(&self, id: NodeId) -> &str
fn node_name(&self, id: NodeId) -> &str
prefix:local) — element / attribute / PI; "" otherwise.Source§fn local_name(&self, id: NodeId) -> &str
fn local_name(&self, id: NodeId) -> &str
Source§fn namespace_prefix(&self, id: NodeId) -> Option<&str>
fn namespace_prefix(&self, id: NodeId) -> Option<&str>
"dc"),
or None when the node has no namespace or is the default
namespace. Default impl returns None; types that carry
namespace info (the arena index) override.Source§fn namespace_uri(&self, id: NodeId) -> &str
fn namespace_uri(&self, id: NodeId) -> &str
"" otherwise.Source§fn is_element(&self, id: NodeId) -> bool
fn is_element(&self, id: NodeId) -> bool
kind(id) == Element.Source§fn allocate_rtf_text_nodes(&self, values: Vec<String>) -> Option<Vec<NodeId>>
fn allocate_rtf_text_nodes(&self, values: Vec<String>) -> Option<Vec<NodeId>>
NodeIds. Used by EXSLT functions
(str:tokenize, str:split, regexp:match) that need to
return a node-set of computed strings without an XSLT-engine
RTF arena to host them. Default returns None — the index
implementation doesn’t support runtime allocation. Indexes
that do (the arena DocIndex) override to return the new
IDs in document order.Source§fn rtf_builder(&self) -> Option<RtfBuilder>
fn rtf_builder(&self) -> Option<RtfBuilder>
RtfBuilder]. The builder’s
add_document / add_element / add_text / add_attribute
API populates a fresh tree; callers hand it back to
finish_rtf to publish the resulting
RtfIndex into the arena. Default returns None — indexes
without arena storage (test shims, foreign-doc wrappers) can
signal “no RTF construction support” here. The concrete arena
DocIndex overrides to return a real builder.Source§fn finish_rtf(&self, builder: RtfBuilder) -> Option<NodeId>
fn finish_rtf(&self, builder: RtfBuilder) -> Option<NodeId>
RtfBuilder] into the arena, returning
the global id of the synthetic document root. Mirrors
rtf_builder; default returns None.Source§fn rtf_node_type(&self, id: NodeId) -> Option<(String, String)>
fn rtf_node_type(&self, id: NodeId) -> Option<(String, String)>
(ns, local) of a constructed RTF
node built with a type= / xsl:type= annotation, if any.
Default None — indexes without RTF type tracking report every
constructed node as untyped.Source§fn is_synthetic_wrap(&self, id: NodeId) -> bool
fn is_synthetic_wrap(&self, id: NodeId) -> bool
id is a synthetic RTF doc-wrap that holds the
items of a sequence-typed XSLT binding rather than a real
XML / XSLT document tree. Used by XSLT’s XTDE1270 / XTDE1370
/ XTDE1380 to refuse the wrap as a document root when the
spec asks for the “root of the tree containing the context
node”. Default false — index shims without sequence-typed
binding support never produce such wraps.Source§fn is_id_attribute(&self, attr_id: NodeId) -> bool
fn is_id_attribute(&self, attr_id: NodeId) -> bool
attr_id is a DTD-declared ID-type attribute or
matches the xml:id convention. Default returns true for
any attribute whose local name is id (libxml2’s de facto
behaviour); indexes built from documents with DTDs override
to consult the parsed <!ATTLIST … ID> declarations.Source§fn is_idref_attribute(&self, attr_id: NodeId) -> bool
fn is_idref_attribute(&self, attr_id: NodeId) -> bool
attr_id is a DTD-declared IDREF/IDREFS-type
attribute. Unlike ID there is no DTD-less convention, so the
default returns false; indexes built from documents with DTDs
override to consult the parsed <!ATTLIST … IDREF> declarations.
Consulted by XPath 2.0 §14.5.5’s idref().