Wraps the Saxon 9 HE XSLT processor Java API so it's easy to use from your JRuby project, with an API modelled on Nokogiri's.
This is a super-minimal first cut, it doesn't do many, many, things that it should.
It only runs under JRuby.
Saxon HE is (c) Michael H. Kay and released under the Mozilla MPL 1.0 (http://www.mozilla.org/MPL/1.0/)
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install saxon-xslt
require 'saxon-xslt' transformer = .(File.open('/path/to/your.xsl')) input = .(File.open('/path/to/your.xml')) output = transformer.transform(input)
saxon-xslt 0.5 includes Saxon HE 184.108.40.206
Differences between Saxon and Nokogiri
Saxon uses a
Processor class as its central object: it holds configuration information and acts as a Factory for creating documents or XSLT stylesheet compilers. Unless you need to tweak the config you don't need to worry about this –
saxon-xslt creates a shared instance behind the scenes when you call
Saxon.XML. If you need to change the configuration you can create your own instance of
Saxon::Processor and pass it an open
File pointing at a Saxon configuration file. (See http://www.saxonica.com/documentation/index.html#!configuration/configuration-file for details of the configuration file.) Once you have a
Saxon::Processor instance you can call the
XSLT methods on it directly:
require 'saxon-xslt' processor = ::.(File.open('/path/to/config.xml')) transformer = processor.XSLT(File.open('/path/to/your.xsl')) input = processor.XML(File.open('/path/to/your.xml')) output = transformer.transform(input)
XML has this idea of 'Public' and 'System' identifiers for documents. The public ID is a kind of abstract name and the system ID is a URI, for example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
There the Public ID is
-//W3C//DTD HTML 4.01 Transitional//EN and the System ID is
http://www.w3.org/TR/html4/loose.dtd. An XML or XSLT processor uses the System ID as a base URI for resolving linked objects, e.g.
<xsl:include> calls with relative URIs.
With Nokogiri the System ID for a document is inferred from its file path, if you hand in a
File object to
saxon-xslt you can also explicitly set the System ID:
xslt = .("<xsl:stylesheet>...</xsl:stylesheet>", system_id: "/path/to/resources/file.xsl")
So, if you have other XSLT stylesheets in
/path/to/resources/ then your dynamically generated XSLT can refer to them with import statements like
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request