Java XSLT transformation problem

   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 = 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");

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?
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.

try using your own serialisation...

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

depending on input maybe sax is not the right approach
use .eg.
// Serialize the document
      OutputFormat format = new OutputFormat(doc);
      XMLSerializer serializer = new XMLSerializer(System.out, format);

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
>>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

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!
pleased to help you
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

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.