Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 319
Vincent Avatar asked Dec 21 '10 11:12

Vincent


People also ask

Is XSL obsolete?

The XslTransform class is obsolete in the Microsoft . NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor.

Which is the processor of XSLT transformation?

This transformation process is specified by the W3C XSL Transformations (XSLT) Version 1.0 recommendation. The XslCompiledTransform class is the XSLT processor in .


1 Answers

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.

like image 196
ronan_mac Avatar answered Sep 29 '22 16:09

ronan_mac