Back in 2002-2003 I did a lot with XSLT (and some more in 2006-2007). Your mileage on this will vary but honestly I would avoid it, for several reasons:
The syntax is a blinding headspin, hard to learn, hard to get right and just plain gives you a headache. The templates themselves aren't too bad but throw in some gnarly XPath expressions and it just hurts;
For reasonably sized documents and transforms it is relatively slow. Whether or not it's slow enough to be relevant to you is something you'll only find with benchmarking your scenario so don't take this as a blanket rule, more of a cautionary tale or a caveat;
Error messages just aren't that useful and it can be hard to figure out problems. Unlike a more traditional approach, you can't whip out a debugger and step through an XSLT;
Generating HTML with any modern Web-flavoured language (C#, Java, PHP, Python, Ruby, etc) is trivial, straightforward, easy to log and easy to debug;
Manipulating XML is arguably more tedious and produces more code that directly manipulating objects and converting them into markup. This of course will vary by what tools your chosen language provides you with.
The only place I can really see having an application for XSLT these days is in consuming Web services that produce XML (lots produce JSON and more easily consumed formats these days).
And even in that case I'd probably still manipulate the XML directly with, say, JAXB in Java (or similar technologies in other languages).
So if you start new project, think twice (or ten times) before jumping into XSLT. And > if you use Eclipse, you can even think twice before using JSP/JSTL. Velocity or > FreeMarker might be a better option.
当然,自 2005 年以来,其他技术的发展速度是 XSLT 所没有的,但它仍然是一个强大的工具,它为您提供了一定程度的抽象,例如 ASP.NET Web 表单所没有的,并且允许您提供通用的可扩展解决方案简单地序列化为一系列输出格式。 使用任何给定语言生成 HTML 都很容易,但现在将其扩展为 XML、将其扩展为 JSON、将其扩展为 CSV 就更困难了。
在仍然受 I/O 限制的环境中,缓存的转换速度足够快。
OTOH,在 XML 中存储数据通常不是一个好主意。 出于上述所有原因,最好存储在 DB/mem 中并根据需要进行序列化。
Answers based on "the syntax is hard" is no answer at all imho. A). It really isn't, and B). You're supposed to be a programmer, just learn it.
Definitely other technologies are advancing at a pace XSLT hasn't since 2005ish, but it remains a powerful tool which gives you a level of abstraction that, say, asp.net webforms don't, and allows you to provide a general scalable solution to trivially serialise to a range of output formats. It's easy to generate HTML with any given language, it's harder to now extend that to XML, now extend that to JSON, now extend that to CSV.
And cached transforms are plenty fast enough in an environment which is still I/O bound.
OTOH, storing data in XML is generally not a good idea. Far better to store in a DB/mem and serialise as required for all the reasons above.
在工作中,我参与的一个项目使用了 XSLT,说实话,这真的很痛苦。 实际的 XSLT 文件并不难使用,但创建 XML 会增加额外的复杂性。 我还发现,除了最基本的页面之外,XML 往往会变得非常臃肿和混乱。 所以,不,我不会推荐它。
At work, a project I'm on uses XSLT and to be honest, it's a real pain. The actual XSLT files aren't that difficult to work with, but having to create XML adds an extra layer of complexity. I've also found that beyond the most basic pages, the XML tends to get very bloated and messy. So, no, I wouldn't recommend it.
研究 MVC 框架,看看哪一个最适合您。 例如 ASP.NET MVC、Ruby on Rails、CakePHP、Catalyst 等。
XSLT is just one method of templating. It is also just one piece of a complete MVC framework, where templating being the View component. XSLT is a great technology, but it's slow and not a first choice on building a scalable web site.
Research on MVC frameworks to see which one fits you best. e.g. ASP.NET MVC, Ruby on Rails, CakePHP, Catalyst, etc.
Spoulson 上面所说的关于模板的内容就是重点。 从输入 XML 文件提供输出页面就可以了。 但这并不能让您获得 CMS。 那么增删改查呢? 搜索? 页面列表?
如果您的网站很小,所有相关的更新都可以通过手动编辑一些 XML 文件来完成,那么为什么不呢,那就去做吧。 但如果这么简单,您不妨手动编辑 HTML。
I want to do this in order to make it easy to update the site using plain XML files (instead of using a full-fledged & expensive CMS system).
Er, what? There are many free and open-source CMSs.
What spoulson said above about templating is the point. Providing output pages from input XML files is fine. But that doesn't get you a CMS. What about C.R.U.D.? Search? Page listings?
If your site is so small that all the relevant updating can be done by you hand-editing some XML files, then why not, go for it. But if it's that simple you might as well just edit HTML by hand.
I like the idea. XSL is a fantastic tool, but you have to have that special moment of enlightenment before you realise how useful it really is. Before that it just seems so-so.
I have used XSL in a variety of applications and it has saved me a lot of time. But obviously dont just use it for the sake of it.
It's a programmers job to tackle complex problems and complex standards. There's stuff that is way harder and still needed. Just keep going at it and get's easier each time you need to learn new stuff.
Xslt is easy.
Really! There are good books out there that teach you xslt. Just learn e.g. rdf/owl (a w3c standard) and it can still get much more complex...
xslt is slow? Just use the right caching if you can. (ok, its not always possible...).
Just read about REST (some book or Roy Fielding dissertation) that's essential stuff too.
Now with XProc (xslt piplines) and a small restserver around calabash (Xproc implementaion) you can archive so much. it can definitly save you time. any data can be exportet to XML, made aviliable via REST and transformed with XProc.
Symphony CMS uses XSLT. While using that CMS I found that the only real problems I had were to do with learning the XSL/XPath syntax, mostly due to a lack of good tutorials/documentation. Might be worth giving Symphony a try if you want to see some relatively modern XSLT usage.
Take a look at http://www.umbraco.org/ It is a free open source CMS tool that uses XSLT extensively to generate pages.
To all those who claim XSLT is hard I would say that it is no harder than SQL. There are scenario's that are hard such as grouping, just like in SQL trees are hard.
Pick the right tool for the right job and you shouldn't have any problems.
对我来说听起来是个坏主意。 使用某些东西要容易得多
像 ASP.NET 一样存储内容
在数据库中 - 然后您可以更新
内容直接进入
数据库 - 它本身就是
比编辑 XML 更容易。
Sounds like a bad idea to me. It's much easier to use something
like ASP.NET with the content stored
in a database - you can then update
the content directly into the
database - which in itself will be
easier than editing the XML.
发布评论
评论(14)
早在 2002-2003 年,我就 XSLT 做了很多工作(2006-2007 年做了更多工作)。 你对此的理解会有所不同,但老实说,我会避免它,原因有几个:
如今,我真正看到 XSLT 应用程序的唯一地方是使用生成 XML 的 Web 服务(现在很多生成 JSON 和更容易使用的格式)。
即使在这种情况下,我可能仍然会直接使用 Java 中的 JAXB(或其他语言中的类似技术)直接操作 XML。
更新:我刚刚遇到XSLT 在 Web 中的消亡框架。 例如:
总结如下:
Back in 2002-2003 I did a lot with XSLT (and some more in 2006-2007). Your mileage on this will vary but honestly I would avoid it, for several reasons:
The only place I can really see having an application for XSLT these days is in consuming Web services that produce XML (lots produce JSON and more easily consumed formats these days).
And even in that case I'd probably still manipulate the XML directly with, say, JAXB in Java (or similar technologies in other languages).
Update: I just came across The Death of XSLT in Web Frameworks. For example:
summarized by:
基于“语法很难”的答案根本不是答案。 A)。 事实并非如此,B)。 你应该是一名程序员,只需学习它。
当然,自 2005 年以来,其他技术的发展速度是 XSLT 所没有的,但它仍然是一个强大的工具,它为您提供了一定程度的抽象,例如 ASP.NET Web 表单所没有的,并且允许您提供通用的可扩展解决方案简单地序列化为一系列输出格式。 使用任何给定语言生成 HTML 都很容易,但现在将其扩展为 XML、将其扩展为 JSON、将其扩展为 CSV 就更困难了。
在仍然受 I/O 限制的环境中,缓存的转换速度足够快。
OTOH,在 XML 中存储数据通常不是一个好主意。 出于上述所有原因,最好存储在 DB/mem 中并根据需要进行序列化。
Answers based on "the syntax is hard" is no answer at all imho. A). It really isn't, and B). You're supposed to be a programmer, just learn it.
Definitely other technologies are advancing at a pace XSLT hasn't since 2005ish, but it remains a powerful tool which gives you a level of abstraction that, say, asp.net webforms don't, and allows you to provide a general scalable solution to trivially serialise to a range of output formats. It's easy to generate HTML with any given language, it's harder to now extend that to XML, now extend that to JSON, now extend that to CSV.
And cached transforms are plenty fast enough in an environment which is still I/O bound.
OTOH, storing data in XML is generally not a good idea. Far better to store in a DB/mem and serialise as required for all the reasons above.
在工作中,我参与的一个项目使用了 XSLT,说实话,这真的很痛苦。 实际的 XSLT 文件并不难使用,但创建 XML 会增加额外的复杂性。 我还发现,除了最基本的页面之外,XML 往往会变得非常臃肿和混乱。 所以,不,我不会推荐它。
At work, a project I'm on uses XSLT and to be honest, it's a real pain. The actual XSLT files aren't that difficult to work with, but having to create XML adds an extra layer of complexity. I've also found that beyond the most basic pages, the XML tends to get very bloated and messy. So, no, I wouldn't recommend it.
我知道在波兰很少有大型门户网站大量使用 XSLT。 他们使用它是因为它可以最大限度地减少通过网络发送的数据量。
我还参与了该项目(大型 HRM 应用程序),我们在那里使用它来将我们的编程语言转换为 .NET。
我想说它有时非常有用。
I know few big web portals which work using XSLT a lot, here in Poland. They used because it can minimize the amount of data sent over the network.
I also worked on the project (Huge HRM application) and we used it there to transform our programming language to .NET.
I would say it is sometimes very useful.
XSLT 只是一种模板方法。 它也是完整的 MVC 框架的一部分,其中模板是视图组件。 XSLT 是一项伟大的技术,但它速度很慢,而且不是构建可扩展网站的首选。
研究 MVC 框架,看看哪一个最适合您。 例如 ASP.NET MVC、Ruby on Rails、CakePHP、Catalyst 等。
XSLT is just one method of templating. It is also just one piece of a complete MVC framework, where templating being the View component. XSLT is a great technology, but it's slow and not a first choice on building a scalable web site.
Research on MVC frameworks to see which one fits you best. e.g. ASP.NET MVC, Ruby on Rails, CakePHP, Catalyst, etc.
呃,什么? 有许多免费和开源的 CMS。
Spoulson 上面所说的关于模板的内容就是重点。 从输入 XML 文件提供输出页面就可以了。 但这并不能让您获得 CMS。 那么增删改查呢? 搜索? 页面列表?
如果您的网站很小,所有相关的更新都可以通过手动编辑一些 XML 文件来完成,那么为什么不呢,那就去做吧。 但如果这么简单,您不妨手动编辑 HTML。
Er, what? There are many free and open-source CMSs.
What spoulson said above about templating is the point. Providing output pages from input XML files is fine. But that doesn't get you a CMS. What about C.R.U.D.? Search? Page listings?
If your site is so small that all the relevant updating can be done by you hand-editing some XML files, then why not, go for it. But if it's that simple you might as well just edit HTML by hand.
我喜欢这个主意。 XSL 是一个很棒的工具,但是您必须经历过特殊的启发时刻才能意识到它到底有多么有用。 在此之前,它看起来只是马马虎虎。
我在各种应用程序中使用过 XSL,它为我节省了大量时间。 但显然不要只是为了使用它而使用它。
I like the idea. XSL is a fantastic tool, but you have to have that special moment of enlightenment before you realise how useful it really is. Before that it just seems so-so.
I have used XSL in a variety of applications and it has saved me a lot of time. But obviously dont just use it for the sake of it.
您所描述的内容已经存在,并且是 Apache Cocoon: http://cocoon.apache.org/
What you are describing already exists and is Apache Cocoon: http://cocoon.apache.org/
xslt很难吗?
解决复杂问题和复杂标准是程序员的工作。 有些东西更难但仍然需要。 只要坚持下去,每次你需要学习新东西时就会变得更容易。
Xslt 很容易。
真的吗! 有一些好书可以教您 xslt。 只需学习例如 rdf/owl (w3c 标准),它仍然会变得更加复杂......
xslt 很慢? 如果可以的话,请使用正确的缓存。 (好吧,这并不总是可能的......)。
只需阅读有关 REST 的内容(一些书或 Roy Fielding 的论文),这也是必不可少的内容。
现在,使用 XProc(xslt piplines)和一个围绕 calabash(Xproc 实现)的小型休息服务器,您可以归档这么多内容。 它绝对可以节省您的时间。 任何数据都可以导出为 XML,通过 REST 提供并使用 XProc 进行转换。
xslt is hard?
It's a programmers job to tackle complex problems and complex standards. There's stuff that is way harder and still needed. Just keep going at it and get's easier each time you need to learn new stuff.
Xslt is easy.
Really! There are good books out there that teach you xslt. Just learn e.g. rdf/owl (a w3c standard) and it can still get much more complex...
xslt is slow? Just use the right caching if you can. (ok, its not always possible...).
Just read about REST (some book or Roy Fielding dissertation) that's essential stuff too.
Now with XProc (xslt piplines) and a small restserver around calabash (Xproc implementaion) you can archive so much. it can definitly save you time. any data can be exportet to XML, made aviliable via REST and transformed with XProc.
Symphony CMS 使用 XSLT。 在使用该 CMS 时,我发现唯一真正的问题与学习 XSL/XPath 语法有关,这主要是由于缺乏良好的教程/文档。 如果您想了解一些相对现代的 XSLT 用法,那么 Symphony 可能值得一试。
Symphony CMS uses XSLT. While using that CMS I found that the only real problems I had were to do with learning the XSL/XPath syntax, mostly due to a lack of good tutorials/documentation. Might be worth giving Symphony a try if you want to see some relatively modern XSLT usage.
看看http://www.umbraco.org/ 它是一个免费的开源CMS工具,广泛使用 XSLT 来生成页面。
对于所有声称 XSLT 很难的人,我想说它并不比 SQL 难。 有些场景是困难的,例如分组,就像 SQL 树一样困难。
为正确的工作选择正确的工具,您应该不会遇到任何问题。
Take a look at http://www.umbraco.org/ It is a free open source CMS tool that uses XSLT extensively to generate pages.
To all those who claim XSLT is hard I would say that it is no harder than SQL. There are scenario's that are hard such as grouping, just like in SQL trees are hard.
Pick the right tool for the right job and you shouldn't have any problems.
附带说明一下,wowarmory.com 是使用 XSLT 的高流量网站的一个很好的示例。 事实上,我认为整个网站都使用它。
As a side note, wowarmory.com is a good example of a high traffic site that uses XSLT. In fact, I think the whole site uses it.
如果您的平台是 ASP.NET,请查看 myxsl
XSLT 使您能够进行不显眼的模板化,这在我看来,这是最终的模板类型。
If your platform is ASP.NET check out myxsl
XSLT gives you the ability to do unobtrusive templating, which is IMO the ultimate kind of templating.
对我来说听起来是个坏主意。 使用某些东西要容易得多
像 ASP.NET 一样存储内容
在数据库中 - 然后您可以更新
内容直接进入
数据库 - 它本身就是
比编辑 XML 更容易。
Sounds like a bad idea to me. It's much easier to use something
like ASP.NET with the content stored
in a database - you can then update
the content directly into the
database - which in itself will be
easier than editing the XML.