Best way to perform XSL transformation in Ruby (XSLT 2.0)
Asked Answered
I

1

7

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

The stylesheet works perfectly in my XML editor.

I'm using Ruby 1.9.3 on Linux.


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

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

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.

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

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.

Illogic answered 21/12, 2010 at 11:12 Comment(5)
Why do you want to perform an XSL transformation? Just curious.Iila
Please post the source code you use to make the transform. Also, please post the simplest test case that demonstrates the problem. Include an XML snippet, the XSL used, and the Ruby code that calls the XSL transformer.Telespectroscope
see https://mcmap.net/q/1625574/-xslt-2-0-and-ruby-on-os-xKristiekristien
"I wish Nokogiri responded to it in a more meaningful way." I think that blames Nokogiri for something that isn't in its control, so really your statement should be "I wish libxml2 had that capability."Chicanery
I can sort of sympathize with the problem here; I think what he wanted is for Nokogiri to give a more useful error message than just "error", which would have lead to the more obvious path that what he was doing isn't actually supported.Jezabel
A
5

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.

Antemundane answered 6/1, 2015 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.