Skip to content
This repository

Ruby/XSLT is a simple XSLT class based on libxml <xmlsoft.org/> and libxslt <xmlsoft.org/XSLT/>

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 ext
Octocat-spinner-32 lib Ruby 1.9 compatible branch of ruby-xslt. March 10, 2009
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 AUTHORS.rdoc
Octocat-spinner-32 COPYING
Octocat-spinner-32 ChangeLog.rdoc
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 ruby-xslt.gemspec
Octocat-spinner-32 setup.rb
README.rdoc

Ruby/XSLT

About

Ruby/XSLT is a simple XSLT class based on libxml <xmlsoft.org/> and libxslt <xmlsoft.org/XSLT/>

Licence

Copyright (C) 2003-2012 Gregoire Lejeune <gregoire dot lejeune at free dot fr>

Ruby/XSLT is freely distributable according to the terms of the GNU General Public License (see the file 'COPYING').

This program is distributed without any warranty. See the file 'COPYING' for details.

INSTALLATION

sudo gem install ruby-xslt

or

ruby extconf.rb # see CONFIGURATION for more options
make
make test
make doc
sudo make install

CONFIGURATION

--help                   display this help and exit

--with-xslt-lib=PATH
--with-xslt-include=PATH
--with-xslt-dir=PATH     specify the directory name for the libxslt include 
                         files and/or library 

--disable-error-handler  disables the new error handler 

--disable-exslt          disables libexslt support <http://exslt.org/>

EXAMPLES

Simple example

require 'xml/xslt'

xslt = XML::XSLT.new()
xslt.xml = "text.xml"
xslt.xsl = "test.xsl"

out = xslt.serve()
print out;

REXML support

require 'rexml/document'
require 'xml/xslt'

xslt = XML::XSLT.new()

xslt.xml = REXML::Document.new File.read( "test.xml" )
xslt.xsl = REXML::Document.new File.read( "test.xsl" )

out = xslt.serve()
print out;

XML::Smart support

require 'xml/smart'
require 'xml/xslt'

xslt = XML::XSLT.new()

xslt.xml = XML::Smart.open( "test.xml" )
xslt.xsl = XML::Smart.open( "test.xsl" )

out = xslt.serve()
print out;

Parameters support

require "xml/xslt"

xslt = XML::XSLT.new()
xslt.xsl = "parameter.xsl"
xslt.xml = "test.xml"
xslt.parameters = { "p1" => "the first parameter ...",
                    "p2" => "'and the second one!'" }
xslt.save("test1.html")

xslt.parameters = { "p1" => "Ruby...",
                    "p2" => "'...is cool !'" }
xslt.save("test2.html")

External functions support

require "xml/xslt"

xslt = XML::XSLT.new()
xslt.xsl = "functions.xsl"
xslt.xml = "test.xml"

XML::XSLT.registerExtFunc("http://test.none", "round-trip") do |arg|
  arg
end

XML::XSLT.registerExtFunc("http://test.none", "type") do |arg|
  arg.class.to_s
end

print xslt.serve

Error handling

XML::XSLT.registerErrorHandler { |string| puts string }

xslt = XML::XSLT.new
xslt.xml = "not xml"

This fragment would print:

Entity: line 1: 
parser 
error : 
Start Tag expected, '<' not found
not xml
^
Something went wrong with that request. Please try again.