[jdom-interest] JDOM + XSLT solution

himank gupta h_i_m_a_n_k at yahoo.com
Mon Oct 3 23:30:35 PDT 2005


hi guys 

 

 i was able to do the transformation with the following code....

 

 

 

 public Document transform(Document sourceDoc, File stylesheetFile)
 {


     TransformerFactory transformerFactory = TransformerFactory.newInstance();
   Templates stylesheet = transformerFactory.newTemplates(new StreamSource(stylesheetFile));
     Transformer processor = stylesheet.newTransformer();
 

     //A holder for an XML Transformation source: a Document, Element, or list of nodes.
     JDOMSource source = new JDOMSource(sourceDoc);


    // A holder for an XSL Transformation result,
      JDOMResult result = new JDOMResult();

   

     processor.transform(source, result);

     Document newDoc = result.getDocument();

   

     // Display the results
     FileOutputStream resultOut = new FileOutputStream("c:\\out.html");
     XMLOutputter outp = new XMLOutputter();
     outp.output(newDoc, resultOut);

     return(newDoc);
 }

 

CHANGES from the previous apporach

 

-- i used Stream Result in place of JDOM Result

-- outputting the document after processing


i was able to have the new Document because JDOMResult let me do it.

StreamResult does not help me with this.

 

PREVIOUS CODE::

 

   // Set up the XSLT stylesheet for use with Xalan-J 2
   TransformerFactory transformerFactory = TransformerFactory.newInstance();
   Templates stylesheet = transformerFactory.newTemplates(new StreamSource(stylesheetFile));
   Transformer processor = stylesheet.newTransformer();
  
  //Take input Stream
   FileInputStream sourceIn = new FileInputStream(new File("c:\\javaxml\\contents.xml"));
   StreamSource source = new StreamSource(sourceIn);
   
  //Make Output Stream
   FileOutputStream resultOut = new FileOutputStream(new File("c:\\out.html"));
   StreamResult result = new StreamResult(resultOut);
   processor.transform(source, result);

 

Please suggest if someone was able to do it with StreamResult.

 



		
---------------------------------
Yahoo! for Good
 Click here to donate to the Hurricane Katrina relief effort. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20051003/694c4674/attachment.htm


More information about the jdom-interest mailing list