简体   繁体   English

使用XSL-FO和HTML?

[英]Using XSL-FO and HTML?

I'm trying to transform some XML-data to HTML with XSLT for my bachelor thesis. 我正在尝试使用XSLT将一些XML数据转换为HTML用于我的学士论文。

My professor wants me to consider XSL-FO too, or at least to write some word about it. 我的教授也希望我考虑XSL-FO,或者至少要写一些关于它的话。 But I'm very noob to this. 但我非常喜欢这个。

So my questions are: 所以我的问题是:

Can I combine FO with HTML? 我可以将FO与HTML结合使用吗? Can I use FO istead of HTML and CSS? 我可以使用FO而不是HTML和CSS吗? If yes, how will my browser render this? 如果是,我的浏览器将如何渲染? Are there any examples/tutorials on how to transform xml into web pages with FO? 是否有关于如何使用FO将xml转换为网页的示例/教程?

Generating XSL-FO and XHTML from XSLT is not necessarily an either-or choice. 从XSLT生成XSL-FO和XHTML不一定是一种选择。

XSL-FO is generally used to generate PDF. XSL-FO通常用于生成PDF。 For that you will need an XSL-FO engine , such as FOP , RenderX , Antenna House , IBex , etc. However, you can convert XSL-FO into XHTML and then render in the browser. 为此,您需要一个XSL-FO引擎 ,例如FOPRenderXAntenna HouseIBex等。但是,您可以将XSL-FO转换为XHTML ,然后在浏览器中呈现。

Generally, it wouldn't be worth the hassle to have your XSLT create XSL-FO and then convert into XHTML (just generate XHTML directly), unless you want to create both output formats (PDF and XHTML) with reduced effort. 通常,让XSLT创建XSL-FO然后转换为XHTML (直接生成XHTML)是不值得的,除非您想要减少工作量创建两种输出格式(PDF和XHTML)。

It is possible to create both **XSL-FO and XHTML at the same time without maintaining two complete sets of stylesheets to create similar output in different vocabularies**. 可以同时创建** XSL-FOXHTML ,而无需维护两套完整的样式表来在不同的词汇表中创建类似的输出**。

Rather than choosing between one format or the other, or having to maintain two distinctly diffirent(but similar) stylesheet libraries, you can create your main stylesheet library to generate either XSL-FO or XHTML and then use a second transform to convert from XSL-FO to XHTML and vice-versa. 您可以创建主样式表库以生成XSL-FOXHTML ,然后使用第二个转换 XSL转换而不是在一种格式或另一种格式之间进行选择,或者必须维护两个明显不同(但相似)的样式表库。 FO XHTML ,反之亦然。 There are existing XSLT stylesheets that you can leverage to do this. 您可以利用现有的XSLT样式表来执行此操作。

In the past I have developed XSL-FO stylesheets and then used the Render-X FO2HTML stylesheet to convert the XSL-FO to XHTML output. 在过去,我开发了XSL-FO样式表,然后使用Render-X FO2HTML样式表XSL-FO转换 XHTML输出。 It converts <block> elements into <div> , <inline> into <span> , etc. 它将<block>元素转换为<div><inline>转换为<span>等。

I haven't used them before, but you could also try using HTML2FO stylesheets to convert XHTML outut into XSL-FO . 我之前没有使用它们,但您也可以尝试使用HTML2FO样式表XHTML outut转换为XSL-FO

Out of the box, you can get amazingly similar output in both formats while maintaining one XSLT library dedicated to one particular output format. 开箱即用,您可以在两种格式下获得惊人相似的输出,同时保持一个专用于一种特定输出格式的XSLT库。

If you happen to need to customize the output slightly (eg different header content for XHTML ) then you just need to import/extend the conversion stylesheets and override the appropriate template(s) for the divergent content. 如果您碰巧需要稍微自定义输出(例如, XHTML的不同标头内容),那么您只需要导入/扩展转换样式表并覆盖不同内容的相应模板。 This makes maintenance much easier, so you don't have to worry about updating multiple sets of stylesheets with essentially the same information. 这使维护变得更加容易,因此您不必担心使用基本相同的信息更新多组样式表。

XSL-FO is for PDF display only (this is not strictly true, but you can take it as a guideline). XSL-FO仅用于PDF显示(这不是严格意义上的,但您可以将其作为指南)。 So HTML output and FO output are not related. 因此HTML输出和FO输出无关。 From your XML source, you can use XSLT to generate XHTML or XSL-FO, but not both at the same time. 从XML源代码中,您可以使用XSLT生成XHTML XSL-FO,但不能同时生成两者。

See for example DocBook. 请参阅DocBook。 It comes with several XSLT stylesheets ready to use, one is for HTML output and one for PDF (via Apache Fop). 它附带了几个可供使用的XSLT样式表,一个用于HTML输出,另一个用于PDF(通过Apache Fop)。 If you are satisfied with the result could be a different question. 如果您对结果感到满意可能是另一个问题。

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

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