Skip to main content

resolve_xpointer

Function resolve_xpointer 

Source
pub fn resolve_xpointer<'a>(
    sub_doc: &'a Document,
    expr: &str,
    href: &str,
) -> Result<Vec<&'a Node<'a>>>
Expand description

Resolve an XPointer expression against an included document, returning the element/document nodes selected, in document order.

This is the XInclude § 4.2 fragment-selector subset, shared by the pure-Rust engine and the libxml2-compat C-ABI XInclude path. Supports the three forms most commonly seen in practice; anything else returns a validation error so the caller can fall back to xi:fallback (or fail loudly rather than splice the wrong content):

  • xpointer(EXPR)EXPR is parsed as XPath 1.0 and evaluated against the included document. The resulting nodeset is returned in document order. Empty nodeset is an error (no nodes → can’t splice anything).
  • element(/N1/N2/...) — the ChildSequence scheme. Walk from the document root, picking the Nth element-typed child at each step (1-based). XInclude § 4.2 / XPointer ChildSequence.
  • element(NAME) / element(NAME/N1/...) — start with the element whose id attribute is NAME, then optionally walk a ChildSequence from there.
  • NAME (bare ID) — shorthand for element(NAME).