> If that's the case, then why did Stefano's case fail?  His input files
> caused Xalan to try to insert a single text node under the Document
> node, which was disallowed.

Because he is going out to a DOM, instead of a stream.  Assaf reminded me
of DocumentFragment.  So with either his or my FormatterListener classes,
you can create the text node that way.  Here's a sample:

import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xalan.xslt.XSLTProcessorFactory;
import org.apache.xalan.xpath.xml.FormatterToDOM;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.xml.sax.SAXException;

/**
 * Simple sample code to show how to run the XSL processor
 * to create a document fragment that can hold a single
 * Text output node.
 */
public class transform
{
     public static void main(String[] args)
    throws org.xml.sax.SAXException
     {
    Document dfactory = new org.apache.xerces.dom.DocumentImpl();
    DocumentFragment frag = dfactory.createDocumentFragment();
    FormatterToDOM handler = new FormatterToDOM(dfactory, frag);
    XSLTProcessorFactory.getProcessor().process(new XSLTInputSource
("foo.xml"),
                      new XSLTInputSource("foo.xsl"),
                      new XSLTResultTarget(handler));

    System.out.println( frag.getFirstChild().getNodeValue() );
     }
}

-scott





Reply via email to