XSLT:有没有办法“继承”罐装功能?

发布于 2024-08-30 14:17:12 字数 459 浏览 10 评论 0原文

我再次不得不拼凑一些 XSLT 以便将生成的 XML 转换为(而不是简单地生成 HTML)。

这次我又产生了巨大的似曾相识的感觉。我再次必须解决基本问题,例如:

  • 如何将字符转换为有效的 html 实体引用
  • 如何在转换为 html 时保留空格/回车符
  • 如何转换为 HTML 而不是 xhtml
  • 如何从 xml 格式 转换为可呈现的格式
  • 如何用子字符串拆分字符串

这都是我之前多次解决过的问题。但每次我回到 XSLT 时,我都必须从头开始,每次都重新发明轮子。

如果它是一种编程语言,我将拥有一个可以调用的预设函数和过程的库。我会有子程序来执行经常重复的任务。我将从一个已经实现了丑陋的样板内容的基类继承。

XSLT 中是否有任何方法可以通过预装代码来发展、扩展和改进生态系统?

i am once again having to cobble together a bit of XSLT into order to turn generated XML into (rather than simply generating HTML).

i'm having huge deja-vu this time again. i'm once again having to solve again basic problems, e.g.:

  • how to convert characters into valid html entity references
  • how to preserve whitespace/carriage returns when converting to html
  • how to convert to HTML as opposed to xhtml
  • how to convert dates from xml format into presentable format
  • how to tear apart strings with substring

This is all stuff that i've solved many times before. But every time i come back to XSLT i have to start from scratch, re-inventing the wheel every time.

If it were a programming language i would have a library of canned functions and procedures i can call. i would have subroutines to perform the commonly repeated tasks. i would inherit from a base class that already implements the ugly boilerplate stuff.

Is there any way in XSLT to grow, expand and improve the ecosystem with canned code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

行雁书 2024-09-06 14:17:12

这就是我已经解决的所有问题
之前很多次。但每次我
回到 XSLT 我必须从
从头开始,每次都重新发明轮子
时间。

当然这不是必需的

如果它是一种编程语言

是的,XSLT 一种编程语言

我想要一个罐装图书馆
我可以调用的函数和过程。我
将有子例程来执行
经常重复的任务。

是的,您可以在 XSLT 中执行此操作。

我愿意
从已经存在的基类继承
实现了丑陋的样板内容。

是的,XSLT 中有一些非常相似的东西

XSLT 有什么办法可以增长吗?
扩大和改善生态系统
预装代码?

即使在 XSLT 1.0 中,也有支持可重用性的强大标准功能

  1. < /a>

XSLT 2.0 添加了一些更强大的功能

  1. 的参数

有多个 XSLT 库已经存在相当长一段时间了:

  1. FXSL (1.x2.x) 在 XSLT 1.0/2.0 中实现高阶函数
  2. FunctX —— 有用的 XSLT 2.0 和 XQuery 函数的库。

XPath 2.1XSLT 2.1 添加高阶函数作为标准。函数成为一流的数据类型。

This is all stuff that i've solved
many times before. But every time i
come back to XSLT i have to start from
scratch, re-inventing the wheel every
time.

This isn't necessary, of course.

If it were a programming language

Yes, XSLT is a programming language.

i would have a library of canned
functions and procedures i can call. i
would have subroutines to perform the
commonly repeated tasks.

Yes, you can do this in XSLT.

i would
inherit from a base class that already
implements the ugly boilerplate stuff.

Yes, there is something quite similar in XSLT.

Is there any way in XSLT to grow,
expand and improve the ecosystem with
canned code?

Even in XSLT 1.0 there are powerful, standard features that support reusability:

  1. <xsl:import>
  2. <xsl:include>
  3. <xsl:apply-templates>
  4. <xsl:call-template>
  5. <xsl:apply-imports>

XSLT 2.0 adds a few even more powerful features:

  1. <xsl:function>
  2. Parameters for <xsl:apply-imports>
  3. <xsl:next-match>

There have been several XSLT libraries for quite some time:

  1. FXSL (1.x and 2.x) implements Higher-Order Functions in XSLT 1.0/2.0
  2. FunctX -- a library of useful XSLT 2.0 and XQuery functions.

XPath 2.1 and XSLT 2.1 add Higher-Order Functions as standard. Functions become first-class datatypes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文