简体   繁体   English

为什么XSL-FO很受欢迎?

[英]Why is XSL-FO popular?

I'm going to create a converter from html to some format. 我将创建一个从html转换为某种格式的转换器。 I'm thinking to use intermediate format XML(XSL-FO). 我正在考虑使用中间格式XML(XSL-FO)。

My question: Why is FO format popular if not so many applications render it? 我的问题:如果没有那么多应用程序呈现它,为什么FO格式很受欢迎?

I am well aware that there's a big debate going on between CSS and XSL-FO supporters, and both sides have valid and good points. 我很清楚CSS和XSL-FO支持者之间正在进行一场激烈的辩论,双方都有有效和优点。

Here's the best brief argument for XSL-FO that I've seen so far: 这是迄今为止我见过的XSL-FO的最佳简要论点:

XSL-FO provides a more sophisticated visual layout model than HTML+CSS. XSL-FO提供了比HTML + CSS更复杂的可视化布局模型。 Formatting supported by XSL-FO, but not supported by HTML+CSS, includes right-to-left and top-to-bottom text, footnotes, margin notes, page numbers in cross-references, and more. XSL-FO支持但HTML + CSS不支持的格式包括从右到左和从上到下的文本,脚注,边距注释,交叉引用中的页码等。 In particular, while CSS (Cascading Style Sheets) is primarily intended for use on the Web, XSL-FO is designed for broader use. 特别是,虽然CSS(层叠样式表)主要用于Web,但XSL-FO的设计目的更广泛。 You should, for instance, be able to write an XSL style sheet that uses formatting objects to lay out an entire printed book. 例如,您应该能够编写一个使用格式化对象来布置整个印刷书籍的XSL样式表。 A different style sheet should be able to transform the same XML document into a Web site. 不同的样式表应该能够将同一XML文档转换为Web站点。

(Source: http://www.cafeconleche.org/books/bible2/chapters/ch18.html ) (来源: http//www.cafeconleche.org/books/bible2/chapters/ch18.html

Here are some arguing XSL-FO is superior: 以下是一些争论XSL-FO是优越的:

While here some say CSS is better: 虽然这里有人说CSS更好:

Both RenderX and Antenna House make excellent XSLFO->PDF renderers. RenderXAntenna House都制作出色的XSLFO-> PDF渲染器。 There is also the free [Apache FOP] renderer, which is good enough for many projects. 还有免费的[Apache FOP]渲染器,这对许多项目来说已经足够了。 It takes a serious effort in order to fully support FO in all its gory details; 为了全面支持FO的所有细节,需要认真努力; perhaps the bar to entry is too high based on the size of the market, the established players, and the potential return. 根据市场规模,既定参与者和潜在回报,或许进入的门槛太高了。

Not that you asked, but before you do too much work on FO to HTML , there are a couple of free choices which might save you some effort. 不是你问的,但是在你对FO做过多的HTML工作之前,有几个免费的选择可能会省你一些努力。

Did you check the Ecrion XSL-FO engine? 你检查过Ecrion XSL-FO引擎了吗? By boss chose it because it supports a lot of output formats (PDF, Word, PowerPoint, Postscript, HTML and a very cool Silverlight output mode) and it has an incredible designer (which to my knowledge is the only one that can work with other formatting engines, including FOP). 老板之所以选择它是因为它支持很多输出格式(PDF,Word,PowerPoint,Postscript,HTML和非常酷的Silverlight输出模式),它有一个令人难以置信的设计师(据我所知,这是唯一一个可以与其他人合作的设计师)格式化引擎,包括FOP)。 The problem with using HTML to generate PDF is that: 使用HTML生成PDF的问题是:

  • HTML doesn't let you control the pagination (like have different layouts on even/odd pages, just like a book or a catalog). HTML不允许您控制分页(就像在偶数/奇数页面上有不同的布局,就像书或目录一样)。
  • You can't control headers and footers. 您无法控制页眉和页脚。
  • There are no instructions for creating page number citations, footnotes, insert the page count, and countless of other things a printable publication may have. 没有关于创建页码引用,脚注,插入页数以及可打印出版物可能具有的无数其他内容的说明。

Advanced engines like Ecrion, Antenna and Renderx are also able to generate high quality PDF output (like PDF/A for archiving or PDF/X for printing). Ecrion,Antenna和Renderx等高级引擎也能够生成高质量的PDF输出(如用于存档的PDF / A或用于打印的PDF / X)。

XSL-FO is a common standard that tool implementers can follow to ensure compatibility, in the same way that HTML is the common standard for web pages, XSL is the standard for XML-to-* translation, etc. XSL-FO是工具实现者可以遵循的通用标准,以确保兼容性,就像HTML是网页的通用标准一样,XSL是XML到*翻译的标准等。

If your HTML can be considered well-formed XML (ie: short tags are closed properly such as <br /> and <img /> - not <br> and <img>) then you should be able to use XSL to translate that directly to XSL-FO, which you can then pass directly to a tool like Apache FOP for conversion. 如果你的HTML可以被认为是格式良好的XML(即:短标签被正确关闭,例如<br />和<img /> - 不是<br>和<img>)那么你应该能够使用XSL来翻译它直接到XSL-FO,然后你可以直接传递给像Apache FOP这样的工具进行转换。 If it's not well-formed, you can always use a tool like Python's BeautifulSoup or PHP's DOMDocument::loadHTML() to load the HTML and output well-formed XHTML for your conversion. 如果它的格式不正确,您可以随时使用Python的BeautifulSoup或PHP的DOMDocument :: loadHTML()等工具来加载HTML并输出格式良好的XHTML以进行转换。

There are also tools like FPDF (PHP) and Prawn (Ruby, which was used for the very pretty Dopplr reports ), but IMHO they're much more "fiddly" to use - more like using absolute positioning in CSS than allowing things to flow by themselves. 还有一些工具,如FPDF (PHP)和Prawn (Ruby,用于非常漂亮的Dopplr报告 ),但恕我直言,它们使用得更加“繁琐” - 更像是在CSS中使用绝对定位而不是让事情流动通过他们自己。 Can cause problems when you consider page breaks and such. 考虑分页等时可能会导致问题。

However, this all depends on what you're doing with the output. 但是,这一切都取决于您对输出的处理方式。

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

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