XSLT 值得吗? [英] Is XSLT worth it?

查看:34
本文介绍了XSLT 值得吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不久前,我开始了一个项目,在该项目中我设计了一个 html 式的 XML 模式,以便作者可以以简化的格式编写他们的内容(教育课程材料),然后通过 XSLT 将其转换为 HTML.我玩了(挣扎)了一段时间,并使其达到了一个非常基本的水平,但后来对我遇到的限制(这很可能是我的知识限制)以及当我阅读建议放弃的博客时感到非常恼火XSLT 并用您选择的语言编写您自己的 XML 到任何解析器,我急切地跳到它上面,它的效果非常好.

A while ago, I started on a project where I designed a html-esque XML schema so that authors could write their content (educational course material) in a simplified format which would then be transformed into HTML via XSLT. I played around (struggled) with it for a while and got it to a very basic level but then was too annoyed by the limitations I was encountering (which may well have been limitations of my knowledge) and when I read a blog suggesting to ditch XSLT and just write your own XML-to-whatever parser in your language of choice, I eagerly jumped onto that and it's worked out brilliantly.

直到今天我仍在努力(实际上我现在应该在努力,而不是在 SO 上玩),而且我看到越来越多的东西让我觉得放弃 XSLT 的决定是个好决定.

I'm still working on it to this day (I'm actually supposed to be working on it right now, instead of playing on SO), and I am seeing more and more things which make me think that the decision to ditch XSLT was a good one.

我知道 XSLT 有它的位置,因为它是一个公认的标准,如果每个人都在编写自己的解释器,那么 90% 的解释器最终都会在 TheDailyWTF.但鉴于它是一种函数式风格语言,而不是大多数程序员熟悉的程序式风格,对于开始着手一个项目的人,例如我自己的项目,您会建议他们沿着我的道路走下去,还是坚持使用 XSLT?

I know that XSLT has its place, in that it is an accepted standard, and that if everyone is writing their own interpreters, 90% of them will end up on TheDailyWTF. But given that it is a functional style language instead of the procedural style which most programmers are familiar with, for someone embarking on a project such as my own, would you recommend they go down the path that I did, or stick it out with XSLT?

推荐答案

负面影响太多!

我已经使用 XSLT 好几年了,真的很喜欢它.您必须意识到的关键是它不是一种编程语言,而是一种模板语言(在这方面,我发现它比 asp.net/spit 优越得多).

I've been using XSLT for a good few years now, and genuinely love it. The key thing you have to realise is that it's not a programming language it's a templating language (and in this respect I find it indescribably superior to asp.net /spit).

XML 是当今 Web 开发的事实上的数据格式,无论是配置文件、原始数据还是内存中的表示.XSLT 和 XPath 为您提供了一种非常强大且非常有效的方法来将数据转换为您可能喜欢的任何输出格式,从而立即为您提供将表示与数据分离的 MVC 方面.

XML is the de facto data format of web development today, be it config files, raw data or in memory reprsentation. XSLT and XPath give you an enormously powerful and very efficient way to transform that data into any output format you might like, instantly giving you that MVC aspect of separating the presentation from the data.

然后是实用功能:清除命名空间、识别不同的架构定义、合并文档.

Then there's the utility abilities: washing out namespaces, recognising disparate schema definitions, merging documents.

必须处理 XSLT 比开发您自己的内部方法更好.至少 XSLT 是一个标准,并且您可以为其聘请一些东西,如果这对您的团队来说真的是一个问题,那么您的团队中的大部分人就可以只使用 XML.

It must be better to deal with XSLT than developing your own in-house methods. At least XSLT is a standard and something you could hire for, and if it's ever really a problem for your team it's very nature would let you keep most of your team working with just XML.

一个真实世界的用例:我刚刚编写了一个应用程序,它处理整个系统的内存中的 XML 文档,并根据最终用户的要求转换为 JSON、HTML 或 XML.我有一个相当随机的要求提供 Excel 数据.一位前同事以编程方式做了类似的事情,但它需要一个包含几个类文件的模块,并且服务器安装了 MS Office!结果证明 Excel 具有 XSD:新功能在 3 小时内对基本代码的影响最小.

A real world use case: I just wrote an app which handles in-memory XML docs throughout the system, and transforms to JSON, HTML, or XML as requested by the end user. I had a fairly random request to provide as Excel data. A former colleague had done something similar programatically but it required a module of a few class files and that the server had MS Office installed! Turns out Excel has an XSD: new functionality with minimum basecode impact in 3 hours.

就我个人而言,我认为这是我职业生涯中遇到的最干净的事情之一,而且我相信所有这些明显的问题(调试、字符串操作、编程结构)都归结为对工具的错误理解.

Personally I think it's one of the cleanest things I've encountered in my career, and I believe all of it's apparent issues (debugging, string manipulation, programming structures) are down to a flawed understanding of the tool.

显然,我坚信这是值得的".

Obviously, I strongly believe it is "worth it".

这篇关于XSLT 值得吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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