简体   繁体   English

ASP.NET MVC与XSL

[英]ASP.NET MVC vs. XSL

Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of data on a web-page with XSL over ASP.NET MVC? 任何人(也许是一个XSL粉丝?)可以帮助我找到在使用XSL over ASP.NET MVC的网页上处理数据呈现的任何优势吗?

The two alternatives are: 两种选择是:

  1. ASP.NET (MVC/WebForms) with XSL 使用XSL的ASP.NET(MVC / WebForms)
    Getting the data from the database and transforming it to XML which is then displayed on the different pages with XSL-templates. 从数据库获取数据并将其转换为XML,然后使用XSL模板在不同的页面上显示。

  2. ASP.NET MVC ASP.NET MVC
    Getting the data from the database as C# objects (or LinqToSql/EF-objects) and displaying it with inline-code on MVC-pages. 从数据库获取数据作为C#对象(或LinqToSql / EF对象)并在MVC页面上使用内联代码显示它。

The main benefit of XSL has been consistent display of data on many different pages, like WebControls. XSL的主要优点是在WebControls等许多不同页面上一致显示数据。 So, correct me if I'm wrong, ASP.NET MVC can be used the same way, but with strongly typed objects. 所以,如果我错了,请纠正我,ASP.NET MVC可以使用相同的方式,但使用强类型对象。 Please help me see if there are any benefits to XSL. 请帮我看看XSL是否有任何好处。

I can see the main benefit of employing XSLT to transform your data and display it to the user would be the following: 我可以看到使用XSLT转换数据并将其显示给用户的主要好处如下:

  • The data is already in an XML format 数据已经是XML格式
  • The data follows a well defined schema (this makes using tools like XMLSpy much easier). 数据遵循定义良好的模式(这使得使用XMLSpy等工具变得更加容易)。
  • The data needs to be transformed into a number of different output formats, eg PDF, WMP and HTML 数据需要转换为许多不同的输出格式,例如PDF,WMP和HTML

If this is to be the only output for your data, and it is not in XML format, then XSLT might not be the best solution. 如果这是您的数据的唯一输出,并且它不是XML格式,那么XSLT可能不是最佳解决方案。

Likewise if user interaction is required (such as editing of the data) then you will end up employing back-end code anyway to handle updates so might prove one technology too far... 同样,如果需要用户交互(例如编辑数据),那么最终会使用后端代码来处理更新,因此可能证明一项技术太过分了......

I've always found two main issues when working with XML transformations: 在使用XML转换时,我总是发现两个主要问题:

Firstly they tend to be quite slow, the whole XML file must be parsed and validated before you can do anything with it. 首先,它们往往很慢,必须先解析和验证整个XML文件,然后才能对它做任何事情。 Being XML it's also excessively verbose, and therefore larger than it needs to be. 作为XML,它也过于冗长,因此比它需要的要大。

Secondly the way transformations work is a bit of a pain to code - custom tools like XmlSpy help, but it's still a different model to what most developers are used to. 其次,转换的工作方式对代码来说有点痛苦 - 像XmlSpy这样的自定义工具有帮助,但它仍然是大多数开发人员习惯的不同模型。

At the moment MVC is very quick and looking very promising, but does suffer from the traditional web-development blight of <% and %> bee-stings all over your code. 目前,MVC非常快,看起来非常有前途,但确实遭受了整个代码中传统的网络开发障碍<%%> Using XML transformations avoids that, but is much harder to read and maintain. 使用XML转换避免了这种情况,但更难以阅读和维护。

I've used that technique in the past, and there are applications where we use it at my current place of employment. 我过去曾使用过这种技术,有些应用我们在目前的工作场所使用它。 (I will admit, I am not totally a fan of it, but I'll play devil's advocate) Really that is one of the main advatages, and pushing this idea can be kinda neat. (我承认,我不是完全忠实于它,但我会扮演魔鬼的拥护者)真的,这是主要的优点之一,推动这个想法可能有点整洁。 You're able to dynamically create the xsl on the fly and change the look and feel of the page on a whim. 您可以动态地动态创建xsl并随心所欲地更改页面的外观。 Is it possible to do this through the other methods...yes, but it's really easy to build a program to modify an xml/xsl document on the fly. 是否可以通过其他方法执行此操作...是的,但是构建一个程序来动态修改xml / xsl文档非常容易。

If you think of using XSL to transform one xml document to another and displaying it as html (which is really what you're doing), you're opening up your system to allow other programs to access the data on the page via XML. 如果您考虑使用XSL将一个xml文档转换为另一个xml文档并将其显示为html(这正是您正在做的事情),那么您将打开系统以允许其他程序通过XML访问页面上的数据。 You can do this through the other methods, but using an xsl transformation forces it to output xml every time. 您可以通过其他方法执行此操作,但使用xsl转换会强制它每次都输出xml。

I would tread lightly with creating a system this way. 我会轻易地以这种方式创建一个系统。 You'll find a lot of pit falls you aren't expecting, and if you don't know xsl really really well, there is going to be a learning curve also. 你会发现很多你不期待的陷阱,如果你真的不太了解xsl,那么也会有一个学习曲线。

Jafar Husain offers a few advantages in his proposal for Pretty XSL , primarily caching of the stylesheet to increase page load and reduce the size of your data. Jafar Husain在他的Pretty XSL提案中提供了一些优势,主要是缓存样式表以增加页面负载并减小数据大小。 Steve Sanderson proposed a slightly different approach using JavaScript as the controller here . 史蒂夫·桑德森提出使用JavaScript作为控制器稍微不同的方法在这里

Another, similar approach would be to use XForms , though the best support for it is through a JavaScript library . 另一种类似的方法是使用XForms ,尽管对它的最佳支持是通过JavaScript库

Check this out if you want to use XSLT and ASP.MVC 如果要使用XSLT和ASP.MVC,请检查此问题

http://www.bleevo.com/2009/06/aspnet-mvc-xslt-iviewengine/ http://www.bleevo.com/2009/06/aspnet-mvc-xslt-iviewengine/

If you only going to display data from DB XSL templates may be convenient solution, but if you gonna handle user interaction. 如果你只是从DB XSL模板显示数据可能是方便的解决方案,但如果你要处理用户交互。 Hm... I don't think it'll be maintainable at all. 嗯......我认为它根本不可维护。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM