xml XSLT 和 XSL-FO 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/740404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:26:58  来源:igfitidea点击:

What's the difference between XSLT and XSL-FO?

xmlxsltxsl-fo

提问by cwap

What's the difference between XSLT and XSL-FO ?

XSLT 和 XSL-FO 有什么区别?

Every resource I've read deal with them as if they were 1, or at least very closely tied..

我读过的每个资源都将它们视为 1,或者至少非常紧密地联系在一起。

采纳答案by Murph

I was wondering about the basis of the question because I thought it was easy to answer, however as soon as you go here: http://www.w3.org/TR/xsl/it becomes clear that its actually a good question - because pretty much the first thing on the page is this statement:

我想知道这个问题的基础,因为我认为这很容易回答,但是一旦你到这里:http: //www.w3.org/TR/xsl/很明显它实际上是一个好问题 -因为几乎页面上的第一件事就是这个声明:

This specification defines the features and syntax for the Extensible Stylesheet Language (XSL), a language for expressing stylesheets. It consists of two parts:

  1. a language for transforming XML documents (XSLT), and
  2. an XML vocabulary for specifying formatting semantics.

该规范定义了可扩展样式表语言 (XSL) 的特性和语法,XSL 是一种用于表达样式表的语言。它由两部分组成:

  1. 一种用于转换 XML 文档 (XSLT) 的语言,以及
  2. 用于指定格式语义的 XML 词汇表。

However, back in the real world, XSLT (which is also what most people will assume you mean by XSL) is a means for transforming XML documents into something else - that something else more often than not being another well structured document probably also formatted as XML (though I've used XSLT to render XML to csv and plain(ish) text).

然而,回到现实世界中,XSLT(这也是大多数人会认为 XSL 的意思)是一种将 XML 文档转换为其他内容的方法 - 其他内容通常不是另一个结构良好的文档,可能也被格式化为XML(尽管我使用 XSLT 将 XML 呈现为 csv 和纯(ish)文本)。

XSL-FO on the other hand is about formatting - about laying out content on a page or a sequence of pages in a fairly strict fashion. Its useful because it allows you to manage content that is spread across multiple pages, its relatively straightforward to specify the format of a page (or even and odd pages) including headers, footers, borders, columns, etc and have your content flow into that. One would therefore take a load of data in, say, an XML format and then use XSLT to convert that data into a document consisting of XSL-FO that in turn is rendered using an appropriate tool in say PDF for print or other means of distribution.

另一方面,XSL-FO 是关于格式化的——关于以相当严格的方式在一个页面或一系列页面上布置内容。它很有用,因为它允许您管理分布在多个页面上的内容,指定页面(或偶数页和奇数页)的格式(包括页眉、页脚、边框、列等)并让您的内容流入其中相对简单. 因此,人们会以 XML 格式加载大量数据,然后使用 XSLT 将该数据转换为由 XSL-FO 组成的文档,该文档又使用适当的工具呈现为 PDF 格式,用于打印或其他分发方式.

The use case I have is to take a pile of tabular data, export that data as XML, render that into XSL-FO and from there to PDF which goes to a printer who turns said PDF into a 500 page directory. One specifies in the XSL-FO that one wants page numbers, page breaks in specific circumstances, that there is a table of contents and an index (each based on particular elements) and the rendering process (to PDF) handles filling in the page numbers across the board.

我的用例是获取一堆表格数据,将该数据导出为 XML,将其渲染到 XSL-FO 中,然后再将其渲染为 PDF,然后将其发送到打印机,该打印机将所述 PDF 转换为 500 页的目录。在 XSL-FO 中指定需要页码、特定情况下的分页符、目录和索引(每个都基于特定元素)以及渲染过程(到 PDF)处理页码的填充全面。

Hopefully you're a bit less confused now..

希望你现在不那么困惑了..

回答by Mads Hansen

Aside from the similarities in the acronyms the two technologies used to be part of the same W3C spec(in draft form). It was later decided to split XSL(XSL-fo) and XSLT out into two separate specifications.

除了首字母缩略词的相似之处,这两种技术曾经是同一 W3C 规范(草案形式)的一部分。后来决定将 XSL(XSL-fo) 和 XSLT 分成两个独立的规范。

Quote from W3Schools:

引自 W3Schools

XSL-FO is Formally Named XSL

Why this confusion? Is XSL-FO and XSL the same thing?

Yes it is, but we will give you an explanation:

Styling is both about transforming and formatting information. When the World Wide Web Consortium (W3C) made their first XSL Working Draft, it contained the language syntax for both transforming and formatting XML documents.

Later, the Working Group at W3C split the original draft into separate Recommendations:

* XSLT, a language for transforming XML documents
* XSL or XSL-FO, a language for formatting XML documents
* XPath, a language for navigating in XML documents

XSL-FO 正式命名为 XSL

为什么会有这种困惑?XSL-FO 和 XSL 是一回事吗?

是的,但我们会给你一个解释:

样式既是关于转换和格式化信息的。当万维网联盟 (W3C) 制定他们的第一个 XSL 工作草案时,它包含了用于转换和格式化 XML 文档的语言语法。

后来,W3C 的工作组将原始草案拆分为单独的建议:

* XSLT, a language for transforming XML documents
* XSL or XSL-FO, a language for formatting XML documents
* XPath, a language for navigating in XML documents

A detailed annotation of the chronology can be found on Dave Pawson's Home page: http://www.dpawson.co.uk/xsl/sect1/history.html

年表的详细注释可以在 Dave Pawson 的主页上找到http: //www.dpawson.co.uk/xsl/sect1/history.html

回答by Premraj

XSLis family of languages used to transform and render XML documents

XSL是用于转换和呈现 XML 文档的语言家族

XSLT(XSL Transformations) : is a language for transforming XML documents into other XMLdocuments, or other formats such as HTMLfor web pages, plain textor into XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG.

XSLT(XSL Transformations) :是一种语言,用于将 XML 文档转换为其他 XML文档或其他格式,例如网页的HTML纯文本XSL 格式对象,随后可能会转换为其他格式,例如PDF、PostScript和 PNG。

Transformation can do the following three ways:

转换可以通过以下三种方式进行:

  1. Referenced:Let the browser do the transformation :using <xsl:processing-instruction>
  2. Embedded:Client side transformation using JavaScript.
  3. Runtime:To make XML data available to all kind of browsers, we can transform the XML document on the SERVER.
  1. 参考:让浏览器进行转换:使用<xsl:processing-instruction>
  2. 嵌入式:使用 JavaScript 进行客户端转换。
  3. 运行时:为了让所有类型的浏览器都可以使用 XML 数据,我们可以在 SERVER 上转换 XML 文档。

For example:

例如

enter image description hereXSL-FO(XSL Formatting Objects) : is not supported by web browsers because it's designed for print output, not online viewing. (from @Hobbes)
Output formats currently supported include PDF, PCL, PS, AFP, TIFF, PNG, SVG, XML (area tree representation), Print, AWT and TXT. The primary output target is PDF. Soruce

在此处输入图片说明XSL-FO(XSL 格式化对象):Web 浏览器不支持,因为它是为打印输出而不是在线查看而设计的。(来自@Hobbes)
目前支持的输出格式包括 PDF、PCL、PS、AFP、TIFF、PNG、SVG、XML(区域树表示)、Print、AWT 和 TXT。主要输出目标是 PDF。

Example code:

示例代码:

<fo:table-row height=".5cm">
            <fo:table-cell>
                <fo:block></fo:block>
            </fo:table-cell>
        </fo:table-row>

Flow chart: enter image description here

流程图: 在此处输入图片说明

回答by Bj?rn

XSLT is used for transforming, XSL (which is the same as XSL-FO) is used for formatting.

XSLT 用于转换,XSL(与 XSL-FO 相同)用于格式化。

http://www.w3schools.com/xslfo/xslfo_intro.asp

http://www.w3schools.com/xslfo/xslfo_intro.asp

回答by Manuel

What about the Wikipedia definition?

怎么样的维基百科的定义

XSL Formatting Objects, or XSL-FO, is a markup language for XML document formatting which is most often used to generate PDFs. XSL-FO is part of XSL, a set of W3C technologies designed for the transformation and formatting of XML data. The other parts of XSL are XSLT and XPath. As of December 12, 2006, the current version of XSL-FO is v1.1.

XSL 格式对象(XSL-FO)是一种用于 XML 文档格式的标记语言,最常用于生成 PDF。XSL-FO 是 XSL 的一部分,XSL 是一组 W3C 技术,旨在转换和格式化 XML 数据。XSL 的其他部分是 XSLT 和 XPath。截至 2006 年 12 月 12 日,XSL-FO 的当前版本为 v1.1。

回答by Hammad Khan

This can be quite confusing as w3schools tutorial site(not related to w3.org) says

正如w3schools 教程网站(与 w3.org 无关)所说,这可能会令人困惑

XSL-FO is now formally named XSL

XSL-FO 现在正式命名为 XSL

enter image description here

在此处输入图片说明

that means XSL-FO and XSL is the same thing but they are not!

这意味着 XSL-FO 和 XSL 是一回事,但它们不是!

XSL is basically representing XML data into an HTML document XSL-FO is about formatting of the document itself. For example if you want to transform XML into a word document, you want to add page numbers, change margin or page layout, add headers and footers etc. These items can only be addressed via XSL FO tags, XSLT has no way to access the document properites. In technical field, you will most likely come across scenario where XML data is rendered in word or PDF document. It would need page numbers, layout format, header etc. These are very important part of the document.

XSL 基本上是将 XML 数据表示为 HTML 文档 XSL-FO 是关于文档本身的格式设置。例如,如果要将 XML 转换为 Word 文档,要添加页码、更改边距或页面布局、添加页眉和页脚等。这些项目只能通过 XSL FO 标签寻址,XSLT 无法访问文档属性。在技​​术领域,您很可能会遇到 XML 数据在 Word 或 PDF 文档中呈现的情况。它需要页码、布局格式、页眉等。这些是文档中非常重要的部分。

Another big difference is XSL and XSL FO has different engines. XSL can not render XSL-FO tags. This question talks about which engine to use for XSL FO

另一个很大的区别是 XSL 和 XSL FO 具有不同的引擎。XSL 无法呈现 XSL-FO 标签。这个问题讨论了 XSL FO 使用哪个引擎

Which is the Best commercial xsl fo engine?

哪个是最好的商业 xsl fo 引擎?

A typical XSL Fo tempate lools like this

一个典型的 XSL Fo 模板是这样的

<?xml version="1.0" encoding="ISO-8859-1"?>

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<fo:layout-master-set>
  <fo:simple-page-master master-name="A4">
    <fo:region-body />
  </fo:simple-page-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="A4">
  <fo:flow flow-name="xsl-region-body">
    <fo:block>Hello W3Schools</fo:block>
  </fo:flow>
</fo:page-sequence>

</fo:root> 

Notice that there is no reference to XML data. It is all about formatting the document itself. This is an extremely important element when it comes to transforming XML data into legal documents. Because you need pager number, document number, layout etc if the output document is pdf or word. With out this information, it is painfully hard to implement page numbers or headers etc.

请注意,没有对 XML 数据的引用。这完全是关于格式化文档本身。在将 XML 数据转换为法律文档时,这是一个极其重要的元素。因为如果输出文档是 pdf 或 word,您需要寻呼机编号、文档编号、布局等。没有这些信息,很难实现页码或标题等。

The confusion comes in because this document will almost certainly contain XSL tags as we will pulling XML data. However if there is no XSL Fo engine, the document will not be rendered.

混淆是因为这个文档几乎肯定会包含 XSL 标记,因为我们将提取 XML 数据。但是,如果没有 XSL Fo 引擎,则不会呈现文档。

So in short they are similar and work together but they are not the same thing. They are rendered by different engines.

所以简而言之,它们是相似的并且可以一起工作,但它们不是一回事。它们由不同的引擎渲染。

回答by Tony Graham

Like so many other things, it depends on your point of view and your history.

像许多其他事情一样,这取决于您的观点和历史。

XSLT is a language (written in XML) "for transforming XML documents into other XML documents.", although the current XSLT 3.0 CR (http://www.w3.org/TR/xslt-30/) changes that to "a language designed primarilyfor transforming XML documents into other XML documents." (Emphasis added.)

XSLT 是一种语言(用 XML 编写)“用于将 XML 文档转换为其他 XML 文档。”,尽管当前的 XSLT 3.0 CR ( http://www.w3.org/TR/xslt-30/) 将其更改为“a设计语言,主要用于XML文档转换成其他XML文档“。(加了重点。)

XSL-FO is "an XML vocabulary for specifying formatting semantics." It is defined in the "Extensible Stylesheet Language (XSL) Version 1.1" Recommendation (http://www.w3.org/TR/xsl11/). A formatter, such as from Antenna House, takes an XML document in the FO vocabulary and produces styled and paginated output.

XSL-FO 是“用于指定格式语义的 XML 词汇表”。它在“可扩展样式表语言 (XSL) 版本 1.1”建议 ( http://www.w3.org/TR/xsl11/) 中定义。格式化程序(例如来自 Antenna House 的格式化程序)采用 FO 词汇表中的 XML 文档并生成样式化和分页的输出。

Where the history comes into it is that initially there was only one spec -- Extensible Stylesheet Language (XSL) -- that defined both transformation -- getting your XML into the FO XML vocabulary -- and styling -- getting the FO into styled and paginated form. The history page from Dave Pawson (http://www.dpawson.co.uk/xsl/sect1/history.html) linked to from Mads Hansen's answer has the full details, but along the way to XSL becoming a Recommendation, the transformation part was seen to be generally useful and was broken out as "XSL Transformations (XSLT)". Transforming markup to markup wasn't new, but having a standard for it with multiple, (mostly) compatible implementations was a breath of fresh air.

历史的起源是最初只有一个规范——可扩展样式表语言 (XSL)——它定义了两种转换——将你的 XML 放入 FO XML 词汇表——和样式——将 FO 放入样式和分页形式。从 Dave Pawson ( http://www.dpawson.co.uk/xsl/sect1/history.html) 链接到 Mads Hansen 的回答的历史页面有完整的细节,但在 XSL 成为推荐的过程中,转换部分被认为是普遍有用的,并被分解为“XSL 转换 (XSLT)”。将标记转换为标记并不是什么新鲜事,但是为它制定一个具有多个(大部分)兼容实现的标准是一种清新的空气。

The way that XSLT could address parts of an XML document was also seen to be generally useful, and it was broken out as "XML Path Language (XPath)" so it could be used by other specs. (XPath is used by, e.g., XQuery and XLink.)

XSLT 处理 XML 文档部分的方式也被普遍认为是有用的,它被分解为“XML 路径语言 (XPath)”,以便其他规范可以使用它。(XPath 被例如 XQuery 和 XLink 使用。)

Where the point of view comes into it is that the XSL 1.1 Recommendation still defines a process of transformation plus formatting, but the transformation part just happens to be defined in a separate document. See http://www.w3.org/TR/xsl11/#d0e386

其观点是,XSL 1.1 Recommendation 仍然定义了转换加格式化的过程,但转换部分恰好在单独的文档中定义。见http://www.w3.org/TR/xsl11/#d0e386

While the official XSL 1.1 PoV is that XSLT and XSL-FO are both parts of XSL, and probably every FO formatter can do the transformation part, in practice, most people transform their XML into XML in the FO vocabulary using an external XSLT processor and feed that FO XML to their formatter.

虽然官方的 XSL 1.1 PoV 是 XSLT 和 XSL-FO 都是 XSL 的一部分,并且可能每个 FO 格式化程序都可以完成转换部分,但实际上,大多数人使用外部 XSLT 处理器将他们的 XML 转换为 FO 词汇表中的 XML,并且将该 FO XML 提供给他们的格式化程序。

Where history meets point of view is that XSLT 1.0 (http://www.w3.org/TR/xslt) defined itself as being part of an XSL system:

历史与观点相遇的地方是 XSLT 1.0 ( http://www.w3.org/TR/xslt) 将自己定义为 XSL 系统的一部分:

XSLT is designed for use as part of XSL, which is a stylesheet language for XML. In addition to XSLT, XSL includes an XML vocabulary for specifying formatting. XSL specifies the styling of an XML document by using XSLT to describe how the document is transformed into another XML document that uses the formatting vocabulary.

XSLT 设计用作 XSL 的一部分,XSL 是 XML 的样式表语言。除了 XSLT 之外,XSL 还包括用于指定格式的 XML 词汇表。XSL 通过使用 XSLT 来描述如何将文档转换为另一个使用格式化词汇表的 XML 文档来指定 XML 文档的样式。

But that point of view isn't present in XSLT 2.0 (http://www.w3.org/TR/xslt20/) and is long gone by the time of XSLT 3.0.

但这种观点在 XSLT 2.0 ( http://www.w3.org/TR/xslt20/) 中并不存在,并且在 XSLT 3.0 时代早已不复存在。

The final part of point of view is that when many people say "XSL" they mean just XSLT, except for those that when they say "XSL" they mean XSL-FO while mostly forgetting that their FO formatter can do both.

观点的最后一部分是,当许多人说“XSL”时,他们的意思只是 XSLT,除了那些当他们说“XSL”时,他们的意思是 XSL-FO,而大多数人却忘记了他们的 FO 格式化程序可以两者兼而有之。

回答by Srikar Doddi

XSL-FO stands for Extensible Stylesheet Language Formatting Objects and is about formatting and now is known as XSL to avoid all confusion. So do not worry about XSL-FO anymore.

XSL-FO 代表可扩展样式表语言格式对象,是关于格式的,现在称为 XSL 以避免所有混淆。所以不要再担心 XSL-FO。

XSLT however is about transforming xML. So it is very clear. XSL is about formatting and XSLT is about transforming.

然而,XSLT 是关于转换 xml 的。所以很清楚。XSL 是关于格式化的,而 XSLT 是关于转换的。

回答by Maurice Perry

XSLT is a template format that can be used to generate all sorts of documents, including plain text documnent.

XSLT 是一种模板格式,可用于生成各种文档,包括纯文本文档。

XSL-FO denotes the use of XSLT to produce FO documents.

XSL-FO 表示使用 XSLT 生成 FO 文档。