I know that XSLT is used for XML to HTML transformation using xsl. But i want to know that is there any benefit to write xml code and convert it into HTML, instead to directly write HTML code.
我知道XSLT用于使用xsl进行XML到HTML的转换。但我想知道编写xml代码并将其转换为HTML有什么好处,而不是直接编写HTML代码。
3 个解决方案
#1
1
It depends, but in many cases the answer is yes. XSLT is really good to convert from one for of XML to another and there are places that need specifically that. In the scenario you're describing, HTML is one of the outputs. If it's the only output, it's probably more effort than it's worth to convert back and forth every time. If, on the other hand, you expecting different HTML outputs, then XML is the neutral way to go. If you're expecting more outputs such as PDF, SCORM or ebook then XML makes even more sense.
这取决于,但在许多情况下答案是肯定的。 XSLT非常适合从XML转换为另一个,并且有些地方需要特别需要。在您描述的场景中,HTML是输出之一。如果它是唯一的输出,那么每次来回转换可能需要付出更多的努力。另一方面,如果您期望不同的HTML输出,那么XML是中立的方式。如果你期望更多的输出,如PDF,SCORM或电子书,那么XML更有意义。
A good analogy here is a database - you don't really need a database to run a website, but any serious website has one. In that sense you also don't need XML for a simple project, but as your needs get more complex, XML gives you that intermediate layer to manage your data. With XML come technologies like W3C Schema or Schematron that allow to validate XML and check XML for various contraints which again are an overkill for a personal website, but give you a lot of power when managing lots of data from multiple sources.
这里一个很好的类比是一个数据库 - 你不需要一个数据库来运行一个网站,但任何一个严肃的网站都有一个。从这个意义上讲,对于一个简单的项目,您也不需要XML,但随着您的需求变得更加复杂,XML为您提供了管理数据的中间层。使用XML,W3C Schema或Schematron等技术可以验证XML并检查XML的各种约束,这对于个人网站来说也是一种过度杀伤,但在管理来自多个来源的大量数据时会给你很大的帮助。
#2
0
Depends on whether that XML is used to store data that can (and/or will) be used elsewhere in another form by other systems.
取决于该XML是否用于存储可以(和/或将要)在其他系统的其他形式的其他地方使用的数据。
XML allows information to be stored in a way so it is accesible for other systems. F.E. Microsoft Office, OpenOffice and iWorks all use XML based formats to store information. This allows for easy conversion between the different software packages.
XML允许以某种方式存储信息,以便可以访问其他系统。 F.E.Microsoft Office,OpenOffice和iWorks都使用基于XML的格式来存储信息。这允许在不同软件包之间轻松转换。
To answer your question: if you just want to display some content on a website and that content is not used anywhere else, I don't see any use in using XML and XSLT for this. HTML fits the purpose just fine. But if you want that content to be used by various systems, XML could be an option.
回答你的问题:如果你只是想在网站上显示某些内容而且其他地方没有使用这些内容,我认为在使用XML和XSLT方面没有任何用处。 HTML符合目的就好了。但是,如果您希望各种系统使用该内容,那么XML可能是一种选择。
#3
0
First off, note that xslt is not primarily targeted at HTML, but to transform from one XML file to another.
首先,请注意xslt不是主要针对HTML,而是从一个XML文件转换到另一个XML文件。
That said, let’s focus on an important niche application: Using XSLT within web pages. I haven’t done that myself just yet (since I’m not creating web pages that much), but have some general idea of some of the reasons why one would.
也就是说,让我们专注于一个重要的利基应用:在网页中使用XSLT。我自己还没有这样做(因为我不是那么多地创建网页),但是对于为什么会这样做有一些原因。
For starters, you may want to present something that is available in XML anyway, from DocBook to Excel exports to some unusual reports of your company’s income sheet. That data may update regularly, but you do not want to manually create HTML all the time. You could include XSLT to load and transform/display that xml data, making your users happy.
对于初学者,您可能想要提供XML格式的东西,从DocBook到Excel导出到贵公司收入表的一些不寻常的报告。该数据可能会定期更新,但您不希望一直手动创建HTML。您可以包含XSLT来加载和转换/显示该xml数据,从而使您的用户满意。
What’s more: If you do the transformation in the client, you can do much more than just creating a fixed HTML table. You can include filters and sorting in your transformation, and include various display styles – of course, you could do all that on the server as well, but you need to implement it anyway, you need to have a server in the first place (XSLT works just fine reading from the file system, I believe), and if the data set is large, doing the transformation on the client may be much more responsive than retransmitting everything just because the user enabled the date column.
更重要的是:如果您在客户端进行转换,那么除了创建固定的HTML表之外,您还可以做更多的事情。您可以在转换中包含过滤器和排序,并包括各种显示样式 - 当然,您也可以在服务器上执行所有这些,但无论如何您需要实现它,您需要首先拥有一台服务器(XSLT)我认为,从文件系统中读取效果很好,如果数据集很大,那么在客户端上进行转换可能比仅仅因为用户启用了日期列而重新传输所有内容的响应要快得多。
#1
1
It depends, but in many cases the answer is yes. XSLT is really good to convert from one for of XML to another and there are places that need specifically that. In the scenario you're describing, HTML is one of the outputs. If it's the only output, it's probably more effort than it's worth to convert back and forth every time. If, on the other hand, you expecting different HTML outputs, then XML is the neutral way to go. If you're expecting more outputs such as PDF, SCORM or ebook then XML makes even more sense.
这取决于,但在许多情况下答案是肯定的。 XSLT非常适合从XML转换为另一个,并且有些地方需要特别需要。在您描述的场景中,HTML是输出之一。如果它是唯一的输出,那么每次来回转换可能需要付出更多的努力。另一方面,如果您期望不同的HTML输出,那么XML是中立的方式。如果你期望更多的输出,如PDF,SCORM或电子书,那么XML更有意义。
A good analogy here is a database - you don't really need a database to run a website, but any serious website has one. In that sense you also don't need XML for a simple project, but as your needs get more complex, XML gives you that intermediate layer to manage your data. With XML come technologies like W3C Schema or Schematron that allow to validate XML and check XML for various contraints which again are an overkill for a personal website, but give you a lot of power when managing lots of data from multiple sources.
这里一个很好的类比是一个数据库 - 你不需要一个数据库来运行一个网站,但任何一个严肃的网站都有一个。从这个意义上讲,对于一个简单的项目,您也不需要XML,但随着您的需求变得更加复杂,XML为您提供了管理数据的中间层。使用XML,W3C Schema或Schematron等技术可以验证XML并检查XML的各种约束,这对于个人网站来说也是一种过度杀伤,但在管理来自多个来源的大量数据时会给你很大的帮助。
#2
0
Depends on whether that XML is used to store data that can (and/or will) be used elsewhere in another form by other systems.
取决于该XML是否用于存储可以(和/或将要)在其他系统的其他形式的其他地方使用的数据。
XML allows information to be stored in a way so it is accesible for other systems. F.E. Microsoft Office, OpenOffice and iWorks all use XML based formats to store information. This allows for easy conversion between the different software packages.
XML允许以某种方式存储信息,以便可以访问其他系统。 F.E.Microsoft Office,OpenOffice和iWorks都使用基于XML的格式来存储信息。这允许在不同软件包之间轻松转换。
To answer your question: if you just want to display some content on a website and that content is not used anywhere else, I don't see any use in using XML and XSLT for this. HTML fits the purpose just fine. But if you want that content to be used by various systems, XML could be an option.
回答你的问题:如果你只是想在网站上显示某些内容而且其他地方没有使用这些内容,我认为在使用XML和XSLT方面没有任何用处。 HTML符合目的就好了。但是,如果您希望各种系统使用该内容,那么XML可能是一种选择。
#3
0
First off, note that xslt is not primarily targeted at HTML, but to transform from one XML file to another.
首先,请注意xslt不是主要针对HTML,而是从一个XML文件转换到另一个XML文件。
That said, let’s focus on an important niche application: Using XSLT within web pages. I haven’t done that myself just yet (since I’m not creating web pages that much), but have some general idea of some of the reasons why one would.
也就是说,让我们专注于一个重要的利基应用:在网页中使用XSLT。我自己还没有这样做(因为我不是那么多地创建网页),但是对于为什么会这样做有一些原因。
For starters, you may want to present something that is available in XML anyway, from DocBook to Excel exports to some unusual reports of your company’s income sheet. That data may update regularly, but you do not want to manually create HTML all the time. You could include XSLT to load and transform/display that xml data, making your users happy.
对于初学者,您可能想要提供XML格式的东西,从DocBook到Excel导出到贵公司收入表的一些不寻常的报告。该数据可能会定期更新,但您不希望一直手动创建HTML。您可以包含XSLT来加载和转换/显示该xml数据,从而使您的用户满意。
What’s more: If you do the transformation in the client, you can do much more than just creating a fixed HTML table. You can include filters and sorting in your transformation, and include various display styles – of course, you could do all that on the server as well, but you need to implement it anyway, you need to have a server in the first place (XSLT works just fine reading from the file system, I believe), and if the data set is large, doing the transformation on the client may be much more responsive than retransmitting everything just because the user enabled the date column.
更重要的是:如果您在客户端进行转换,那么除了创建固定的HTML表之外,您还可以做更多的事情。您可以在转换中包含过滤器和排序,并包括各种显示样式 - 当然,您也可以在服务器上执行所有这些,但无论如何您需要实现它,您需要首先拥有一台服务器(XSLT)我认为,从文件系统中读取效果很好,如果数据集很大,那么在客户端上进行转换可能比仅仅因为用户启用了日期列而重新传输所有内容的响应要快得多。