Ruby C
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


= libxslt-ruby


This version has been forked to provide xslt output methods that serialize the result of a xslt transformation according to the settings choosen in the stylesheet.


I renamed the gem to avoid confusion into libxslt-ruby-mw while the library name remains the same. One should not install libxslt-ruby and libxslt-ruby-mw gems at the same time.

The version has also been updated to gem version 0.9.7 by hand.

== Overview

The libxslt gem provides Ruby language bindings for GNOME's Libxslt
toolkit. It is free software, released under the MIT License.

== Requirements

libxslt-ruby requires Ruby 1.8.4 or higher.  It is dependent on 
the following libraries to function properly:

* libm      (math routines: very standard)
* libz      (zlib)
* libiconv
* libxml2
* libxslt
* libxml-ruby bindings

If you are running Linux or Unix you'll need a C compiler so the extension
can be compiled when it is installed.  If you are running Windows, then install the Windows specific RubyGem which
includes an already built extension.

!!!NOTE!!!  The libxml-ruby and libxslt-ruby bindings must absolutely, positively,
without a doubt share the same libxml2 library.  This is because libxslt modifies
XML documents created by libxml2.  If there are two copies of libxml2 on your 
system, then when XML documents allocated in copy #1 are manipulated by copy #2,
a segmentation fault will occur.  So make sure that your system has only one copy of libxml2


The easiest way to install libxslt-ruby is via Ruby Gems.  To install:

<tt>gem install libxslt-ruby</tt>

If you are running Windows, make sure to install the Win32 RubyGem which 
includes an already built binary file.  The binary is built against
libxml2 version 2.6.32, iconv version 1.11 and libxslt version 1.1.24.
Binaries for libxml2 and iconv are provided in the libxml-ruby bindings,
while a binary for libxslt is provided in the libxslt-ruby bindings. 

The Windows binaries are biult with MingW.  The gem also includes 
a Microsoft VC++ 2005 solution.  If you wish to run a debug version
of libxml-ruby on Windows, then it is highly recommended
you use VC++.


For in-depth information about using libxslt-ruby please refer
to its online Rdoc documentation.  

All libxslt classes are in the LibXSLT::XSLT module. The simplest
way to use libxslt is to require 'xslt'.  This will mixin the 
LibXML and LibXSLT modules into the global namespace, allowing you to 
write code like this: 

require 'xslt'
document =
stylesheett =

If you prefer not to add the LibXSLT module to the global namepace, then
write your code like this:

require 'libxslt'

class MyClass
  def some_method
    document =
    stylesheett =

Given an XML file like:

  <?xml version="1.0" encoding="UTF-8"?>
  <?xml-stylesheet href="fuzface.xsl" type="text/xsl"?>
      <id>$Id$</id>     <title>Fuzface...</title>
      <subtitle>The Internet's a big place and here's some proof...</subtitle>
        I think it's a tragedy that I'm going to start off my new
        commentary by talking about facial hair and the Internet.
        Something about that just screams pathetic, but whatever: it's
        humor and that's life.

And an XSLT file like this:

  <?xml version="1.0" ?>
  <xsl:stylesheet xmlns:xsl="" version="1.0">
  <xsl:template match="/">
    <xsl:element name="html">
      <xsl:element name="head">
        <xsl:element name="title">Ramblings - <xsl:value-of select="commentary/meta/title" /> - <xsl:value-of select="commentary/meta/subtitle" /></xsl:element>
      <xsl:element name="body">
        <xsl:element name="h1"><xsl:value-of select="commentary/meta/title" /></xsl:element>
        <xsl:element name="h3"><xsl:value-of select="commentary/meta/subtitle" /></xsl:element>
        By: <xsl:value-of select="commentary/meta/author/first_name" /> <xsl:value-of select="commentary/meta/author/last_name" /><xsl:element name="br" />
        Date: <xsl:value-of select="commentary/meta/date" /><xsl:element name="br" />
        <xsl:for-each select="./commentary/body">
          <xsl:apply-templates />
  <xsl:template match="para">
    <xsl:element name="p">
      <xsl:value-of select="." />

We can easily transform the XML with the following ruby code:

  require 'xslt'
  # Create a new XSL Transform
  stylesheet_doc = XML::Document.file('files/fuzface.xsl')
  stylesheet =

  # Transform a xml document
  xml_doc = XML::Document.file('files/fuzface.xml')
  result = stylesheet.apply(xml_doc)
You can then print, save or manipulate the returned document.

== License

See LICENSE for license information.


RDoc comments are included - run 'rake doc' to generate documentation.
You can find the latest documentation at:



For more information please refer to the documentation.  If you have any
questions, please send email to