简体   繁体   English

如何使用XSLT生成文本文件

[英]How to generate a text file using XSLT

I want to generate a text format file using XML and XSLT using Java. 我想使用Java使用XML和XSLT生成文本格式文件。

I know how to generate PDF format, but I have no idea about generating text format, ie what packages are needed, what are the changes needed in XSLT? 我知道如何生成PDF格式,但是我不知道如何生成文本格式,即需要哪些软件包,XSLT中需要进行哪些更改?

If anybody can provide the sample for this it would be a great help for me. 如果有人可以为此提供样品,那对我将有很大的帮助。

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 shows how to get the raw text. David M展示了如何获取原始文本。 However, you say you know how to generate PDF. 但是,您说您知道如何生成PDF。 Generating PDF directly from XSLT is a challenge. 直接从XSLT生成PDF是一个挑战。 So perhaps the question means something else. 因此,也许这个问题还有其他含义。

Are you using XSL FO or similar? 您是否正在使用XSL FO或类似产品? 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). 在这种情况下,Apache FOP IIRC(Apache FOP)允许生成格式化的文本以及PDF(尽管可能不太好,并且已经使用了很长时间了)。 Other PDF generating tools may or may not also have a text output option. 其他PDF生成工具可能具有也可能没有文本输出选项。

If you run fop from commandline 如果您从命令行运行fop

fop -fo file.fo -txt file.txt

Or (if this is an embedded FOP) 或者(如果这是嵌入式FOP)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM