DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4995>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4995

Xalan doesn't work with non-document DOM source

           Summary: Xalan doesn't work with non-document DOM source
           Product: XalanJ2
           Version: CurrentCVS
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: org.apache.xalan.transformer
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


If you pass a DOMSource which is not a Document Element as the source document 
to a xalan transformer, nothing ever matches.

This is because in transform(), xalan has the following code:
      try
      {
        this.transformNode(dtm.getDocument());
      }

It gets the Document from the dtm, and applies the transformer to it. However, 
since I didn't pass a document in as the DOMSource, getDocument() returns an 
empty document id (I assume), so xalan thinks the source document is empty.

In the sample code below, "DOM SOURCE 1" fails to work, because it passes an 
Element to the DOMSource

--- START SAMPLE CODE ---
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

import org.w3c.dom.*;
import org.xml.sax.*;

import org.apache.xalan.transformer.*;
import org.apache.xalan.trace.*;

import java.io.*;


public class testit {

    private static String xslt = 
"<xsl:stylesheet "+
"        version=\"1.0\" "+
"        xmlns:TEST=\"TESTURI\""+
"        xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\""+
"        xmlns:xalan=\"http://xml.apache.org/xalan\";>"+
"        <xsl:output method=\"xml\" version=\"1.0\" encoding=\"UTF-8\" 
indent=\"no\"/>"+

"        <!-- main template -->"+
"        <xsl:template match=\"/TEST:actions\">"+
"                <MATCHED/>"+
"        </xsl:template>"+
"</xsl:stylesheet>";

    private static String xmlText =
"<TEST:actions xmlns:TEST=\"TESTURI\"/>";

    public static void main(String[] args) 
        throws Throwable {

        // create a new DocumentBuilder
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance
();
        docFactory.setNamespaceAware(true);
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        // Create a new TransformerFactory
        TransformerFactory tFactory = TransformerFactory.newInstance();

        // Create a new transformer
        Templates templates = tFactory.newTemplates(new StreamSource(new 
StringReader(xslt)));
        Transformer transformer = templates.newTransformer();

        // Create a new DOM document
        Document srcDoc = docBuilder.newDocument();
        Element el = srcDoc.createElementNS("TESTURI", "actions");
        srcDoc.appendChild(el);

        // create sources
        DOMSource domSource1 = new DOMSource(srcDoc.getDocumentElement());
        DOMSource domSource2 = new DOMSource(srcDoc);
        StreamSource textSource = new StreamSource(new StringReader(xmlText));

        // Transform it!
        System.out.println("DOM SOURCE1: ");
        transformer.transform(domSource1, new StreamResult(System.out));
        System.out.println();
        
        // Transform it!
        System.out.println("DOM SOURCE2: ");
        transformer.transform(domSource2, new StreamResult(System.out));
        System.out.println();

        // Transform it!
        System.out.println("STREAM SOURCE: ");
        transformer.transform(textSource, new StreamResult(System.out));
        System.out.println();
    }
}
--- END SAMPLE CODE ---


--- START SAMPLE OUTPUT ---
DOM SOURCE1: 
<?xml version="1.0" encoding="UTF-8"?>

DOM SOURCE2: 
<?xml version="1.0" encoding="UTF-8"?>
<MATCHED xmlns:xalan="http://xml.apache.org/xalan"; xmlns:TEST="TESTURI"/>

STREAM SOURCE: 
<?xml version="1.0" encoding="UTF-8"?>
<MATCHED xmlns:xalan="http://xml.apache.org/xalan"; xmlns:TEST="TESTURI"/>

--- END SAMPLE OUTPUT ---

Reply via email to