使用浮动 div 元素格式化语言

发布于 2024-11-12 09:23:58 字数 1098 浏览 5 评论 0原文

我将数据存储在结构化 XML 中,我希望使用 XSLT(或其他替代方案)使其更具可读性。目标文档应该有很多在同一行中向左和向右对齐的文本实例,并且我需要有像 div 浮动这样的行为:

<div style="float: left;">
  <p align=left>
    Left text. Left text. Left text. Left text. Left text. Left text. 
  </p>
</div>

<div style="float: right;">
  <p align=right>
    Right text. Right text. Right text. Right text. Right text. Right text. 
  </p>
</div>
<div style="clear: both;" />

这样,当两者的文本长度都大于容器宽度时,写入“左侧文本”DIV,然后在其下方写入“右侧文本”DIV。

我无法使用 XSLT 来制作 HTML 文件,因为它将在打印中使用,而且我还需要一种在分页符处具有某种“保持在一起”功能的语言(如果分页符发生在元素中间,则应在元素之前中断)。拥有支持自动调整列大小的表格(如 HTML 表格)将是一个巨大的优势,但不是必需的。

我正在研究 XSL-FO,但找不到支持这些功能的免费渲染器。我想过使用XSL制作WordML文件,但我还没有找到任何关于它的教程。拥有 Word(或 Open Office)文档会很棒,因为我可以进行细微的调整。另外,我正在考虑使用 LaTex。

你能给我什么建议?

编辑:我正在检查一些我不知道的CSS功能(多年来没有弄乱它),它确实有一些与打印相关的功能(page-break-inside:avoid,@页面等)除了对浮动和表格自动布局有很好的支持。尽管打印功能没有得到广泛支持,但 Opera 和 IE 确实支持它,并且我在 IE9 中进行了一些测试,它呈现得非常好。因此,我将尝试使用 HTML/CSS 进行 XSLT,因为它拥有我需要的一切,并且学习曲线会更平滑(我已经了解一些 CSS,并且已经使用 HTML 多年)。

I have data stored in structured XML that I want to make it more readable using XSLT (or another alternative). The target document should have lots of instances of text aligned both to the left and to the right in the same line, and I need to have a behaviour like div floats:

<div style="float: left;">
  <p align=left>
    Left text. Left text. Left text. Left text. Left text. Left text. 
  </p>
</div>

<div style="float: right;">
  <p align=right>
    Right text. Right text. Right text. Right text. Right text. Right text. 
  </p>
</div>
<div style="clear: both;" />

This way, when the text lenght of both are bigger than the container width, the "Left text" DIV is written, then the "Right text" DIV is writter BELOW it.

I can't use XSLT to make a HTML file, because it will be use in print and I also need a language that has some "keep together" feature at page breaks (if a page break occurs in the middle of the element, it should break before the element). Having tables that supports auto sizing its columns (like the HTML table) would be a huge plus but not required.

I was studying XSL-FO, but I couldn't find a free renderer that supports those features. I thought about using XSL to make a WordML file, but I haven't found any tutorials on it. Having a Word (or Open Office) document would be great, cause I could make minor adjustments. Also, I'm considering using LaTex.

What can you suggest me?

EDIT: I was checking some CSS features that I didn't know about (haven't messed with it in years) and it does have some print related features (page-break-inside:avoid, @page, etc) besides having an excelent support for floats and auto layout of tables. Even though the print features are not widelly supported, Opera and IE do support it and I ran some tests in IE9 an it rendered very well. So I will try XSLT with HTML/CSS since it has everything I need and will have a smoother learning curve (I already know some CSS and have use HTML for years).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹊巢 2024-11-19 09:23:58

我认为您应该通过使用一些众所周知的 XML 标准模式(如 DITA 或 DOCBOOK)来决定采用更通用的方法来解决您的问题。

这些模式的优点是可以让您编写自己的 XML 并根据它们支持的输出格式根据需要呈现它。而且它们都是免费的,一旦您拥有正确的源文档,您就可以轻松获得PDF、RTF、WebHelp、HTML等。

因此,您需要:

  • 做出决定,是 DITA 还是 DOCBOOK?
  • 编写一个转换来获取您的 XML 并将其转换为特定的标准 DITA 或 DOCBOOK
  • 决定用于管理您选择的标准的工具,并测试您可以从中获得的所有输出,看看哪一个更适合。

如果您决定使用 DITA,那么您有两个免费选择:

  • DITA-OT
  • DITAC

就个人而言,我会选择 DITA 和 DITA-OT,因为它具有基于 XSLT 的插件和基于蚂蚁。但两者都有其理由。我开始使用 DITA-OT,最后使用 DITA-OT 和 DITAC。

我没有在这里放置任何参考,因为你可以使用谷歌轻松找到你需要的东西。


关于 FLOAT

DITA-OT 提供了一种特定的 XSL-FO 转换类型,称为 PDF2,其 XSL-FO 处理器是 RenderX。 RenderX 目前支持 fo:float 所以我想你能够找到你的方法。可能您需要覆盖一些 PDF2 模板,这肯定比实现您自己的 PDF 转换更简单。

请注意,只要您可以接受每个页面上的小脚水印,RenderX 就是可行的。否则你应该花一些钱。

I think you should decide for a more general approach to your problem by going with some well known XML standard schema like DITA or DOCBOOK.

These schemas have the advantage of letting you write your own XML and render it as you need according to the output format they support. Moreover, they are free and you can obtain PDF, RTF, WebHelp, HTML and so on easily once you have the corret source documents.

So, you need to:

  • make your decision, DITA or DOCBOOK?
  • write a transfrom that gets your XML and convert it to the specific standard DITA or DOCBOOK
  • decide the tool to use for managing the standard you have chosen and test all output you can obtain from it and see which one fits better.

If you decide for DITA, you have two free choices there:

  • DITA-OT
  • DITAC

Personally, I would go with DITA and DITA-OT because it has the flexibility of plugins based on XSLT and custom builds based on ANT. But both have their reasons. I started with DITA-OT and ended using both DITA-OT and DITAC.

I did not put any reference here, because you can easily find what you need using Google.


ABOUT FLOAT

DITA-OT provides a specific XSL-FO transtype which is called PDF2 and whose XSL-FO processor is RenderX. RenderX currently supports fo:float so I imagine you will be able to find your way. May be you will need to override some PDF2 template, which is definitely simpler than implementing your own PDF transform.

Note that RenderX is feasable as long as a small foot watermark on each page is acceptable for you. Otherwise you should spend some money.

¢蛋碎的人ぎ生 2024-11-19 09:23:58

我肯定会坚持使用 XSL-FO 和 Apache Fop。我对它所获得的结果非常满意,唯一一次我看到它遇到困难是当有人认为尝试让它生成 Word 文档是个好主意时。我从未见过这会产生好的结果。事实上,我只对它生成的 PDF 或 PS 格式的输出感到满意。

请详细说明 FOP 在浮动和分页符方面有何不足?很难知道这是特定于这些功能的问题还是特定于具有 Word/RTF/HTML 输出格式的功能的问题。

最后,我会避免在工作/开放式办公室的心态中周旋。如果您打算自动生成文档,请花时间使其正确,这样就不需要手动步骤。

I would definitely stick with XSL-FO and Apache Fop. I've been very happy with the results I've been able to get with it and the only times I've see it struggle is when someone thinks it's a good idea to try and get it to produce Word Documents. I've never seen this produce good results. In fact I've onyl every been happy with the output it produces in PDF or PS format.

Please elaborate on how the FOP was falling short regarding floats and page breaks? It's hard to know if it is a problem specific to those features or if it was specific to those features with a Word/RTF/HTML output format.

Finally, I would avoid the tweek it in Work/Open Office mentality. If you are going to the effort of automating the document generation, spend the time on getting it right, so there are no manual steps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文