Jasper Reports xml formating

Posted on 2007-07-22
Last Modified: 2013-11-18
Hello experts.
I need to format jasper XML report.
I am using
                              _printFile, _builtReport + ".xml", false);

to generate the xml report and it produces this type of output:      
 <jasperPrint name="Report" pageWidth="1000" pageHeight="100000" orientation="Landscape">
- <page>
- <text lineSpacingFactor="1.3578125" leadingOffset="-3.1972656" runDirection="LTR" textHeight="0" hyperlinkType="None" hyperlinkTarget="Self" bookmarkLevel="0">
  <reportElement x="238" y="0" width="528" height="23" forecolor="#003399" />
- <textContent>
- <![CDATA[ Referral Report

How can I format the report so it has Report as a root element?. I'd like other elements from detail section to be subelements of elements contained in columnHeader, or at least group them somehow and clear all that unnessesary pageWidth and orientation attributes and remove 'page' element...?
Question by:olenadmytrenko
    LVL 17

    Expert Comment

    by:Dejan Pažin

    You can always use XSLT to transform the original xml into format you need.

    You can use Xalan for that:

    Author Comment

    Thanks for that.
    To get an associated stylesheet I have to do this:

    / 2a. Get the stylesheet from the XML source.
    String media = null , title = null, charset = null;
    javax.xml.transform.Source stylesheet = tFactory.getAssociatedStylesheet
                       (new StreamSource("foo.xml"), media, title, charset);

    My XML documents doesn't have a stylesheet attached though.. Is it possible to specify an external stylesheet?
    LVL 17

    Accepted Solution

    Added below are the basic steps taken from You simply state your source and xsl file.

    // 1. Instantiate a TransformerFactory.
    javax.xml.transform.TransformerFactory tFactory =

    // 2. Use the TransformerFactory to process the stylesheet Source and
    //    generate a Transformer.
    javax.xml.transform.Transformer transformer = tFactory.newTransformer

    // 3. Use the Transformer to transform an XML Source and send the
    //    output to a Result object.
         new new

    Or, you can also use commandline tool:

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now