You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Desrochers, Jean-Cedric(STL)" <je...@express-scripts.com> on 2000/10/27 22:11:52 UTC

Process problem with Xalan-J 1.2

Hi,

Recently I downloaded the latest and greatest version of Xalan-J.  I did
some simple test to see if this new version was creating any problem in our
application. At my big surprise... BOUM!!!!

I tried a very basic example; to transform an XML document to generate an
HTML document. What use to generate the HTML document now throws this
exception:

XSL Error: Cannot use a DTMLiaison for a input DOM node... pass a
org.apache.xalan.xpath.xdom.XercesLiaison instead!
XSL Error: SAX Exception
org.apache.xalan.xslt.XSLProcessorException:
  	at
org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1756)
 	at
org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1648)
 	at
org.apache.xalan.xslt.XSLTEngineImpl.getSourceTreeFromInput(XSLTEngineImpl.j
ava:876)
 	at
org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:600) 
	...


Does anybody know if I do something wrong here?  With Xerces 1.2 and Xalan-J
1.2-D01 it works fine but if I try with Xalan-J 1.2 it blows.... 

Here's the java code of my little test :


// Import of Sun's JDK classes
// ---------------------------
import java.io.StringReader;
import java.io.StringWriter;
import java.io.IOException;

// Import of Xalan and Xerces classes
// ----------------------------------
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTProcessor;
import org.apache.xalan.xslt.XSLTProcessorFactory;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xerces.parsers.DOMParser;

// Import of DOM and SAX interfaces
// --------------------------------
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;


/**
 *
 *
 */
public class HtmlGenerationTest {

    /** The Xerces DOM Parser */
    private static final DOMParser theDomParser = new DOMParser();

    /** The Xalan XSLT Processor */
    private static final XSLTProcessor theXsltProcessor;
    static {
        try {
                theXsltProcessor = XSLTProcessorFactory.getProcessor();
        } catch (SAXException se) {
            throw new InternalError("Unable to get the XSLT Processor!");
        }
    }

    public String process() {
        try {
            // Creating the XML data input source
            InputSource anXmlSource = new InputSource(new
StringReader(getXmlData()));
            theDomParser.parse(anXmlSource);
            Document anXMLDocument = theDomParser.getDocument();
            XSLTInputSource anXMLInputSource = new
XSLTInputSource(anXMLDocument);

            // Creating the XSLT Stylesheet input source
            InputSource anXsltSource = new InputSource(new
StringReader(getXsltStylesheet()));
            theDomParser.parse(anXsltSource);
            Document anXSLTStylesheet = theDomParser.getDocument();
            XSLTInputSource anXsltInputSource = new
XSLTInputSource(anXSLTStylesheet);

            // Creating the result object that will contain the output
            XSLTResultTarget aResultTarget = new XSLTResultTarget(new
StringWriter(1000));

            // Process the XML data and the XSLT stylesheet together
            theXsltProcessor.process(anXMLInputSource, anXsltInputSource,
aResultTarget);

            return aResultTarget.getCharacterStream().toString();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (SAXException se) {
            se.printStackTrace();
        }

        return "";
    }

    private String getXmlData() {
        StringBuffer aDataBuffer = new StringBuffer(500);
        aDataBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        aDataBuffer.append("<correspondence_data>\n");
        aDataBuffer.append("    <paragraph>For your convenience, this is
just a test by J-C on Thu Oct 26 13:16:14 CDT 2000.</paragraph>");
        aDataBuffer.append("    <paragraph>Thank you.</paragraph>");
        aDataBuffer.append("</correspondence_data>");

        return aDataBuffer.toString();
    }

    private String getXsltStylesheet() {
        StringBuffer aStylesheetBuffer = new StringBuffer(2000);
        aStylesheetBuffer.append("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>");
        aStylesheetBuffer.append("<xsl:stylesheet version=\"1.0\"
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">");
        aStylesheetBuffer.append("<xsl:output method=\"html\"
omit-xml-declaration=\"yes\"/>");
        aStylesheetBuffer.append("<xsl:output method=\"html\"
omit-xml-declaration=\"yes\"/>");
        aStylesheetBuffer.append("    <xsl:template match=\"/\">");
        aStylesheetBuffer.append("        <HTML>");
        aStylesheetBuffer.append("            <HEAD>");
        aStylesheetBuffer.append("                <TITLE>Letter
Preview</TITLE>");
        aStylesheetBuffer.append("            </HEAD>");
        aStylesheetBuffer.append("            <BODY>");
        aStylesheetBuffer.append("            <xsl:apply-templates
select=\"//paragraph\"/>");
        aStylesheetBuffer.append("            </BODY>");
        aStylesheetBuffer.append("        </HTML>");
        aStylesheetBuffer.append("    </xsl:template>");
        aStylesheetBuffer.append("    <xsl:template match=\"paragraph\">");
        aStylesheetBuffer.append("        <P><xsl:value-of
select=\"text()\"/></P>");
        aStylesheetBuffer.append("    </xsl:template>");
        aStylesheetBuffer.append("</xsl:stylesheet>");

        return aStylesheetBuffer.toString();
    }

    public static void main(String[] args) {
        HtmlGenerationTest aTest = new HtmlGenerationTest();
        String anHtmlContent = aTest.process();
        System.out.println(anHtmlContent);
    }
}