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

查看:22
本文介绍了为什么选择 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.

我对支持或反对 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 不应该是主要目标——创建用户体验才是.不要担心媒介.

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 页面,并轻松创建逻辑组织、类型安全的模板供未来的工程师学习和扩展.

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天全站免登陆