Java XSLT transformation problem

Hi,
   I am trying to transform a very large XML document using DOM4J in Java. Here's what I do:

1. Read in the original XML file using SAXReader (reader is a SAXReader object):
Document myDoc = reader.read(new File("very_large_xml_file.xml"))...

2. Pass the Document myDoc to the following function that transforms the file:

public Document stylesheet_trans(Document document, String stylesheet)
            throws Exception
      {
        // load the transformer using JAXP
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer(
            new StreamSource(stylesheet)
        );

        // now lets style the given document
        DocumentSource source = new DocumentSource(document);
        DocumentResult result = new DocumentResult();
        transformer.transform(source, result);

        // return the transformed document
        Document transformedDoc = result.getDocument();
        return transformedDoc;
    }

finally, write the returned Document to a new file:

final_file = new FileWriter("final_transformed_large_xml_file.xml");
returned_doc.write(final_file);

The problem here is, when I opened the final_transformed_large_xml_file.xml in a browser, it tells me that the document is truncated (that is, the transformation process seems unable to handle such a large original file...) -- there is no real problem with the actual tag transformations, but it is just cut off before the end. Can anyone help me with this problem?
NGInterfaceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mightyoneCommented:
try using your own serialisation...

it is not recommenden using Document.write() for documents not opened with document.open

see: http://cafeconleche.org/quotes2005.html
and
depending on input maybe sax is not the right approach
http://cafeconleche.org/books/xmljava/chapters/ch06s07.html
use .eg.
0
mightyoneCommented:
// Serialize the document
      OutputFormat format = new OutputFormat(doc);
      format.setLineWidth(65);
      format.setIndenting(true);
      format.setIndent(2);
      XMLSerializer serializer = new XMLSerializer(System.out, format);
      serializer.serialize(doc);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
>>the transformation process seems unable to handle such a large original file

That seems unlikely. More likely, perhaps, is that the browser can't handle it.

Assuming Windows, issue the command:

type yourfile.xml

and look for the closing tag

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

NGInterfaceAuthor Commented:
Thanks. I adjusted the serializer to conform with the DOM4J's API and it now works!
0
CEHJCommented:
:-)
0
mightyoneCommented:
pleased to help you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.