XSLT 的替代方案?

发布于 2024-12-10 18:44:53 字数 212 浏览 0 评论 0原文

在我的项目中,我有一个 huuuuge XSLT,用于将一些 XML 文件转换为 HTML。 问题是这个文件日益增大,难以阅读、调试和测试。 所以我正在考虑将所有解析过程移至Java。

你认为这是个好主意吗?如果您建议使用哪些库来解析 XML 并生成 HTML(XML)?表现会更好还是更差?

如果这不是一个好主意,还有其他想法吗?

谢谢

随机化

on my project I have a huuuuge XSLT used to convert some XML files to HTML.
The problem is that this file is growing up day by day, it's hard to read, debug and test.
So I was thinking about moving all the parsing process to Java.

Do you think is a good idea? In case what libraries to parse XML and generate HTML(XML) do u suggest? performances will be better or worse?

If it's not a good idea any alternative idea?

Thanks

Randomize

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

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

发布评论

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

评论(3

后eg是否自 2024-12-17 18:44:53

看一下 CDuce - 它是一种严格类型、静态编译的 XML 处理语言。

Take a look at CDuce - it is a strictly typed, statically compiled XML processing language.

肤浅与狂妄 2024-12-17 18:44:53

我曾经有一个客户遇到过类似的问题 - 数千行 XSLT,并且一直在增长。我花了一个小时带着越来越怀疑的心情阅读它,然后用 20 行 XSLT 重写了它。

重构往往是一个好主意,而且代码越糟糕,就越值得重构。但没有理由相信仅仅因为代码很糟糕并且需要重构,您就需要更改为不同的编程语言。如果您知道如何正确使用 XST,它实际上非常擅长处理多样性和复杂性。

代码可能是对特殊情况进行特殊处理的累积,并且发现的每个新的特殊情况都会导致添加更多规则。对于任何语言来说,这都是一个很难解决的问题,但是 XSLT 可以比大多数语言更好地处理这个问题,只要您一直用心寻找包含所有特殊规则的抽象一般规则,因此您只需将特殊规则编码为例外情况。

I once had a client with a similar problem - thousands of lines of XSLT, growing all the time. I spent an hour reading it with increasing incredulity, then rewrote it in 20 lines of XSLT.

Refactoring is often a good idea, and the worse the code is, the more worthwhile refactoring is. But there's no reason to believe that just because the code is bad and in need of refactoring, you need to change to a different programming language. XST is actually very good at handling variety and complexity if you know how to use it properly.

It's possible that the code is an accumulation of special handling of special cases, and each new special case discovered results in more rules being added. That's a tough problem to tackle in any language, but XSLT can deal with it better than most, provided you apply your mind all the time to finding abstract general rules that encompass all the special rules, so you only need to code the special rules as exceptions.

咽泪装欢 2024-12-17 18:44:53

我会考虑使用 Velocity 作为替代方案。与 XSL-T 相比,我更喜欢它。转换比模板更难编写,因为后者看起来与我希望生成的 XML 完全相同。添加标记以映射数据是一件简单的事情。

I'd consider Velocity as an alternative. I prefer it to XSL-T. The transforms are harder to write than templates, because the latter look exactly like the XML I wish to produce. It's a simple thing to add in the markup to map in the data.

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