tags:

views:

150

answers:

5

I want to generate a text format file using XML and XSLT using Java.

I know how to generate PDF format, but I have no idea about generating text format, i.e. what packages are needed, what are the changes needed in XSLT?

If anybody can provide the sample for this it would be a great help for me.

+4  A: 

You just need an:

<xsl:output method="text" omit-xml-declaration="yes" />

element, and then just output text from your templates. No package needed.

David M
A: 

i tried with this but i m getting some unexpected format..:( Please help

Tried what with what? If you are responding to an answer do so in a comment on that answer, not by adding another answer; the order of answers isn't fixed and can be changed by the user, so it's impossible to work out what you're replying to.
NickFitz
+1  A: 

David M shows how to get the raw text. However, you say you know how to generate PDF. Generating PDF directly from XSLT is a challenge. So perhaps the question means something else.

Are you using XSL FO or similar? In that case, IIRC, the Apache FOP allows generating formatted text as well as PDF (although perhaps not very well, not looked at it for ages). Other PDF generating tools may or may not also have a text output option.

Tom Hawtin - tackline
A: 

@tom-hawtin-tackline Yes , i am using XSL FO and i want to generate ".txt" file as output.

I mentioned it wrongly, so sorry for that.

Please provide solution for the same.

A: 

If you run fop from commandline

fop -fo file.fo -txt file.txt

Or (if this is an embedded FOP)

Fop fop = fopFactory.newFop(MimeConstants.MIME_PLAIN_TEXT, out);
Peter Lindqvist