Ecrion Software Inc. Homepage
Forum Home Forum Home > XF Rendering Server > Sample Code
  New Posts New Posts RSS Feed: Java code needed to read/render  the XSL
  FAQ FAQ  Forum Search   Register Register  Login Login

Java code needed to read/render the XSL

 Post Reply Post Reply
Author
Message / View First Unread Post
srivatsahg View Drop Down
Newbie
Newbie
Avatar

Joined: 06 Oct 2010
Location: Stuttgart
Posts: 36
Post Options Post Options   Quote srivatsahg Quote  Post ReplyReply Direct Link To This Post Topic: Java code needed to read/render the XSL
    Posted: 20 Oct 2010 at 3:19am
Hello

I have modified the sample Java snippet provided by Ecrion to my needs. However i get error when i start the transformation using TransformerFactory and i get the error msg as the stylesheet could not be compiled

            String xmlString;
            String xslString;

            File xmlFile = new File("C:/Srivatsa/Reports/Ecrion/DemoReport/Demo.xml");
            File xsltFile = new File("C:/Srivatsa/Reports/Ecrion/DemoReport/Demo.xsl");
           
            xmlString = FileUtils.readFileToString(xmlFile);
            xslString = FileUtils.readFileToString(xsltFile,"utf-8");
           
            InputStream xml = new StringBufferInputStream(xmlString);
            InputStream xslt = new StringBufferInputStream(xslString);
            OutputStream outputStream = new             FileOutputStream("C:\\XSLTransformation.pdf");

            // JAXP reads data using the Source interface
            Source xmlSource = new StreamSource(xml);
            Source xsltSource = new StreamSource(xslt);

            // the factory pattern supports different XSLT processors
            TransformerFactory transFact = TransformerFactory.newInstance();
            Transformer trans = transFact.newTransformer(xsltSource);

            ByteArrayOutputStream xmlResult = new ByteArrayOutputStream();
            trans.transform(xmlSource, new StreamResult(xmlResult));

            InputStream inputStream = new StringBufferInputStream(xmlResult.toString());
           
            Engine eng = new Engine();
            RenderingParameters rp = new RenderingParameters();

            rp.InputFormat = Engine.InputFormat.XSLFO;
            rp.OutputFormat = Engine.OutputFormat.PDF;
       
            eng.Render(inputStream, outputStream, rp);
           
            // remember to close the streams
            inputStream.close();
            outputStream.close();

            System.out.println("Document rendered successfully!");


Any idea where am i going wrong

Vatsa


Back to Top
srivatsahg View Drop Down
Newbie
Newbie
Avatar

Joined: 06 Oct 2010
Location: Stuttgart
Posts: 36
Post Options Post Options   Quote srivatsahg Quote  Post ReplyReply Direct Link To This Post Posted: 20 Oct 2010 at 4:51am
Anyone out there to help me
Back to Top
florinv View Drop Down
Admin Group
Admin Group


Joined: 19 May 2008
Posts: 83
Post Options Post Options   Quote florinv Quote  Post ReplyReply Direct Link To This Post Posted: 21 Oct 2010 at 3:07pm
If you get a stylesheet compilation error, most likely the error is in the XSL file, not in the JAVA code.Try to validate the XSL in XF Designer.
Back to Top
srivatsahg View Drop Down
Newbie
Newbie
Avatar

Joined: 06 Oct 2010
Location: Stuttgart
Posts: 36
Post Options Post Options   Quote srivatsahg Quote  Post ReplyReply Direct Link To This Post Posted: 22 Oct 2010 at 3:46am
The same stylesheet works perfectly from the XF designer. But it does not work when i do it  programmatically. I dont think its a problem with the XSL.



Back to Top
gabig View Drop Down
Admin Group
Admin Group


Joined: 06 Aug 2008
Posts: 144
Post Options Post Options   Quote gabig Quote  Post ReplyReply Direct Link To This Post Posted: 22 Oct 2010 at 4:34am
We have multiple XSLT engines. Are you sure you're using the same in both cases?

In XF Designer, go to the Options dialog, in the XSL Transformations section. Here you can view or change the XSLT engine used by the Designer.

Now in your code, you can choose to let Ultrascale perform the transformation using that engine. Use the XsltEngine rendering parameter to set it.

Use InputFormat.XML instead of XSLFO to pass the XML stream directly to Ultrascale. The idea here is to let Ultrascale manage the transformation as well.

Create a LocalDocumentTemplate from your XSL and set it as the Template parameter. The transformation will be performed client side.

Finally, pass the XML stream as the input for the Engine.Render() method.

Let me know if you encounter any issues.

Regards,
Gabi
Back to Top
srivatsahg View Drop Down
Newbie
Newbie
Avatar

Joined: 06 Oct 2010
Location: Stuttgart
Posts: 36
Post Options Post Options   Quote srivatsahg Quote  Post ReplyReply Direct Link To This Post Posted: 25 Oct 2010 at 3:37am
I still face the same issue...Cry
Could you please send me a snippet of the code which

1. Reads a stylesheet from a file location.
2. Sets the Transformation parameters and
3. sets the parameter for Rendering engine.

Though im sure of points 2 and 3. I am not sure about the Point 1.

Kindly reply
Srivatsa



Back to Top
gabig View Drop Down
Admin Group
Admin Group


Joined: 06 Aug 2008
Posts: 144
Post Options Post Options   Quote gabig Quote  Post ReplyReply Direct Link To This Post Posted: 25 Oct 2010 at 7:08am
Would using a Server Template work for you? It means you would first upload your XFD or XSL template to the server, then let Ultrascale handle the transform server-side.

Also, could you send a sample template to support? Perhaps we can troubleshoot the original issue and see why the template cannot be processed successfully with Java's internal XSL engine.

Regards,
Gabi

Edited by gabig - 25 Oct 2010 at 7:09am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.69
Copyright ©2001-2010 Web Wiz

This page was generated in 0.184 seconds.