Expand description
Document and Node implementation using XDMTree
// First create a XDMTreeNode from the source XML
let src = from("<MyTest>This is the source document</MyTest>").expect("unable to parse source XML");
// Make this an [Item]
let isrc = Rc::new(Item::Document(Rc::new(src.get_doc())));
// Parse the XSL stylesheet
let style = from("<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='/'>It works!</xsl:template>
</xsl:stylesheet>").expect("unable to parse XSL stylesheet");
let istyle = Rc::new(style.get_doc());
// Setup dynamic context with result document
let sc = StaticContext::new_with_xslt_builtins();
let rd: XDMTree = Rc::new(RefCell::new(StableGraph::new()));
XDMTreeNode::new(rd.clone());
let dc = from_document(istyle, &rd, &sc).expect("failed to compile stylesheet");
// Prime the stylesheet evaluation by finding the template for the document root
// and making the document root the initial context
let t = dc.find_match(&isrc);
// Now evaluate the Sequence Constructor
// with the source document as the initial context
let seq = evaluate(&dc, Some(vec![isrc]), Some(0), &t).expect("evaluation failed");
assert_eq!(seq.to_string(), "It works!");