Okay, Brad. I understand the problem now. Sorry, I'm a little slow on this, trying to do 18 million things at once here.
You are passing $body into your extension function. $body is a Result Tree Fragment (RTF) as defined in the XSLT recommendation. Since you only have one method called addPage, the XalanJ extension mechanism recognizes that it can map the RTF into a java String and successfully call your extension method. To map the RTF into a String, the XalanJ extension mechanism effectively calls the XPath string() function. This basically returns the concatenation of all text node descendants of the RTF, which is exactly what you're seeing. The solution here is to specify the signature of your addPage method as: public void addPage(String ident, org.w3c.dom.traversal.NodeIterator body)
