Element e1 = new Element("a:a", "urn:a");
Element e2 = new Element("a:b", "urn:a");
e1.appendChild(e2);
Canonicalizer canonicalizer = new Canonicalizer(out,
Canonicalizer.EXCLUSIVE_XML_CANONICALIZATION_WITH_COMMENTS);
XPathContext context = new XPathContext("a", "urn:a");
Document doc = new Document(e1);
canonicalizer.write(doc.query("(//. | //@* | //namespace::*)[ancestor-or-self::a:b]", context));
String s = out.toString("UTF8");
assertEquals("<a:b xmlns:a=\"urn:a\"></a:b>", s);