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=14691>.
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=14691

Transformation with xalan does not yield correct results when trace used

           Summary: Transformation with xalan does not yield correct results
                    when trace used
           Product: XalanJ2
           Version: 2.4
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: org.apache.xalan.trace
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


I am using xalan 2.4.1 and when I use tracing, the transformation output is has 
only elements with most of them having no data. When I just turn the tracing 
off, the transformation again works correctly.


Sample code as follows:

--------------------------------------------------------------------------------
//Inputs: tracefilename - filename for trace file
//        xslFileName   - xsl filename
//        xmlStr        - XML input string


String xslFileName=null;
String traceFileName = null;

FileWriter traceFileWriter = null;
PrintWriter tracePrintWriter = null;
PrintTraceListener printTraceListener = null;


//Set transformer system property
Properties props = System.getProperties();
props.put 
("javax.xml.transform.TransformerFactory", "org.apache.xalan.xsltc.trax.Transfor
merFactoryImpl");
System.setProperties(props);


// Set up a PrintTraceListener object to print to a file.
try {
        traceFileWriter = new FileWriter(traceFileName, true);
}
catch (IOException ioe) {
        throw new CxXsltTransformationException("IOException: Creating trace 
file \"" + traceFileName + "\"" + ioe);
}

tracePrintWriter = new PrintWriter(traceFileWriter);
printTraceListener = new PrintTraceListener(tracePrintWriter);
// Print information as each node is 'executed' in the stylesheet.
printTraceListener.m_traceElements = true;
// Print information after each result-tree generation event.
printTraceListener.m_traceGeneration = true;
// Print information after each selection event.
printTraceListener.m_traceSelection = true;
// Print information whenever a template is invoked.
printTraceListener.m_traceTemplates = true;



//COMPILE

Templates templates = null;

try {
        // Get an input stream for the XSL stylesheet
        StreamSource stylesheet = new StreamSource(xslFileName);
        // The TransformerFactory will compile the stylesheet and
        // put the translet classes inside the Templates object
        TransformerFactory factory = TransformerFactory.newInstance();
        templates = factory.newTemplates(stylesheet);

}
catch (TransformerConfigurationException tce) {
        throw new CxXsltTransformationException
("TransformerConfigurationException: Processing XSL Source \"" + xslFileName 
+ "\" Into Templates- " + tce);
}



//TRANSFORM with trace

StringWriter xmlWriter = null;

try {
        StreamSource document = new StreamSource( new StringReader(xmlStr) );
        xmlWriter = new StringWriter();
        StreamResult result = new StreamResult(xmlWriter);
        Transformer transformer = templates.newTransformer();

        tracePrintWriter.println((new Date()).toString() +"XML String Before 
Transformation = \"" + xmlStr + "\"" );

        if (transformer instanceof TransformerImpl) {
            
                TransformerImpl transformerImpl = (TransformerImpl)transformer;
                // Register the TraceListener with the TraceManager associated 
with the TransformerImpl.
                TraceManager traceMgr = transformerImpl.getTraceManager();
                try {
                        traceMgr.addTraceListener(printTraceListener);
                }
                catch (TooManyListenersException tmle) {
                        throw new CxXsltTransformationException(printstr 
+ "TooManyListenersException: Adding trace listener." + tmle);
                }
        } else {
                System.out.println(printstr + "WARNING: Transformer not of type 
TransformerImpl. Tracing not possible.");
        }
                transformer.transform(document, result);
}
catch (TransformerConfigurationException tce) {
        throw new CxXsltTransformationException
("TransformerConfigurationException: Creating transformer from existing 
template - " + tce);
                
}
catch (TransformerException te) {
        throw new CxXsltTransformationException("TransformerException: 
Transforming XML string \"" + xmlStr + "\" Using existing template - " + te);
}


//END

Reply via email to