在 Ruby (XSLT 2.0) 中执行 XSL 转换的最佳方式 [英] Best way to perform XSL transformation in Ruby (XSLT 2.0)

查看:28
本文介绍了在 Ruby (XSLT 2.0) 中执行 XSL 转换的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Ruby 中执行 XSL 转换的最佳和最有效的方法是什么?我尝试过 Nokogiri,但无论我尝试什么,结果总是:

What would be the best and most efficient way to to perform XSL transformation in Ruby? I have tried Nokogiri, but no matter what I tried it always results in:

compilation error: element stylesheet

样式表在我的 XML 编辑器中完美运行.

The stylesheet works perfectly in my XML editor.

我在 Linux 上使用 Ruby 1.9.3.

I'm using Ruby 1.9.3 on Linux.

翻来覆去,我发现 Nokogiri 不支持 XSLT 2.0:

After poking around, I found out that Nokogiri does not support XSLT 2.0:

Nokogiri 使用 libxml2,它只支持 XPath 1.0/XSLT1.0

Nokogiri uses libxml2, which only supports XPath 1.0/XSLT1.0

我的样式表是使用 XSLT 2.0 语法编写的.我更新了这个问题的标题以反映这一点.我希望 Nokogiri 以更有意义的方式回应它.

My stylesheet was written using XSLT 2.0 syntax. I updated the title of this question to reflect this. I wish Nokogiri responded to it in a more meaningful way.

为什么要执行 XSL 转换?只是好奇.

Why do you want to perform an XSL transformation? Just curious.

我正在开发一个向其他网站提交 XML 提要的网站.每个提要具有不同的格式,但提要的数据源是相同的.因此,我决定使用从数据库提供的 XSL 样式表,而不是为每个提要编写自定义代码.这样我就可以通过上传新的样式表来创建新的提要.

I'm working on a website that submits XML feeds to other sites. Every feed has a different format, but the source of data for the feed is the same. So, instead of writing custom code for every feed I decided to use XSL stylesheets, served from a database. This way I can create new feeds just by uploading a new stylesheet.

推荐答案

通过 saxon-xslt gem.我认为不可能通过其他 Ruby 实现来做到这一点.当然,MRI ruby​​ 将依赖于尚未实现 XPath 2.0 的 libxml.有关详细信息,请参阅此主题.

It is possible to use XSLT 2.0 in JRuby via the saxon-xslt gem. I don't think it's possible to do it via other Ruby implementations. Certainly MRI ruby would depend on libxml which hasn't implemented XPath 2.0 yet. See this thread for more information.

这篇关于在 Ruby (XSLT 2.0) 中执行 XSL 转换的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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