将 XSLT 1.0 升级到 XSLT 2.0 [英] Upgrading XSLT 1.0 to XSLT 2.0

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

问题描述

从 XSLT 1.0 升级到 2.0 涉及什么?
1 - 升级的可能原因是什么?
2 - 不升级的可能原因是什么?
3 - 最后,升级的步骤是什么?

What is involved in upgrading from XSLT 1.0 to 2.0?
1 - What are the possible reasons for upgrading?
2 - What are the possible reasons for NOT upgrading?
3 - And finally, what are the steps to upgrading?

我希望有一个执行摘要——简短版本:)

I'm hoping for an executive summary--the short version :)

推荐答案

从 XSLT 1.0 升级到 2.0 涉及什么?

What is involved in upgrading from XSLT 1.0 to 2.0?

1 - 升级的可能原因是什么?

1 - What are the possible reasons for upgrading?

如果您是 XSLT 程序员,您将受益于更方便和更具表现力的 XSLT 2.0 语言 + XPath 2.0 和新的 XDM(XPath 数据模型).​​

If you are an XSLT programmer you'll benefit largely from the more convenient and expressive XSLT 2.0 language + XPath 2.0 and the new XDM (XPath Data Model).

您可能想观看此XSLT 2.0 Pluralsight 课程,以获得坚定而系统的理解XSLT 2.0 的强大功能.

You may want to watch this XSLT 2.0 Pluralsight course to get firm and systematic understanding of the power of XSLT 2.0.

你有:

  • 强类型和所有可用的 XSD 类型.

  • Strong typing and all XSD types available.

定义您自己的(架构)类型的能力.

The ability to define your own (schema) types.

在 XPath 1.0 中没有任何对应物(只是缺少)的 XPath 2.0 序列类型.

the XPath 2.0 sequence type that doesn't have any counterpart (simply is missing) in XPath 1.0.

在纯 XSLT 中定义和编写函数的能力——xsl:function 指令.

The ability to define and write functions in pure XSLT -- the xsl:function instruction.

XPath 表达式中的范围变量(for 子句).

Range variables in XPath expressions (the for clause).

更好、更强大的字符串处理 -- XPath 2.0 在其 tokenize()matches()replace() 中支持正则表达式 函数.

Much better and more powerful string processing -- XPath 2.0 supports regular expressions in its tokenize(), matches() and replace() functions.

更好、更强大的字符串处理 -- XSLT 2.0 对正则表达式的支持 -- xsl:analyze-stringxsl:matching-substringxsl:non-matching-substring 新的 XSLT 指令.

Much better and more powerful string processing -- XSLT 2.0 support for regular expressions -- the xsl:analyze-string, xsl:matching-substring and xsl:non-matching-substring new XSLT instructions.

更方便、强大和富有表现力的分组:xsl:for-each-group 指令.

More convenient, powerful and expressive grouping: the xsl:for-each-group instruction.

许多新的、非常强大的 XPath 2.0 函数 -- 例如日期、时间和持续时间的函数,仅举几例.

A lot of new, very powerful XPath 2.0 functions -- such as the functions on date, time and duration, just to name a few.

新的 XPath 运算符 intersectexceptis>><<, some, every, instance of, castable as, ... 等

The new XPath operators intersect, except, is, >>, <<, some, every, instance of, castable as, ..., etc.

通用 XPath 运算符 >< 等现在适用于任何有序值类型(不仅适用于 XPath 1.0 中的数字).

The general XPath operators >, <, etc. now work on any ordered value type (not only on numbers as in XPath 1.0).

新的、更安全的值比较运算符:ltleeqgtge, ne.

New, safer value comparison operators: lt, le, eq, gt, ge, ne.

XPath 2.0 to 运算符,允许使用 xsl:for-each select="1 to $N"

The XPath 2.0 to operator, allowing to have xsl:for-each select="1 to $N"

这些以及许多其他改进/新功能显着提高了任何 XSLT 程序员的工作效率,这使得 XSLT 2.0 开发可以在使用 XSLT 1.0 开发相同模块所需的一小部分时间内完成.

These, and many other improvements/new features significantly increase the productivity of any XSLT programmer, which allows XSLT 2.0 development to be finished in a small fraction of the time necessary for developing the same modules with XSLT 1.0.

强类型允许在编译时捕获许多错误并立即更正.对我来说,这种强大的类型安全性是使用 XSLT 2.0 的最大优势.

Strong typing allows many errors to be caught at compile time and to be corrected immediately. For me this strong type-safety is the biggest advantage of using XSLT 2.0.

2 - 不升级的可能原因是什么?

2 - What are the possible reasons for NOT upgrading?

  • 保留现有的、遗留的 XSLT 1.0 应用程序并继续将它们与 XSLT 1.0 一起使用,同时只开发应用程序通常是可能的、合理的和具有成本效益的使用 XSLT 2.0.

    • It is often possible, reasonable and cost-efficient to leave existing, legacy XSLT 1.0 applications untouched and to continue using them with XSLT 1.0, while at the same time developing only new applications using XSLT 2.0.

      您的管理层 + 任何其他非技术原因.

      Your management + any other non-technical reasons.

      有很多以糟糕风格编写的遗留 XSLT 1.0 应用程序(例如,使用现在需要重写和重构代码的 DOE 或扩展函数).

      Having a lot of legacy XSLT 1.0 applications written in a poor style (e.g. using DOE or extension functions that now need to be re-written and the code refactored).

      没有可用的 XSLT 2.0 处理器.

      Not having available an XSLT 2.0 processor.

      3 - 最后,升级的步骤是什么?

      3 - And finally, what are the steps to upgrading?

      • "1.0" 更改 xsl:stylesheetxsl:transform 元素的 version 属性code> 到 "2.0".

        • Change the version attribute of the xsl:stylesheet or xsl:transform element from "1.0" to "2.0".

          删除任何 xxx:node-set() 函数.

          删除任何 DOE.

          准备好迎接惊喜吧,xsl:value-of 现在不仅输出序列的第一个项,而且输出所有 项.

          Be ready for the surprise that xsl:value-of now outputs not just the first, but all items of a sequence.

          尽量使用新的xsl:sequence指令——用它来代替任何xsl:copy-of指令;当输出的类型不是字符串或文本节点时,请随时使用它代替 xsl:value-of.

          Try to use the new xsl:sequence instruction as much as possible -- use it to replace any xsl:copy-of instructions; use it instead of xsl:value-of any time when the type of the output isn't string or text node.

          广泛测试.

          当测试验证代码按预期工作时,开始重构(如果认为有必要).为任何变量、参数、模板和函数声明类型是个好主意.这样做可能会发现新的、隐藏的错误,修复它们可以提高代码的质量.

          When the testing has verified that the code works as expected, start refactoring (if deemed necessary). It is a good idea to declare types for any variables, parameters, templates and functions. Doing so may reveal new, hidden errors and fixing them increases the quality of your code.

          (可选)决定将哪些命名模板重写为 xsl:function.

          Optionally, decide which named templates to rewrite as xsl:function.

          确定您是否仍然需要旧版本中使用的一些扩展函数,或者您可以使用 XSLT 新的强大功能轻松重写它们.

          Decide if you still need some extension functions that are used in the old version, or you can rewrite them easily using the new, powerful capabilities of XSLT.

          最后的评论:并非所有上述步骤都是必需的,可以在零错误测试结果上停止并宣布迁移成功.在项目中开始使用所有 XSLT 2.0/XPath 2.0 功能要干净得多.

          Final remarks: Not all of the above steps are necessary and one can stop and declare the migration successful on zero bug testing results. It is much cleaner to start using all XSLT 2.0/XPath 2.0 features in new projects.

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

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