weft-xml 0.2.1

XPath 3.1, XQuery 3.1 and XSLT 3.0 in Rust: a command and the libraries under it, tested on the W3C suites
//! docs/usage.md's stylesheet example (crates/xml/tests/docs.rs holds the two
//! to one text): one compiled stylesheet, several documents.
//!
//!     cargo run -p weft-xml --example compile_once

use xdm::{arena::TreeArena, rt::Item, Document, XdmError};
use xpath_ir::ctx::Dyn;
use xpath_ir::xslt::transform::{run, strip, Invocation};
use xpath_ir::xslt::{compile_text, Resources};

/// What xsl:import, xsl:include and document() may read: here, nothing.
struct NoFiles;
impl Resources for NoFiles {
    fn read(&self, _uri: &str) -> Option<Vec<u8>> {
        None
    }
}
static NO_FILES: NoFiles = NoFiles;

fn main() -> Result<(), XdmError> {
    let text = r#"<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
      <xsl:output omit-xml-declaration="yes"/>
      <xsl:template match="/"><n><xsl:value-of select="sum(//@n)"/></n></xsl:template>
    </xsl:stylesheet>"#;
    let sheet = compile_text(text, "file:///sum.xsl", &NO_FILES)?;
    for source in ["<d><i n='1'/><i n='2'/></d>", "<d><i n='40'/><i n='2'/></d>"] {
        let arena = TreeArena::new(); // holds the source and every tree the run makes
        let mut context = Dyn::empty();
        context.arena = Some(&arena);
        let document: &Document = arena.alloc(Document::parse(source)?);
        let root = strip(&sheet, document, &context).root_ref(); // xsl:strip-space
        let outcome = run(&sheet, &context, Invocation { source: Some(Item::Node(root)), ..Invocation::default() })?;
        let tree = outcome.tree.expect("a principal result");
        println!("{}", xpath_ir::serfn::serialize_document_checked(&tree, &outcome.params)?);
    }
    Ok(())
}