为什么选择XSL转换? [英] Why choose an XSL-transformation?

查看:108
本文介绍了为什么选择XSL转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于当前项目,必须决定是否使用XML和XSL转换来生成HTML或直接使用HTML模板。

For a current project the decision has to be made whether to use XML and an XSL-transformation to produce HTML or to directly use HTML-templates.

我' d对支持或反对XSL方法的论据感兴趣。我知道,在你必须支持许多不同布局的情况下,XSL解决方案有很多优点,但是为什么你会在你只需要支持一个目标布局的情况下选择呢?

I'd be interested in arguments for or against the XSL-approach. I understand that in cases where you have to support many different layouts, an XSL-solution has a lot of advantages, but why would you choose it in those cases where you only have to support one target layout?

编辑:我们在这里谈论Java。

We're talking about Java here.

推荐答案

XSLT是一种函数式编程语言,您可以使用它来创建与任何模板系统一样丰富的前端。但是,你不应该 - 你和你的团队会疯狂。

XSLT is a functional programming language and you can use it to create frontends as rich as any templating system. However, you shouldn't — you and your team will go insane.

这两个选项都提供了以合乎逻辑的方式将对象转换为表示形式的机会。 XSLT最适合创建更多XML,这可能会让您相信它是用于创建XHTML的完美候选者。但是,创建XHTML不应该是主要目标 - 创建用户体验。不要关心 medium

Both options present the opportunity of transforming objects into a presentation form in a logical sort of way. XSLT is best suited for creating more XML, which might lead you to believe that it's a perfect candidate to use to create XHTML. However, creating XHTML shouldn't be the primary goal — Creating a user experience is. Don't concern yourself with the medium.

XSLT的两个重要缺点涉及语法:您的模板及其包含的模板,这些模板包含的模板都将是巨大而冗长的。其次,你将不得不做很多函数式编程,当遇到带有累加函数参数的递归模板而不是简单的for循环时,经验不足的工程师可能会感到困惑和恐惧。

Two significant drawbacks to XSLT concern the syntax: Your templates, and the templates that they include, and the templates that those templates include will all be gigantic and verbose. Second, you'll have to do a lot of functional programming, and less-experienced engineers may be confused and terrified when they encounter a recursive template with an accumulating function parameter instead of a simple for loop.

如果您被改造逻辑构造的有效XML实体的美感所吸引,那么请考虑使用类型安全的模板系统来转换bean。查看 Google XML Pages ,并创建易于组织的,类型安全的模板,这将很容易为未来的工程师提供和扩展。

If you're attracted by the beauty of transforming logically-constructed, valid XML entities, consider instead a type-safe templating system that transforms beans instead. Check out Google XML Pages, and create logically-organized, type-safe templates that will be easy for future engineers to pick up and extend.

这篇关于为什么选择XSL转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆