File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

report writing using XML

 
Anuj Anand
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been asked to read an XML file and generate a report output .For e.g just like reports generated out of Client server architecture . I wanted to ask that what would be the best way for that and whether we can use any report writing tools along with a XML parser.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both XSLT Transformations with static stylesheets (XSL) and dynamic output generation using parsers are viable solutions to your problem.
However, doing it using a parser may not be the most efficient way since a parser "strips off" the XML document into atomic pieces and you need to put them together again!! A parser was never intended to be used for this purpose. On the other hand, an XSLT transformation walks through the XML tree transforming each node into some output format.
I am not sure if there are any specific report generation tools compatible with XML documents. Even if there are some, they will be using XSLT transformations behind the screens. So to get started with your assignment, finalize on the structure of your XML documents( get the DTD if it is available, ) get the required output format and start writing the XSL.
Cheers!
Ajith
 
Anuj Anand
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ajith
Well the structure of the doucment will not be fixed .However the XML needs to act like a transformation engine .For e.g the report structure on one day can be
<AMOUNT>
<PREMIUM>400<PREMIUM>
<RATE>600<RATE>
</AMOUNT>
Lets say report strucure is
Premium Rate Total
400 600 24000
The next day i get a different input file say
<AMOUNT>
<TOTAL1>500</TOTAL1>
<TOTAL2>500</TOTAL2>
</AMOUNT>

So report can be like
TOTAL1 TOTAL2 TOTAL3
500 500 250000
Also there should be provision for sorting,order by etc all conditions .I was thinking of an idea that for sorting and order by, i enter that variable in input file .Then using that variable and the input file,the XML input file and using the parser i dynamically generate the report which could be infact an HTML .Since my knowledge of XMl is limited i wanted to ensure whether this could be done
thanks

 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anuj, for report generating tools you can check http://www.xmlsoftware.com - a lot of free (and not so free ) software available.
To add something to what Ajith already said. XSLT, the language, has two remarkable features:
1) your XSLT program can be data-driven. It means you do not have to specify a path to walk the tree, instead, you can provide a set of templates (generic or specific ones) and your templates will be applied depending on what data in an XML document are
2) introspection functions, such as name() which output current node name.
By combining these features, we can build very flexible XSLT programs to process XML documents of almost any structure. For example, this XSLT
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="AMOUNT">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="node()">
<xsl:value-of select="name()"/>: <xsl:value-of select="." /><br/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
Being applied to your first XML, outputs:
PREMIUM: 400
RATE: 600
And the same XSLT being fed your second document produces:
TOTAL1: 500
TOTAL2: 500

XSLT can change processing logic dynamically, based on either information in input XML document or input parameters, so your idea about putting an variable for sorting in an input file will work. It is a bit tricky, though. There is an idiom to achieve dynamic sorting:
<xsl:variable name="sortFields" select=�your field here� />
<xsl:sort select=�*[name(.)=$sortFields]">
and, as far as I can understand, there is performance penalty for such �dynamics�, but it can be done.
Of course, all this can be achieved with DOM/Java also, so you have a choice. My personal opinion is that for this class of tasks you can be more productive using XSLT than using DOM � after you become comfortable with XSLT, the language. If you all you need is to quickly process a couple of files and you are initially more comfortable with DOM, then XSLT can bring too much learning overhead. In long run XSLT is worth to bury yourself in.
[This message has been edited by Mapraputa Is (edited May 18, 2001).]
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some Chinese painter said: �when I paint the Nature, there is no me, it�s the Nature who paints herself through my brush�. That�s what XSLT is about.
Sorry for being too philosophical, it�s Friday night...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic