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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! README.md's library example (crates/xml/tests/docs.rs holds the two to
//! one text): a stylesheet's text over a document's text.
//!
//!     cargo run -p weft-xml --example transform

use xpath_ir::xslt::transform::transform_text;

fn main() {
    let stylesheet = r#"<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
      <xsl:template match="/"><out><xsl:value-of select="count(//i)"/></out></xsl:template>
    </xsl:stylesheet>"#;
    // the last argument names an initial template, for a run with no source
    match transform_text(stylesheet, Some("<d><i/><i/></d>"), None) {
        Ok(result) => println!("{result}"),
        Err(code) => eprintln!("{code}"), // a W3C error code, such as XTDE0640
    }
}