This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Problem with SimpleTransform servlet


I created a very simple static method that allows you to pass in the source
XML, transform XSL, and target XML file name and it will do this for you
using Saxon or Xalan (I recommend Saxon..much faster). That be helpful for
you? Then you don't need to create another servlet, you just call the static
transform method from your first servlet.


> -----Original Message-----
> From: Karen Fox [mailto:kfox@mitre.org]
> Sent: Thursday, October 18, 2001 12:25 PM
> To: XSL List
> Subject: [xsl] Problem with SimpleTransform servlet
> 
> 
> I'm using the Xalan SimpleTransform servlet to transform an XML file
> into another XML file.  It appears to be working as far as 
> creating the
> new file, but all it writes is the header data.  The rest is blank and
> the file appears to be open because I can't delete it without 
> restarting
> JRun.
> 
> I'm using Xalan 2.1.0 and the SimpleTransform code is below.  We
> modified it slightly so we could call it from another servlet.
> 
> // Imported TraX classes
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.stream.StreamSource;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.TransformerException;
> import javax.xml.transform.TransformerConfigurationException;
> 
> 
> // Imported java classes
> import java.io.FileOutputStream;
> import java.io.FileNotFoundException;
> import java.io.IOException;
> 
> /**
>  *  Use the TraX interface to perform a transformation in the simplest
> manner possible
>  *  (3 statements).
>  */
> public class SimpleTransform2
> {
>         public static void main(String args[])
>         {
>         }
> 
>         public void transform(String xmlFile, String xslFile, String
> outFile)
>     throws TransformerException, TransformerConfigurationException, 
>            FileNotFoundException, IOException
>   {  
> 
>         System.out.println("Entering transform");
>   // Use the static TransformerFactory.newInstance() method to
> instantiate 
>   // a TransformerFactory. The javax.xml.transform.TransformerFactory 
>   // system property setting determines the actual class to 
> instantiate
> --
>   // org.apache.xalan.transformer.TransformerImpl.
>         TransformerFactory tFactory = 
> TransformerFactory.newInstance();
>         
>         // Use the TransformerFactory to instantiate a 
> Transformer that
> will
> work with  
>         // the stylesheet you specify. This method call also processes
> the
> stylesheet
>   // into a compiled Templates object.
>         Transformer transformer = tFactory.newTransformer(new
> StreamSource(xslFile));
> 
>         // Use the Transformer to apply the associated 
> Templates object
> to an
> XML document
>         // (foo.xml) and write the output to a file (foo.out).
>         transformer.transform(new StreamSource(xmlFile), new
> StreamResult(new
> FileOutputStream(outFile)));
>         
>         //System.out.println("************* The result is in 
> " + outFile
> +
> "*************");
>   }
> }
> 
> This is all that prints out:
> <?xml version="1.0" encoding="UTF-8"?>
> <ROWSET xmlns:fo="http://www.w3.org/1999/XSL/Format"/>
> 
> I'd appreciate any suggestions of what else I can try to fix this. 
> Thank you.
> 
> Karen Fox
> The MITRE Corporation
> kfox@mitre.org
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]