You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2002/11/09 08:21:23 UTC

DO NOT REPLY [Bug 14406] New: - Calling to nodelist() in TraceListener changed transformation output

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

Calling to nodelist()  in TraceListener changed transformation output

           Summary: Calling to nodelist()  in TraceListener changed
                    transformation output
           Product: XalanJ2
           Version: 2.4
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Critical
          Priority: Other
         Component: org.apache.xpath
        AssignedTo: xalan-dev@xml.apache.org
        ReportedBy: cxing@borland.com


Here is a simple test program.

import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import org.apache.xalan.trace.*;
import org.w3c.dom.*;


public class tracetest {
  public tracetest(String xml, String xslt) {
    TransformerFactory tFactory = TransformerFactory.newInstance();
    try {
      Transformer transformer = tFactory.newTransformer(new StreamSource
(xslt));
      ((org.apache.xalan.transformer.TransformerImpl)
transformer).getTraceManager().addTraceListener(new TestTraceListener());
      transformer.transform(new StreamSource(xml), new StreamResult
(System.out));
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  public static void main(String[] args) {
    if (args.length != 2) {
      System.out.println("java tracetest xml-file xslt-file");
      System.exit(1);
    }
    new tracetest(args[0], args[1]);
  }
}


class TestTraceListener implements TraceListener {
  public void trace(TracerEvent ev)
  {

  }
   public void selected(SelectionEvent ev) throws 
javax.xml.transform.TransformerException {
     NodeList nl = ev.m_selection.nodelist();
   }
   public void generated(GenerateEvent ev) {

   }
}

With or without the line
NodeList nl = ev.m_selection.nodelist();
will change Xalan's behaviour dramatically.

Xalan 2.4.1: With calling to nodelist(), for-each select nothing, without that 
calling, evereything works fine.
Xalan 2.2.x: With calling to nodelist(), for-each select twice of each node, 
without that calling, evereything works fine.
The method nodelist() should be READ-ONLY, should not change any state in the 
transformaer.

Here is the test XML file:

<?xml version="1.0"?>
<!DOCTYPE XmlEmployees SYSTEM "Employees.dtd">
<XmlEmployees>
	<XmlEmployee>
		<EmpNo>2</EmpNo>
		<FirstName>Robert</FirstName>
		<LastName>Nelson</LastName>
		<PhoneExt>250</PhoneExt>
		<HireDate>1988-12-28</HireDate>
		<DeptNo>600</DeptNo>
		<JobCode>VP</JobCode>
		<JobGrade>2</JobGrade>
		<JobCountry>USA</JobCountry>
		<Salary>105900.000000</Salary>
		<FullName>Nelson, Robert</FullName>
	</XmlEmployee>
	<XmlEmployee>
		<EmpNo>4</EmpNo>
		<FirstName>Bruce</FirstName>
		<LastName>Young</LastName>
		<PhoneExt>233</PhoneExt>
		<HireDate>1988-12-28</HireDate>
		<DeptNo>621</DeptNo>
		<JobCode>Eng</JobCode>
		<JobGrade>2</JobGrade>
		<JobCountry>USA</JobCountry>
		<Salary>97500.000000</Salary>
		<FullName>Young, Bruce</FullName>
	</XmlEmployee>
	<XmlEmployee>
		<EmpNo>5</EmpNo>
		<FirstName>Kim</FirstName>
		<LastName>Lambert</LastName>
		<PhoneExt>22</PhoneExt>
		<HireDate>1989-02-06</HireDate>
		<DeptNo>130</DeptNo>
		<JobCode>Eng</JobCode>
		<JobGrade>2</JobGrade>
		<JobCountry>USA</JobCountry>
		<Salary>102750.000000</Salary>
		<FullName>Lambert, Kim</FullName>
	</XmlEmployee>
</XmlEmployees>


Here is the XSLT file.

<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:java="http://xml.apache.org/xslt/java"
exclude-result-prefixes="java">
<xsl:output method="xml" indent="yes"/>
<xsl:output encoding="ISO-8859-1"/>
<xsl:strip-space elements="*"/>


<xsl:template match="/">
  <html>
    <head>
    <xsl:element name="title">EmployeesList View</xsl:element>
   <a> <img alt="" border="0" height="64" src="images/jbuilder.gif" 
width="64"/> </a>
    </head>

    <body>
      <xsl:element name="h1">List of Employees</xsl:element>
      <xsl:element name = "table">
        <xsl:attribute name="border">2</xsl:attribute>
        <xsl:attribute name="bgColor">#FF8040</xsl:attribute>
        <xsl:attribute name="cellPadding">3</xsl:attribute>
        <xsl:attribute name="cellSpacing">3</xsl:attribute>
        <xsl:attribute name="frame">box</xsl:attribute>
        <xsl:attribute name="bordercolor">black</xsl:attribute>
        <xsl:attribute name="rules">all</xsl:attribute>
        <tr BGCOLOR = "Yellow">
         
<th>Name</th><th>Emp_No</th><th>Dept_No</th><th>Extension</th><th>Hire_Date</th
><th>Salary($)</th>
         <th>Code</th><th>Grade</th><th>Country</th>
        </tr>

        <xsl:for-each select="XmlEmployees/XmlEmployee">
          <xsl:sort select="EmpNo"/>
            <tr>
            <xsl:element name="td">
                    <xsl:value-of select="FullName"/>
            </xsl:element>


          <xsl:element name="td">
                  <xsl:value-of select="EmpNo"/>
          </xsl:element>


          <xsl:element name="td">
                  <xsl:value-of select="DeptNo"/>
          </xsl:element>


          <xsl:element name="td">
                  <xsl:value-of select="PhoneExt"/>
          </xsl:element>


          <xsl:element name="td">
                  <xsl:value-of select="HireDate"/>
          </xsl:element>


          <xsl:element name="td">
                  <xsl:value-of select="Salary"/>
          </xsl:element>


          <xsl:element name="td">
                  <xsl:value-of select="JobCode"/>
          </xsl:element>


          <xsl:element name="td">
                  <xsl:value-of select="JobGrade"/>
          </xsl:element>


          <xsl:element name="td">
                  <xsl:value-of select="JobCountry"/>
          </xsl:element>
        </tr>
        </xsl:for-each>
     </xsl:element>
    </body>
</html>
</xsl:template>
</xsl:stylesheet>