简体   繁体   English

如何将带有 CSS 的 HTML 转换为 xsl-fo?

[英]How to convert HTML with CSS to xsl-fo?

I want convert HTML with Css to xsl-fo.我想将带有 CSS 的 HTML 转换为 xsl-fo。 Anyone can suggest to me how to convert this.任何人都可以向我建议如何转换它。

I have 2 file one html file and once css file.我有 2 个文件,一个 html 文件和一次 css 文件。 I want to generate xsl-fo file with these 2 files so that I can easily generate pdf, rtf and other format easily.我想用这2个文件生成xsl-fo文件,这样我就可以轻松生成pdf、rtf等格式。

HTML file 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="style.css"/> *--> css file* 
<title></title>
</head>
<body>
<div class="cw-default">
<p><span class="sans"><b>Short title</b></span> this is text for testing<i>italic text</i>.</p>
<p class="center">this is test</p>
</div>
</body>
</html>

style.css file will add property into the html, I want this property values will come in generated FO file also. style.css 文件会将属性添加到 html 中,我希望此属性值也将出现在生成的 FO 文件中。

/* Style Sheet */

.cw-default { font-size: 1em; }
.sans  { font-family: arial,helvetica }
.center   {text-align: center;}

We have used this in many projects:我们已经在很多项目中使用了它:

Werner Donne's CSS to XSL FO Werner Donne 的 CSS 到 XSL FO

This is XSL plus code to convert CSS, CSS2 to XSL FO.这是将 CSS、CSS2 转换为 XSL FO 的 XSL 加代码。

Converting HTML to xsl-fo is a transformation from one Markup Language to another.将 HTML 转换为 xsl-fo 是从一种标记语言到另一种标记语言的转换。 The difference between them is that HTML is used to be displayed with Browsers and xsl-fo is used to turned into PDF by Renderers.它们之间的区别在于,HTML 用于与浏览器一起显示,而 xsl-fo 用于由渲染器转换为 PDF。
CSS is not a tool to transform a Markup Language but to style it. CSS 不是转换标记语言的工具,而是对其进行样式设置的工具。 You can use it with both HTML and xsl-fo, but that does not mean that it is able to do a transformation.您可以将它与 HTML 和 xsl-fo 一起使用,但这并不意味着它能够进行转换。 The Language built for transformations is XSLT.为转换构建的语言是 XSLT。 This is the right tool for what you want to achieve.这是您想要实现的目标的正确工具。 Be aware that XSLT works with XML input and most HTML isn't valid XML, but XHTML is.请注意,XSLT 可用于 XML 输入,并且大多数 HTML 不是有效的 XML,但 XHTML 是有效的。 Just be sure to close your tags ;-)请务必关闭您的标签;-)
Here is an example: Xslt to xsl-fo transformation下面是一个例子: Xslt to xsl-fo 转换

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

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