Last Update: Tue Jul 15 15:48:25 Mountain Daylight Time 2008



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


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 installed.


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

gem install libxslt-ruby

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.12 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. These binaries should be put either in the libxslt/lib directory or on the Windows path.

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++.


Given an XML file like:

  <?xml version="1.0" encoding="UTF-8"?>
  <?xml-stylesheet href="fuzface.xsl" type="text/xsl"?>

      <date>$Date: 2008-07-14 21:23:19 -0600 (Mon, 14 Jul 2008) $</date>
      <id>$Id: README 94 2008-07-15 03:23:19Z cfis $</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 'libxslt'

  # 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.


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