You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by xa...@xml.apache.org on 2004/09/04 19:16:38 UTC

[jira] Updated: (XALANJ-1671) Transformation produces different results with DOM and Stream sources

The following issue has been updated:

    Updater: Brian Minchau (mailto:minchau@ca.ibm.com)
       Date: Sat, 4 Sep 2004 10:15 AM
    Changes:
             assignee changed from Xalan Developers Mailing List
             description changed from When a node being used in the tranformation is empty the DOMSource and Stream 
source produce different results. For example - 

Input Xml - 
-------------------------
<Root>
<SampleData attr1="" attr2="b" attr3="c" />
</Root>
-------------------------

XSL - 
-------------------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:output method="xml" indent="yes" xalan:indent-amount="4" 
xmlns:xalan="http://xml.apache.org/xslt"/>
<xsl:template match="SampleData">
<SampleData>
    <attr1><xsl:value-of select="@attr1" /> </attr1>
    <attr2><xsl:value-of select="@attr2" /> </attr2>
    <attr3><xsl:value-of select="@attr3" /> </attr3>
</SampleData>

</xsl:template>

</xsl:stylesheet>
-------------------------

Transformer class - 
-------------------------
import java.io.*;
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.*;

public class SampleTransform
{
	public static void main(String[] args) throws  Exception
  {  
    String sampleFileName="sample-input-data.xml";

	TransformerFactory tFactory = TransformerFactory.newInstance();
    DocumentBuilder builder = DocumentBuilderFactory.newInstance
().newDocumentBuilder();
    InputSource inputSource = new InputSource(new FileReader(sampleFileName));
    Document document = builder.parse(inputSource);
    document.normalize();
    DOMSource domSource = new DOMSource();
    domSource.setNode(document);

    // Create the transformer
	Transformer transformer = tFactory.newTransformer(new StreamSource
("sample-transform.xsl"));


    
    // transform the input xml using stream source
	transformer.transform(new StreamSource(sampleFileName),
            new StreamResult(new FileOutputStream("output-using-stream.out")));

    // transform the input xml using dom source
	transformer.transform(domSource, new StreamResult(new FileOutputStream
("output-dom.out")));
	
	System.out.println("check output files output-dom.out and output-
stream.out");
  }
}
-------------------------


The output using the stream source is - 

-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<SampleData>
    <attr1/>
    <attr2>b</attr2>
    <attr3>c</attr3>
</SampleData>
-------------------------

Output using the dom source is 

-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<SampleData>
    <attr1>
    </attr1>
    <attr2>b</attr2>
    <attr3>c</attr3>
</SampleData>

-------------------------

Please note the extra new line character in the "attr1" element. The dom source 
and stream source should produce the same output. However, in the case shown 
about, this does not happen. Is this a bug? to When a node being used in the tranformation is empty the DOMSource and Stream 
source produce different results. For example - 

Input Xml - 
-------------------------
<Root>
<SampleData attr1="" attr2="b" attr3="c" />
</Root>
-------------------------

XSL - 
-------------------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:output method="xml" indent="yes" xalan:indent-amount="4" 
xmlns:xalan="http://xml.apache.org/xslt"/>
<xsl:template match="SampleData">
<SampleData>
    <attr1><xsl:value-of select="@attr1" /> </attr1>
    <attr2><xsl:value-of select="@attr2" /> </attr2>
    <attr3><xsl:value-of select="@attr3" /> </attr3>
</SampleData>

</xsl:template>

</xsl:stylesheet>
-------------------------

Transformer class - 
-------------------------
import java.io.*;
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.*;

public class SampleTransform
{
	public static void main(String[] args) throws  Exception
  {  
    String sampleFileName="sample-input-data.xml";

	TransformerFactory tFactory = TransformerFactory.newInstance();
    DocumentBuilder builder = DocumentBuilderFactory.newInstance
().newDocumentBuilder();
    InputSource inputSource = new InputSource(new FileReader(sampleFileName));
    Document document = builder.parse(inputSource);
    document.normalize();
    DOMSource domSource = new DOMSource();
    domSource.setNode(document);

    // Create the transformer
	Transformer transformer = tFactory.newTransformer(new StreamSource
("sample-transform.xsl"));


    
    // transform the input xml using stream source
	transformer.transform(new StreamSource(sampleFileName),
            new StreamResult(new FileOutputStream("output-using-stream.out")));

    // transform the input xml using dom source
	transformer.transform(domSource, new StreamResult(new FileOutputStream
("output-dom.out")));
	
	System.out.println("check output files output-dom.out and output-
stream.out");
  }
}
-------------------------


The output using the stream source is - 

-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<SampleData>
    <attr1/>
    <attr2>b</attr2>
    <attr3>c</attr3>
</SampleData>
-------------------------

Output using the dom source is 

-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<SampleData>
    <attr1>
    </attr1>
    <attr2>b</attr2>
    <attr3>c</attr3>
</SampleData>

-------------------------

Please note the extra new line character in the "attr1" element. The dom source 
and stream source should produce the same output. However, in the case shown 
about, this does not happen. Is this a bug?
             environment changed from Operating System: All
Platform: PC to Operating System: All
Platform: PC
             priority changed to Blocker
             Component changed to DOM
             Component changed from Xalan
    ---------------------------------------------------------------------
For a full history of the issue, see:

  http://issues.apache.org/jira/browse/XALANJ-1671?page=history

---------------------------------------------------------------------
View the issue:
  http://issues.apache.org/jira/browse/XALANJ-1671

Here is an overview of the issue:
---------------------------------------------------------------------
        Key: XALANJ-1671
    Summary: Transformation produces different results with DOM and Stream sources
       Type: Bug

     Status: Unassigned
   Priority: Blocker

    Project: XalanJ2
 Components: 
             DOM
   Versions:
             2.5

   Assignee: 
   Reporter: Abhilash Koneri

    Created: Fri, 26 Sep 2003 7:40 PM
    Updated: Sat, 4 Sep 2004 10:15 AM
Environment: Operating System: All
Platform: PC

Description:
When a node being used in the tranformation is empty the DOMSource and Stream 
source produce different results. For example - 

Input Xml - 
-------------------------
<Root>
<SampleData attr1="" attr2="b" attr3="c" />
</Root>
-------------------------

XSL - 
-------------------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:output method="xml" indent="yes" xalan:indent-amount="4" 
xmlns:xalan="http://xml.apache.org/xslt"/>
<xsl:template match="SampleData">
<SampleData>
    <attr1><xsl:value-of select="@attr1" /> </attr1>
    <attr2><xsl:value-of select="@attr2" /> </attr2>
    <attr3><xsl:value-of select="@attr3" /> </attr3>
</SampleData>

</xsl:template>

</xsl:stylesheet>
-------------------------

Transformer class - 
-------------------------
import java.io.*;
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.*;

public class SampleTransform
{
	public static void main(String[] args) throws  Exception
  {  
    String sampleFileName="sample-input-data.xml";

	TransformerFactory tFactory = TransformerFactory.newInstance();
    DocumentBuilder builder = DocumentBuilderFactory.newInstance
().newDocumentBuilder();
    InputSource inputSource = new InputSource(new FileReader(sampleFileName));
    Document document = builder.parse(inputSource);
    document.normalize();
    DOMSource domSource = new DOMSource();
    domSource.setNode(document);

    // Create the transformer
	Transformer transformer = tFactory.newTransformer(new StreamSource
("sample-transform.xsl"));


    
    // transform the input xml using stream source
	transformer.transform(new StreamSource(sampleFileName),
            new StreamResult(new FileOutputStream("output-using-stream.out")));

    // transform the input xml using dom source
	transformer.transform(domSource, new StreamResult(new FileOutputStream
("output-dom.out")));
	
	System.out.println("check output files output-dom.out and output-
stream.out");
  }
}
-------------------------


The output using the stream source is - 

-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<SampleData>
    <attr1/>
    <attr2>b</attr2>
    <attr3>c</attr3>
</SampleData>
-------------------------

Output using the dom source is 

-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<SampleData>
    <attr1>
    </attr1>
    <attr2>b</attr2>
    <attr3>c</attr3>
</SampleData>

-------------------------

Please note the extra new line character in the "attr1" element. The dom source 
and stream source should produce the same output. However, in the case shown 
about, this does not happen. Is this a bug?


---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.

If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa

If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org