You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Daniel Barclay <Da...@digitalfocus.com> on 2000/06/07 22:04:32 UTC

problem?: should XercesLiaison handle entity-reference nodes for DOM input source?


Is XercesLiaison supposed to handle DOM entity-reference nodes?

Or are you supposed to have to call:

  setFeature( "http://apache.org/xml/features/dom/create-entity-ref-nodes", 
              false )

on Xerces' DOMParser when passing its output to Xalan's 
XSLTProcessor.process(...) method?


I used Xerces' DOMParser to parse a document containing an external 
entity into a DOM tree, and used that as the input to Xalan. 

However, Xalan ignore any data in the external entity.  

I looked at the DOM data, and the external entity data was present, 
underneath an explicit representation of the reference to the 
external entity. 

Xalan acted as if it doesn't understand that it should look under
the reference node to get the element subtree underneath.


I did use:

  XSLTProcessorFactory.getProcessorUsingLiaisonName( 
          "org.apache.xalan.xpath.xdom.XercesLiaison" )

to get my instance of XSLTProcessor, per the instructions in the JavaDoc 
method description for XSLTProcessorFactory.getProcessor().

I thought that that would cause XSLTProcessor to correctly process the
external entity, but it still didn't.


Then i tried calling:

  setFeature( "http://apache.org/xml/features/dom/create-entity-ref-nodes", 
              false)

in the parser-calling code.  When I did that, Xalan started processing
the data from the external entity.

It seems that Xalan doesn't understand reference notes, or maybe that
XercesLiaison doesn't handle them for XSLTProcessor.


Is a bug (are XSLTProcessor or XercesLiaison supposed to be handling
this), does Xalan require that reference nodes be simplified, or am
I missing some other setup that I need?


This all with Xalan 1.0.3 and Xerces 1.0.1.

Here (also attached) is my test program:

----------------------------------------------------------------------
import org.apache.xalan.xslt.*;
import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.*;
import org.w3c.dom.*;
import java.io.*;

public class XalanEntityInclusion
{
    static String styleSheet = 
            ""
            + "<xsl:stylesheet \n"
            + "  version=\"1.0\" \n"
            + "  xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" \n"
            + "  > \n"
            + " \n"
            + " <xsl:template match=\"@*|node()\"> \n"
            + "   <xsl:copy> \n"
            + "    <xsl:apply-templates select=\"@*|node()\"/> \n"
            + "   </xsl:copy> \n"
            + " </xsl:template> \n"
            + " \n"
            + "</xsl:stylesheet> \n"
            ;

    static String documentEntity = 
            "" 
            + "<?xml version=\"1.0\"?> \n"
            + "<!DOCTYPE test [ \n"
            + "<!ENTITY extEnt SYSTEM \"extEnt\"> \n"
            + "]> \n"
            + " \n"
            + "<test attr=\"x\">&extEnt;</test> \n"
            ;

    static String externalEntity = 
            "<extEnt></extEnt>";

    static void run( boolean createRefNodes )
        throws IOException,     
               SAXException
    {
        DOMParser parser = new DOMParser();

        parser.setEntityResolver(
            new EntityResolver()
                {
                    public InputSource resolveEntity( String publicId,
                                                      String systemId )
                    {
                        return 
                            new InputSource( 
                                new StringReader( externalEntity ) );
                    } // resolveEntity( ... )
                }
            );

        InputSource documentEntitySource = 
            new InputSource( new StringReader( documentEntity ) );

        parser.setFeature( 
            "http://apache.org/xml/features/dom/create-entity-ref-nodes", 
            createRefNodes );

        parser.parse( documentEntitySource );

        Document document = parser.getDocument();

        XSLTProcessorFactory.
            getProcessorUsingLiaisonName(
                org.apache.xalan.xpath.xdom.XercesLiaison.class.getName()
                );

        XSLTProcessor proc = 
            XSLTProcessorFactory.getProcessorUsingLiaisonName(
                "org.apache.xalan.xpath.xdom.XercesLiaison"
                );
        
        XSLTInputSource documentSource = 
            new XSLTInputSource( document );
        XSLTInputSource styleSource = 
            new XSLTInputSource( new StringReader( styleSheet ) );
        XSLTResultTarget target =
            new XSLTResultTarget( System.err );

        proc.process( documentSource, styleSource, target );


    } // run( ... )

    public static void main( String[] args )
        throws IOException,     
               SAXException
    {
        System.err.println();
        System.err.println( "create-entity-ref-nodes true:" );
        run( true );
        System.err.println();
        System.err.println();
        System.err.println( "create-entity-ref-nodes false:" );
        run( false );
        System.err.println();
    } // main( String[] args )


} // class XalanEntityInclusion
----------------------------------------------------------------------


Daniel

-- 
Daniel Barclay
Digital Focus
Daniel.Barclay@digitalfocus.com